1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- "use strict";
- const RuntimeGlobals = require("../RuntimeGlobals");
- const RuntimeModule = require("../RuntimeModule");
- const Template = require("../Template");
- class GlobalRuntimeModule extends RuntimeModule {
- constructor() {
- super("global");
- }
-
- generate() {
- return Template.asString([
- `${RuntimeGlobals.global} = (function() {`,
- Template.indent([
- "if (typeof globalThis === 'object') return globalThis;",
- "try {",
- Template.indent(
-
-
-
- "return this || new Function('return this')();"
- ),
- "} catch (e) {",
- Template.indent(
-
- "if (typeof window === 'object') return window;"
- ),
- "}"
-
-
-
-
- ]),
- "})();"
- ]);
- }
- }
- module.exports = GlobalRuntimeModule;
|