diff --git a/lib/internal/per_context.js b/lib/internal/per_context.js index f07e8822296b03..d4982344cb1478 100644 --- a/lib/internal/per_context.js +++ b/lib/internal/per_context.js @@ -3,6 +3,16 @@ // node::NewContext calls this script (function(global) { + // https://github.com/tc39/proposal-global + // https://github.com/nodejs/node/pull/22835 + // TODO(devsnek,ljharb) remove when V8 71 lands + Object.defineProperty(global, 'globalThis', { + value: global, + writable: true, + enumerable: false, + configurable: true, + }); + // https://github.com/nodejs/node/issues/14909 if (global.Intl) delete global.Intl.v8BreakIterator; diff --git a/test/parallel/test-global-descriptors.js b/test/parallel/test-global-descriptors.js new file mode 100644 index 00000000000000..ab56d949f16c50 --- /dev/null +++ b/test/parallel/test-global-descriptors.js @@ -0,0 +1,18 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); + +const actualGlobal = Function('return this')(); + +const { + value, + configurable, + enumerable, + writable +} = Object.getOwnPropertyDescriptor(actualGlobal, 'globalThis'); + +assert.strictEqual(value, actualGlobal, 'globalThis should be global object'); +assert.strictEqual(configurable, true, 'globalThis should be configurable'); +assert.strictEqual(enumerable, false, 'globalThis should be non-enumerable'); +assert.strictEqual(writable, true, 'globalThis should be writable');