Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 293c9f0

Browse filesBrowse files
bmeckBridgeAR
authored andcommitted
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: #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>
1 parent a7c8322 commit 293c9f0
Copy full SHA for 293c9f0

File tree

Expand file treeCollapse file tree

7 files changed

+49
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+49
-2
lines changed
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+3Lines changed: 3 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ Support is currently only provided for the root context and no guarantees are
218218
currently provided that `global.Array` is indeed the default intrinsic
219219
reference. Code may break under this flag.
220220

221+
`--require` runs prior to freezing intrinsics in order to allow polyfills to
222+
be added.
223+
221224
### `--heapsnapshot-signal=signal`
222225
<!-- YAML
223226
added: v12.0.0
Collapse file

‎lib/internal/bootstrap/pre_execution.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/pre_execution.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ function prepareMainThreadExecution(expandArgv1 = false) {
4848
initializeClusterIPC();
4949

5050
initializeDeprecations();
51-
initializeFrozenIntrinsics();
5251
initializeCJSLoader();
5352
initializeESMLoader();
5453
loadPreloadModules();
54+
initializeFrozenIntrinsics();
5555
}
5656

5757
function patchProcessObject(expandArgv1) {
Collapse file

‎lib/internal/main/worker_thread.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/worker_thread.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ port.on('message', (message) => {
106106
require('internal/process/policy').setup(manifestSrc, manifestURL);
107107
}
108108
initializeDeprecations();
109-
initializeFrozenIntrinsics();
110109
initializeCJSLoader();
111110
initializeESMLoader();
112111
loadPreloadModules();
112+
initializeFrozenIntrinsics();
113113
publicWorker.parentPort = publicPort;
114114
publicWorker.workerData = workerData;
115115

Collapse file
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
Object.defineProperty(
3+
Object.prototype,
4+
'flatten', {
5+
enumerable: false,
6+
// purposefully named something that
7+
// would never land in JS itself
8+
value: function smoosh() {}
9+
}
10+
);
Collapse file
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
'use strict';
2+
console.log({}.flatten.name);
Collapse file

‎test/fixtures/worker-from-argv.js‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
const {Worker} = require('worker_threads');
3+
new Worker(process.argv[2]).on('exit', process.exit);
Collapse file

‎test/parallel/test-preload.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-preload.js
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const fixtureA = fixtures.path('printA.js');
2323
const fixtureB = fixtures.path('printB.js');
2424
const fixtureC = fixtures.path('printC.js');
2525
const fixtureD = fixtures.path('define-global.js');
26+
const fixtureE = fixtures.path('intrinsic-mutation.js');
27+
const fixtureF = fixtures.path('print-intrinsic-mutation-name.js');
28+
const fixtureG = fixtures.path('worker-from-argv.js');
2629
const fixtureThrows = fixtures.path('throws_error4.js');
2730

2831
// Test preloading a single module works
@@ -62,6 +65,32 @@ childProcess.exec(
6265
}
6366
);
6467

68+
// Test that preload can be used with --frozen-intrinsics
69+
childProcess.exec(
70+
`"${nodeBinary}" --frozen-intrinsics ${
71+
preloadOption([fixtureE])
72+
} ${
73+
fixtureF
74+
}`,
75+
function(err, stdout) {
76+
assert.ifError(err);
77+
assert.strictEqual(stdout, 'smoosh\n');
78+
}
79+
);
80+
childProcess.exec(
81+
`"${
82+
nodeBinary
83+
}" --frozen-intrinsics ${
84+
preloadOption([fixtureE])
85+
} ${
86+
fixtureG
87+
} ${fixtureF}`,
88+
function(err, stdout) {
89+
assert.ifError(err);
90+
assert.strictEqual(stdout, 'smoosh\n');
91+
}
92+
);
93+
6594
// Test that preload can be used with stdin
6695
const stdinProc = childProcess.spawn(
6796
nodeBinary,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.