Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/internal/per_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be worthwhile emitting an experimental warning while this is still in early stages?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t see why; it’s not in early stages, it’s in stage 3, and v8 is shipping it unflagged.

});

// https://github.com/nodejs/node/issues/14909
if (global.Intl) delete global.Intl.v8BreakIterator;

Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-global-descriptors.js
Original file line number Diff line number Diff line change
@@ -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');