• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Arrow function so it closes over the this-value of the preload scope.
2const globalPreload = () => {
3  /* global getBuiltin */
4  const assert = getBuiltin('assert');
5  const vm = getBuiltin('vm');
6
7  assert.strictEqual(typeof require, 'undefined');
8  assert.strictEqual(typeof module, 'undefined');
9  assert.strictEqual(typeof exports, 'undefined');
10  assert.strictEqual(typeof __filename, 'undefined');
11  assert.strictEqual(typeof __dirname, 'undefined');
12
13  assert.strictEqual(this, globalThis);
14  (globalThis.preloadOrder || (globalThis.preloadOrder = [])).push('loader');
15
16  vm.runInThisContext(`\
17var implicitGlobalProperty = 42;
18const implicitGlobalConst = 42 * 42;
19`);
20
21  assert.strictEqual(globalThis.implicitGlobalProperty, 42);
22  (implicitGlobalProperty).foo = 'bar'; // assert: not strict mode
23
24  globalThis.explicitGlobalProperty = 42 * 42 * 42;
25}
26
27export function getGlobalPreloadCode() {
28  return `\
29<!-- assert: inside of script goal -->
30(${globalPreload.toString()})();
31`;
32}
33