Skip to content

Commit

Permalink
src/js.js: new globalThis compat routine
Browse files Browse the repository at this point in the history
  • Loading branch information
daurnimator authored and giann committed Jan 27, 2024
1 parent f9d61c2 commit d6362d1
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,25 @@ if (typeof process !== "undefined") {
} catch (e) {}
}

const global_env = (function() {
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 */
}
})();
const global_env = (function(Object) {
return typeof globalThis === 'object' ?
globalThis // eslint-disable-line no-undef
: (this ?
// compat: strict mode is unsupported
this
: ( // Based on https://mathiasbynens.be/notes/globalthis
Object.defineProperty(Object.prototype, '_', {
configurable: true,
get: function () {
delete Object.prototype._;
return this;
}
})
/* global _ */
, _
)
);
}(Object));

let apply, construct, Reflect_deleteProperty;
if (typeof Reflect !== "undefined") {
Expand Down

0 comments on commit d6362d1

Please sign in to comment.