News for hackers. Stuff that matters.
Re:A horrifying globalThis polyfill in JavaScript by daurnimator on Sunday May 12, 2019 @11:42PM (#19896290)
Thanks for the new method!

In fengari we currently use https://github.com/fengari-lua/fengari-interop/blob/8e59efb7...

    const global_env = (function() {
        /* global WorkerGlobalScope */ /* see https://github.com/sindresorhus/globals/issues/127 */
        if (typeof process !== "undefined") {
            /* node */
            return global;
        } else if (typeof window !== "undefined") {
            /* browser window */
            return window;
        } else if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
            /* web worker */
            return self;
        } else {
            /* unknown global env */
            return (0, eval)('this'); /* use non-strict mode to get global env */
        }
    })();
I created https://github.com/fengari-lua/fengari-interop/issues/45 to track.
Re:A horrifying globalThis polyfill in JavaScript by bfred_it on Monday May 13, 2019 @03:00AM (#19896887)
eval doesn’t work with some CSP settings, the article mentions this and other limits of previous solutions.
Re:A horrifying globalThis polyfill in JavaScript by codedokode on Monday May 13, 2019 @08:44AM (#19898673)
You use "global_env" only inside luaopen_js(). Why don't you just add it as an argument, for example:

function luaopen_js(L, global) { ... }

instead of writing this ugly hack?

Re:A horrifying globalThis polyfill in JavaScript by daurnimator on Monday May 13, 2019 @08:00PM (#19905344)
`luaopen_js` is the entry point for the library with a set API. (that follows https://www.lua.org/manual/5.3/manual.html#lua_CFunction ). The caller cannot pass more arguments.
Re:A horrifying globalThis polyfill in JavaScript by Technetium_Hat on Monday May 13, 2019 @11:13AM (#19900059)
Why the comma operator with the eval?
Re:A horrifying globalThis polyfill in JavaScript by daurnimator on Monday May 13, 2019 @08:03PM (#19905374)