1// Flags: --frozen-intrinsics 2'use strict'; 3require('../common'); 4const assert = require('assert'); 5 6assert.throws( 7 () => Object.defineProperty = 'asdf', 8 TypeError 9); 10 11// Ensure we can extend Console 12{ 13 class ExtendedConsole extends console.Console {} 14 15 const s = new ExtendedConsole(process.stdout); 16 const logs = []; 17 s.log = (msg) => logs.push(msg); 18 s.log('custom'); 19 s.log = undefined; 20 assert.strictEqual(s.log, undefined); 21 assert.strictEqual(logs.length, 1); 22 assert.strictEqual(logs[0], 'custom'); 23} 24 25// Ensure we can write override Object prototype properties on instances 26{ 27 const o = {}; 28 o.toString = () => 'Custom toString'; 29 assert.strictEqual(o + 'asdf', 'Custom toStringasdf'); 30 assert.strictEqual(Object.getOwnPropertyDescriptor(o, 'toString').enumerable, 31 true); 32} 33 34// Ensure we can not override globalThis 35{ 36 assert.throws(() => { globalThis.globalThis = null; }, 37 { name: 'TypeError' }); 38 assert.strictEqual(globalThis.globalThis, globalThis); 39} 40 41// Ensure that we cannot override console properties. 42{ 43 const { log } = console; 44 45 assert.throws(() => { console.log = null; }, 46 { name: 'TypeError' }); 47 assert.strictEqual(console.log, log); 48} 49