forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathloader-side-effect.mjs
32 lines (26 loc) · 992 Bytes
/
loader-side-effect.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Arrow function so it closes over the this-value of the preload scope.
const globalPreloadSrc = () => {
/* global getBuiltin */
const assert = getBuiltin('assert');
const vm = getBuiltin('vm');
assert.strictEqual(typeof require, 'undefined');
assert.strictEqual(typeof module, 'undefined');
assert.strictEqual(typeof exports, 'undefined');
assert.strictEqual(typeof __filename, 'undefined');
assert.strictEqual(typeof __dirname, 'undefined');
assert.strictEqual(this, globalThis);
(globalThis.preloadOrder || (globalThis.preloadOrder = [])).push('loader');
vm.runInThisContext(`\
var implicitGlobalProperty = 42;
const implicitGlobalConst = 42 * 42;
`);
assert.strictEqual(globalThis.implicitGlobalProperty, 42);
(implicitGlobalProperty).foo = 'bar'; // assert: not strict mode
globalThis.explicitGlobalProperty = 42 * 42 * 42;
}
export function globalPreload() {
return `\
<!-- assert: inside of script goal -->
(${globalPreloadSrc.toString()})();
`;
}