Browse Source

Rename global to globalThis and enable by default

pull/2160/head
Sami Vaarala 5 years ago
parent
commit
49327dec17
  1. 6
      config/config-options/DUK_USE_GLOBAL_BINDING.yaml
  2. 6
      polyfills/global.js
  3. 4
      src-input/builtins.yaml
  4. 10
      tests/ecmascript/test-bi-global-global-binding.js
  5. 2
      util/makeduk_base.yaml

6
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).

6
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,

4
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

10
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);

2
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

Loading…
Cancel
Save