From 49327dec17cba3d6991644a4114fab14f238a846 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Sat, 3 Aug 2019 02:19:45 +0300 Subject: [PATCH] Rename global to globalThis and enable by default --- config/config-options/DUK_USE_GLOBAL_BINDING.yaml | 6 ++---- polyfills/global.js | 6 +++--- src-input/builtins.yaml | 4 ++-- tests/ecmascript/test-bi-global-global-binding.js | 10 +++++----- util/makeduk_base.yaml | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/config/config-options/DUK_USE_GLOBAL_BINDING.yaml b/config/config-options/DUK_USE_GLOBAL_BINDING.yaml index 096bb622..55b357f0 100644 --- a/config/config-options/DUK_USE_GLOBAL_BINDING.yaml +++ b/config/config-options/DUK_USE_GLOBAL_BINDING.yaml @@ -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). diff --git a/polyfills/global.js b/polyfills/global.js index f21b1f56..a80c2f7c 100644 --- a/polyfills/global.js +++ b/polyfills/global.js @@ -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, diff --git a/src-input/builtins.yaml b/src-input/builtins.yaml index d4c42252..8028ace5 100644 --- a/src-input/builtins.yaml +++ b/src-input/builtins.yaml @@ -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 diff --git a/tests/ecmascript/test-bi-global-global-binding.js b/tests/ecmascript/test-bi-global-global-binding.js index 5f841720..76576b75 100644 --- a/tests/ecmascript/test-bi-global-global-binding.js +++ b/tests/ecmascript/test-bi-global-global-binding.js @@ -1,5 +1,5 @@ /* - * 'global' binding based on https://github.com/tc39/proposal-global + * 'globalThis' binding based on https://github.com/tc39/proposal-global */ /*=== @@ -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); diff --git a/util/makeduk_base.yaml b/util/makeduk_base.yaml index 5495725f..55a6f352 100644 --- a/util/makeduk_base.yaml +++ b/util/makeduk_base.yaml @@ -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