"Redacted" global-namespace

kai zhu kaizhu256 at gmail.com
Sat Sep 29 23:02:41 UTC 2018


thx. for those too lazy, i translated the npm-package into a standalone-snippet you can copy-paste anywhere:

```js
/*jslint browser*/
/*global global global2 self*/
(function () {
/*
 * polyfill for
 * https://github.com/tc39/proposal-global
 * 1. replace all occurrences of global2 with <redacted-name>
 * 2. copy-paste this code into any browser/node/io.js/node-webkit script
 *    to enable global-object global2
 */
    "use strict";
    var descriptor;
    var obj;
    var polyfill;
    if (
        typeof global !== "object"
        || !global
        || global.Math !== Math
        || global.Array !== Array
    ) {
        if (String(typeof self) !== "undefined") {
            polyfill = self;
        } else if (String(typeof window) !== "undefined") {
            polyfill = window;
        } else if (String(typeof global) !== "undefined") {
            polyfill = global;
        } else {
            polyfill = Function('return this')(); // jslint ignore:line
        }
    } else {
        polyfill = global;
    }
    if (Object.defineProperty && (function () {
        obj = {};
        try {
            Object.defineProperty(obj, "x", {enumerable: false, value: obj});
/* jslint ignore:start */
            for (var _ in obj) {
                return false;
            }
/* jslint ignore:end */
            return obj.x === obj;
        } catch (ignore) { /* this is IE 8. */
            return false;
        }
    }())) {
        descriptor = Object.getOwnPropertyDescriptor(polyfill, "global2");
        if (!descriptor || (
            descriptor.configurable
            && (descriptor.enumerable || descriptor.writable || global2 !== polyfill)
        )) {
            Object.defineProperty(polyfill, "global2", {
                configurable: true,
                enumerable: false,
                value: polyfill,
                writable: false
            });
        }
    } else if (typeof global2 !== "object" || global2 !== polyfill) {
        polyfill.global2 = polyfill;
    }
}());
```

kai zhu
kaizhu256 at gmail.com

 

> On 30 Sep 2018, at 4:16 AM, Jordan Harband <ljharb at gmail.com> wrote:
> 
> The polyfill already exists on npm <https://www.npmjs.com/package/globalthis>; it's linked from the proposal repo.
> 
> On Sat, Sep 29, 2018 at 5:02 AM kai zhu <kaizhu256 at gmail.com <mailto:kaizhu256 at gmail.com>> wrote:
> +1 for unified global-object (currently stage-3)
> 
> can someone pm me what the redacted-name is?  i'm interested in polyfilling it for existing projects, e.g.:
> 
> ```js
> /*jslint browser*/
> /*global global process*/
> (function () {
> /*
>  * polyfill for
>  * https://github.com/tc39/proposal-global <https://github.com/tc39/proposal-global>
>  * assuming redacted-name is "global2"
>  */
>     "use strict";
>     var global2;
>     try {
>         global2 = process.versions.node && global;
>     } catch (ignore) {
>     }
>     global2 = global2 || window;
>     global2.global2 = global2;
> }());
> ```
> 
> kai zhu
> kaizhu256 at gmail.com <mailto:kaizhu256 at gmail.com>
>> On 11 Aug 2018, at 1:29 AM, Jordan Harband <ljharb at gmail.com <mailto:ljharb at gmail.com>> wrote:
>> 
>> The rationale is in the notes themselves.
>> 
>> Yes, we could do so in principle, but it's rarely useful to do so.
>> 
>> If the impact is insignificant, then we made nothing worse, just delayed some information spreading for a few weeks/months. If the impact is significant, then this has a positive effect.
>> 
>> I'm not seeing the downside.
>> 
>> On Fri, Aug 10, 2018 at 10:27 AM, kdex <kdex at kdex.de <mailto:kdex at kdex.de>> wrote:
>> I'd be interested to learn why it was decided to redact a possible new name 
>> for `global` in the latest meeting notes[1].
>> 
>> Although I do understand that redacting the name minimizes its chance to gain 
>> more usage, I doubt that the impact would be significant; if anything, I think 
>> people would have trouble to think of this form of standardization as "open".
>> 
>> By the same argument, we could in principle redact any new prototype/global 
>> property, couldn't we? Is the intent not to cause a second "smooshgate"? 
>> What's the point?
>> 
>> [1] https://github.com/rwaldron/tc39-notes/blob/master/es9/2018-07/
>> july-24.md#new-name-for-global <https://github.com/rwaldron/tc39-notes/blob/master/es9/2018-07/july-24.md#new-name-for-global>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
>> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss>
>> 
>> 
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
>> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180930/d5a80001/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-09-30 at 5.36.17 AM.jpg
Type: image/jpeg
Size: 101022 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180930/d5a80001/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-09-30 at 5.33.05 AM.jpg
Type: image/jpeg
Size: 67520 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180930/d5a80001/attachment-0003.jpg>


More information about the es-discuss mailing list