source: frontend/node_modules/webpack/lib/runtime/GlobalRuntimeModule.js@ cdcff72

Last change on this file since cdcff72 was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3*/
4
5"use strict";
6
7const RuntimeGlobals = require("../RuntimeGlobals");
8const RuntimeModule = require("../RuntimeModule");
9const Template = require("../Template");
10
11class 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
48module.exports = GlobalRuntimeModule;
Note: See TracBrowser for help on using the repository browser.