mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
bootstrap: run preload prior to frozen-intrinsics
This is used to allow people to run polyfills. Co-Authored-By: Anna Henningsen <github@addaleax.net> PR-URL: https://github.com/nodejs/node/pull/28940 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
9fd9efa492
commit
85898e0aca
@ -218,6 +218,9 @@ Support is currently only provided for the root context and no guarantees are
|
||||
currently provided that `global.Array` is indeed the default intrinsic
|
||||
reference. Code may break under this flag.
|
||||
|
||||
`--require` runs prior to freezing intrinsics in order to allow polyfills to
|
||||
be added.
|
||||
|
||||
### `--heapsnapshot-signal=signal`
|
||||
<!-- YAML
|
||||
added: v12.0.0
|
||||
|
@ -48,10 +48,10 @@ function prepareMainThreadExecution(expandArgv1 = false) {
|
||||
initializeClusterIPC();
|
||||
|
||||
initializeDeprecations();
|
||||
initializeFrozenIntrinsics();
|
||||
initializeCJSLoader();
|
||||
initializeESMLoader();
|
||||
loadPreloadModules();
|
||||
initializeFrozenIntrinsics();
|
||||
}
|
||||
|
||||
function patchProcessObject(expandArgv1) {
|
||||
|
@ -106,10 +106,10 @@ port.on('message', (message) => {
|
||||
require('internal/process/policy').setup(manifestSrc, manifestURL);
|
||||
}
|
||||
initializeDeprecations();
|
||||
initializeFrozenIntrinsics();
|
||||
initializeCJSLoader();
|
||||
initializeESMLoader();
|
||||
loadPreloadModules();
|
||||
initializeFrozenIntrinsics();
|
||||
publicWorker.parentPort = publicPort;
|
||||
publicWorker.workerData = workerData;
|
||||
|
||||
|
10
test/fixtures/intrinsic-mutation.js
vendored
Normal file
10
test/fixtures/intrinsic-mutation.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
Object.defineProperty(
|
||||
Object.prototype,
|
||||
'flatten', {
|
||||
enumerable: false,
|
||||
// purposefully named something that
|
||||
// would never land in JS itself
|
||||
value: function smoosh() {}
|
||||
}
|
||||
);
|
2
test/fixtures/print-intrinsic-mutation-name.js
vendored
Normal file
2
test/fixtures/print-intrinsic-mutation-name.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
console.log({}.flatten.name);
|
3
test/fixtures/worker-from-argv.js
vendored
Normal file
3
test/fixtures/worker-from-argv.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
const {Worker} = require('worker_threads');
|
||||
new Worker(process.argv[2]).on('exit', process.exit);
|
@ -23,6 +23,9 @@ const fixtureA = fixtures.path('printA.js');
|
||||
const fixtureB = fixtures.path('printB.js');
|
||||
const fixtureC = fixtures.path('printC.js');
|
||||
const fixtureD = fixtures.path('define-global.js');
|
||||
const fixtureE = fixtures.path('intrinsic-mutation.js');
|
||||
const fixtureF = fixtures.path('print-intrinsic-mutation-name.js');
|
||||
const fixtureG = fixtures.path('worker-from-argv.js');
|
||||
const fixtureThrows = fixtures.path('throws_error4.js');
|
||||
|
||||
// Test preloading a single module works
|
||||
@ -62,6 +65,32 @@ childProcess.exec(
|
||||
}
|
||||
);
|
||||
|
||||
// Test that preload can be used with --frozen-intrinsics
|
||||
childProcess.exec(
|
||||
`"${nodeBinary}" --frozen-intrinsics ${
|
||||
preloadOption([fixtureE])
|
||||
} ${
|
||||
fixtureF
|
||||
}`,
|
||||
function(err, stdout) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(stdout, 'smoosh\n');
|
||||
}
|
||||
);
|
||||
childProcess.exec(
|
||||
`"${
|
||||
nodeBinary
|
||||
}" --frozen-intrinsics ${
|
||||
preloadOption([fixtureE])
|
||||
} ${
|
||||
fixtureG
|
||||
} ${fixtureF}`,
|
||||
function(err, stdout) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(stdout, 'smoosh\n');
|
||||
}
|
||||
);
|
||||
|
||||
// Test that preload can be used with stdin
|
||||
const stdinProc = childProcess.spawn(
|
||||
nodeBinary,
|
||||
|
Loading…
Reference in New Issue
Block a user