Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap: run preload prior to --frozen-intrinsics #28940

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
sam-github marked this conversation as resolved.
Show resolved Hide resolved
be added.

### `--heapsnapshot-signal=signal`
<!-- YAML
added: v12.0.0
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ function prepareMainThreadExecution(expandArgv1 = false) {
initializeClusterIPC();

initializeDeprecations();
initializeFrozenIntrinsics();
initializeCJSLoader();
initializeESMLoader();
loadPreloadModules();
initializeFrozenIntrinsics();
addaleax marked this conversation as resolved.
Show resolved Hide resolved
}

function patchProcessObject(expandArgv1) {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/intrinsic-mutation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
Object.defineProperty(
bmeck marked this conversation as resolved.
Show resolved Hide resolved
Object.prototype,
'flatten', {
enumerable: false,
// purposefully named something that
// would never land in JS itself
value: function smoosh() {}
}
);
2 changes: 2 additions & 0 deletions test/fixtures/print-intrinsic-mutation-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';
console.log({}.flatten.name);
3 changes: 3 additions & 0 deletions test/fixtures/worker-from-argv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
const {Worker} = require('worker_threads');
new Worker(process.argv[2]).on('exit', process.exit);
29 changes: 29 additions & 0 deletions test/parallel/test-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down