11cb0ef41Sopenharmony_ci// Flags: --frozen-intrinsics
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciassert.throws(
71cb0ef41Sopenharmony_ci  () => Object.defineProperty = 'asdf',
81cb0ef41Sopenharmony_ci  TypeError
91cb0ef41Sopenharmony_ci);
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci// Ensure we can extend Console
121cb0ef41Sopenharmony_ci{
131cb0ef41Sopenharmony_ci  class ExtendedConsole extends console.Console {}
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  const s = new ExtendedConsole(process.stdout);
161cb0ef41Sopenharmony_ci  const logs = [];
171cb0ef41Sopenharmony_ci  s.log = (msg) => logs.push(msg);
181cb0ef41Sopenharmony_ci  s.log('custom');
191cb0ef41Sopenharmony_ci  s.log = undefined;
201cb0ef41Sopenharmony_ci  assert.strictEqual(s.log, undefined);
211cb0ef41Sopenharmony_ci  assert.strictEqual(logs.length, 1);
221cb0ef41Sopenharmony_ci  assert.strictEqual(logs[0], 'custom');
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci// Ensure we can write override Object prototype properties on instances
261cb0ef41Sopenharmony_ci{
271cb0ef41Sopenharmony_ci  const o = {};
281cb0ef41Sopenharmony_ci  o.toString = () => 'Custom toString';
291cb0ef41Sopenharmony_ci  assert.strictEqual(o + 'asdf', 'Custom toStringasdf');
301cb0ef41Sopenharmony_ci  assert.strictEqual(Object.getOwnPropertyDescriptor(o, 'toString').enumerable,
311cb0ef41Sopenharmony_ci                     true);
321cb0ef41Sopenharmony_ci}
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci// Ensure we can not override globalThis
351cb0ef41Sopenharmony_ci{
361cb0ef41Sopenharmony_ci  assert.throws(() => { globalThis.globalThis = null; },
371cb0ef41Sopenharmony_ci                { name: 'TypeError' });
381cb0ef41Sopenharmony_ci  assert.strictEqual(globalThis.globalThis, globalThis);
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci// Ensure that we cannot override console properties.
421cb0ef41Sopenharmony_ci{
431cb0ef41Sopenharmony_ci  const { log } = console;
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  assert.throws(() => { console.log = null; },
461cb0ef41Sopenharmony_ci                { name: 'TypeError' });
471cb0ef41Sopenharmony_ci  assert.strictEqual(console.log, log);
481cb0ef41Sopenharmony_ci}
49