1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const RuntimeGlobals = require("../RuntimeGlobals");
|
8 | const RuntimeModule = require("../RuntimeModule");
|
9 | const Template = require("../Template");
|
10 |
|
11 | class GlobalRuntimeModule extends RuntimeModule {
|
12 | constructor() {
|
13 | super("global");
|
14 | }
|
15 |
|
16 | |
17 |
|
18 |
|
19 | generate() {
|
20 | return Template.asString([
|
21 | `${RuntimeGlobals.global} = (function() {`,
|
22 | Template.indent([
|
23 | "if (typeof globalThis === 'object') return globalThis;",
|
24 | "try {",
|
25 | Template.indent(
|
26 |
|
27 |
|
28 |
|
29 | "return this || new Function('return this')();"
|
30 | ),
|
31 | "} catch (e) {",
|
32 | Template.indent(
|
33 |
|
34 | "if (typeof window === 'object') return window;"
|
35 | ),
|
36 | "}"
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | ]),
|
42 | "})();"
|
43 | ]);
|
44 | }
|
45 | }
|
46 |
|
47 | module.exports = GlobalRuntimeModule;
|