Skip to content

Commit c26f2bd

Browse files
ljharbdevsnek
authored andcommitted
src: add globalThis
Per https://github.com/tc39/proposal-global, the global value `globalThis` should be configurable, writable, and non-enumerable.
1 parent 1cee085 commit c26f2bd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/internal/per_context.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
// node::NewContext calls this script
44

55
(function(global) {
6+
// https://github.com/tc39/proposal-global
7+
// https://github.com/nodejs/node/pull/22835
8+
// TODO(devsnek,ljharb) remove when V8 71 lands
9+
Object.defineProperty(global, 'globalThis', {
10+
value: global,
11+
writable: true,
12+
enumerable: false,
13+
configurable: true,
14+
});
15+
616
// https://github.com/nodejs/node/issues/14909
717
if (global.Intl) delete global.Intl.v8BreakIterator;
818

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
6+
const actualGlobal = Function('return this')();
7+
8+
const {
9+
value,
10+
configurable,
11+
enumerable,
12+
writable
13+
} = Object.getOwnPropertyDescriptor(actualGlobal, 'globalThis');
14+
15+
assert.strictEqual(value, actualGlobal, 'globalThis should be global object');
16+
assert.strictEqual(configurable, true, 'globalThis should be configurable');
17+
assert.strictEqual(enumerable, false, 'globalThis should be non-enumerable');
18+
assert.strictEqual(writable, true, 'globalThis should be writable');

0 commit comments

Comments
 (0)