|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Rev | Line | |
|---|
| [9af201e] | 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 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 | * Generates runtime code for this runtime module.
|
|---|
| 18 | * @returns {string | null} runtime code
|
|---|
| 19 | */
|
|---|
| 20 | generate() {
|
|---|
| 21 | return Template.asString([
|
|---|
| 22 | `${RuntimeGlobals.global} = (function() {`,
|
|---|
| 23 | Template.indent([
|
|---|
| 24 | "if (typeof globalThis === 'object') return globalThis;",
|
|---|
| 25 | "try {",
|
|---|
| 26 | Template.indent(
|
|---|
| 27 | // This works in non-strict mode
|
|---|
| 28 | // or
|
|---|
| 29 | // This works if eval is allowed (see CSP)
|
|---|
| 30 | "return this || new Function('return this')();"
|
|---|
| 31 | ),
|
|---|
| 32 | "} catch (e) {",
|
|---|
| 33 | Template.indent(
|
|---|
| 34 | // This works if the window reference is available
|
|---|
| 35 | "if (typeof window === 'object') return window;"
|
|---|
| 36 | ),
|
|---|
| 37 | "}"
|
|---|
| 38 | // It can still be `undefined`, but nothing to do about it...
|
|---|
| 39 | // We return `undefined`, instead of nothing here, so it's
|
|---|
| 40 | // easier to handle this case:
|
|---|
| 41 | // if (!global) { … }
|
|---|
| 42 | ]),
|
|---|
| 43 | "})();"
|
|---|
| 44 | ]);
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | module.exports = GlobalRuntimeModule;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.