Skip to content

Commit 56e0299

Browse files
committed
snapshot: insert argv[0] at argv[1] in setDeserializeMainFunction
1 parent 9c4ca0a commit 56e0299

8 files changed

Lines changed: 11 additions & 10 deletions

File tree

doc/api/v8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ v8.startupSnapshot.setDeserializeMainFunction((shelf) => {
13621362
// process.env and process.argv are refreshed during snapshot
13631363
// deserialization.
13641364
const lang = process.env.BOOK_LANG || 'en_US';
1365-
const book = process.argv[1];
1365+
const book = process.argv[2];
13661366
const name = `${book}.${lang}.txt`;
13671367
console.log(shelf.storage.get(name));
13681368
}, shelf);

lib/internal/v8/startup_snapshot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ function setDeserializeMainFunction(callback, data) {
106106
markBootstrapComplete,
107107
} = require('internal/process/pre_execution');
108108

109-
// This should be in sync with run_main_module.js until we make that
110-
// a built-in main function.
111-
// TODO(joyeecheung): make a copy of argv[0] and insert it as argv[1].
112109
prepareMainThreadExecution(false);
110+
// Like SEA (FixupArgsForSEA), insert argv[0] at argv[1] so that user
111+
// args begin at argv[2], consistent with run_main_module.js.
112+
process.argv.splice(1, 0, process.argv[0]);
113113
markBootstrapComplete();
114114
callback(data);
115115
});

test/embedding/test-embedding-snapshot-as-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ spawnSyncAndAssert(
4343
stdout(output) {
4444
assert.deepStrictEqual(JSON.parse(output), {
4545
originalArgv: [embedtest, '__node_anonymous_main', ...buildSnapshotExecArgs],
46-
currentArgv: [embedtest, ...runSnapshotExecArgs],
46+
currentArgv: [embedtest, embedtest, ...runSnapshotExecArgs],
4747
});
4848
return true;
4949
},

test/embedding/test-embedding-snapshot-basic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ spawnSyncAndAssert(
4343
stdout(output) {
4444
assert.deepStrictEqual(JSON.parse(output), {
4545
originalArgv: [embedtest, '__node_anonymous_main', ...buildSnapshotExecArgs],
46-
currentArgv: [embedtest, ...runSnapshotExecArgs],
46+
currentArgv: [embedtest, embedtest, ...runSnapshotExecArgs],
4747
});
4848
return true;
4949
},

test/embedding/test-embedding-snapshot-without-code-cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ spawnSyncAndAssert(
4343
stdout(output) {
4444
assert.deepStrictEqual(JSON.parse(output), {
4545
originalArgv: [embedtest, '__node_anonymous_main', ...buildSnapshotExecArgs],
46-
currentArgv: [embedtest, ...runSnapshotExecArgs],
46+
currentArgv: [embedtest, embedtest, ...runSnapshotExecArgs],
4747
});
4848
return true;
4949
},

test/fixtures/snapshot/typescript-main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const v8 = require('v8');
99
const assert = require('assert');
1010

1111
v8.startupSnapshot.setDeserializeMainFunction(( { ts }) => {
12-
const input = process.argv[1];
13-
const output = process.argv[2];
12+
const input = process.argv[2];
13+
const output = process.argv[3];
1414
console.error(`Compiling ${input} to ${output}`);
1515
assert(input);
1616
assert(output);

test/fixtures/snapshot/v8-startup-snapshot-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ v8.startupSnapshot.setDeserializeMainFunction((shelf) => {
4848
// process.env and process.argv are refreshed during snapshot
4949
// deserialization.
5050
const lang = process.env.BOOK_LANG || 'en_US';
51-
const book = process.argv[1];
51+
const book = process.argv[2];
5252
const name = `${book}.${lang}.txt`;
5353
console.error('Reading', name);
5454
console.log(shelf.storage.get(name).toString());

test/parallel/test-snapshot-argv1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ require('v8').startupSnapshot.setDeserializeMainFunction(() => {
4949

5050
const stdout = JSON.parse(child.stdout.toString().trim());
5151
assert.deepStrictEqual(stdout, [
52+
process.execPath,
5253
process.execPath,
5354
'argv1',
5455
'argv2',

0 commit comments

Comments
 (0)