Skip to content

Commit

Permalink
src: add globalThis
Browse files Browse the repository at this point in the history
Per https://github.com/tc39/proposal-global, the global value
`globalThis` should be configurable, writable, and non-enumerable.
  • Loading branch information
ljharb authored and devsnek committed Sep 13, 2018
1 parent 1cee085 commit c26f2bd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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,
});

// 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');

0 comments on commit c26f2bd

Please sign in to comment.