Skip to content

Commit

Permalink
Rename global to globalThis and enable by default
Browse files Browse the repository at this point in the history
  • Loading branch information
svaarala committed Aug 3, 2019
1 parent 577f267 commit 49327de
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
6 changes: 2 additions & 4 deletions config/config-options/DUK_USE_GLOBAL_BINDING.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
define: DUK_USE_GLOBAL_BINDING
introduced: 2.1.0
default: false
default: true
tags:
- ecmascript
- experimental
description: >
Provide a 'global' binding (https://github.com/tc39/proposal-global).
Disabled by default because it's still a proposal and there may be
reasons it won't be widely implemented: https://github.com/tc39/proposal-global/issues/20.
Provide a 'globalThis' binding (https://github.com/tc39/proposal-global).
6 changes: 3 additions & 3 deletions polyfills/global.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Duktape 2.1.0 adds a 'global' binding. Polyfill for earlier versions.
* Duktape 2.5.0 adds a 'globalThis' binding. Polyfill for earlier versions.
*/

if (typeof global === 'undefined') {
if (typeof globalThis === 'undefined') {
(function () {
var global = new Function('return this;')();
Object.defineProperty(global, 'global', {
Object.defineProperty(global, 'globalThis', {
value: global,
writable: true,
enumerable: false,
Expand Down
4 changes: 2 additions & 2 deletions src-input/builtins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ objects:
bidx: true

properties:
# 'global' binding giving easy to access to the global object.
# 'globalThis' binding giving easy to access to the global object.
# Not yet standard, see https://github.com/tc39/proposal-global.
- key: "global"
- key: "globalThis"
value:
type: object
id: bi_global
Expand Down
10 changes: 5 additions & 5 deletions tests/ecmascript/test-bi-global-global-binding.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* 'global' binding based on https://github.com/tc39/proposal-global
* 'globalThis' binding based on https://github.com/tc39/proposal-global
*/

/*===
Expand All @@ -18,12 +18,12 @@ function test() {
// Standard trick to access global object.
g = new Function('return this')();

// proposal-global provides 'global' for cleaner standard access.
print(typeof global);
print(g === global);
// proposal-global provides 'globalThis' for cleaner standard access.
print(typeof globalThis);
print(g === globalThis);

// Attributes in current proposal.
pd = Object.getOwnPropertyDescriptor(g, 'global');
pd = Object.getOwnPropertyDescriptor(g, 'globalThis');
print(typeof pd);
if (pd) {
print(pd.value === g);
Expand Down
2 changes: 1 addition & 1 deletion util/makeduk_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ DUK_USE_DEBUGGER_INSPECT: true
DUK_USE_FASTINT: true
DUK_USE_JSON_STRINGIFY_FASTPATH: true

DUK_USE_GLOBAL_BINDING: true
#DUK_USE_GLOBAL_BINDING: true

#DUK_USE_CACHE_ACTIVATION: false
#DUK_USE_CACHE_CATCHER: false
Expand Down

0 comments on commit 49327de

Please sign in to comment.