From 1a9a577a968749d090fd7e8e2e71bedf43fc3eb3 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 13 May 2019 03:29:24 +0200 Subject: [PATCH] bootstrap: --frozen-intrinsics unfreeze console PR-URL: https://github.com/nodejs/node/pull/27663 Reviewed-By: Ruben Bridgewater --- doc/api/cli.md | 38 +++++++++++++++++++++++++++---- lib/internal/freeze_intrinsics.js | 2 -- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index a8a18620fb3152..42950418282ef2 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -211,11 +211,41 @@ Support is currently only provided for the root context and no guarantees are currently provided that `global.Array` is indeed the default intrinsic reference. -**Code breakage is highly likely with this flag**, especially since limited -support for subclassing builtins is provided currently due to ECMA-262 bug -https://github.com/tc39/ecma262/pull/1320. +**Code breakage is highly likely with this flag**, since redefining any +builtin properties on a subclass will throw in strict mode due to the ECMA-262 +issue https://github.com/tc39/ecma262/pull/1307. This flag may still change +or be removed in the future. + +To avoid these cases, any builtin function overrides should be defined upfront: + + +```js +const o = {}; +// THROWS: Cannot assign read only property 'toString' of object +o.toString = () => 'string'; + +// OK +const o = { toString: () => 'string' }; + +class X { + constructor() { + this.toString = () => 'string'; + } +} +// THROWS: Cannot assign read only property 'toString' of object +new X(); + +class X { + toString = undefined; + constructor() { + this.toString = () => 'string'; + } +} +// OK +new X(); +``` + -Both of the above may change in future updates, which will be breaking changes. ### `--heapsnapshot-signal=signal`