Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: add globalThis #22835

Closed
wants to merge 1 commit into from
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');