-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
src: fixup Error.stackTraceLimit during snapshot building #55121
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0d5185f
src: parse --stack-trace-limit and use it in --trace-* flags
joyeecheung de5862a
src: fixup Error.stackTraceLimit during snapshot building
joyeecheung 644043c
fixup! src: fixup Error.stackTraceLimit during snapshot building
joyeecheung ceeee4d
fixup! src: fixup Error.stackTraceLimit during snapshot building
joyeecheung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| 'use strict'; | ||
|
|
||
| // This is meant to be run with --trace-exit. | ||
|
|
||
| const depth = parseInt(process.env.STACK_DEPTH) || 30; | ||
| let counter = 1; | ||
| function recurse() { | ||
| if (counter++ < depth) { | ||
| recurse(); | ||
| } else { | ||
| process.exit(0); | ||
| } | ||
| } | ||
|
|
||
| recurse(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
|
|
||
| const { | ||
| setDeserializeMainFunction, | ||
| } = require('v8').startupSnapshot; | ||
|
|
||
| console.log(`During snapshot building, Error.stackTraceLimit =`, Error.stackTraceLimit); | ||
| console.log(getError('During snapshot building', 30)); | ||
|
|
||
| setDeserializeMainFunction(() => { | ||
| console.log(`After snapshot deserialization, Error.stackTraceLimit =`, Error.stackTraceLimit); | ||
| console.log(getError('After snapshot deserialization', 30)); | ||
| }); | ||
|
|
||
| function getError(message, depth) { | ||
| let counter = 1; | ||
| function recurse() { | ||
| if (counter++ < depth) { | ||
| return recurse(); | ||
| } | ||
| const error = new Error(message); | ||
| return error.stack; | ||
| } | ||
| return recurse(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
|
|
||
| const { | ||
| setDeserializeMainFunction, | ||
| } = require('v8').startupSnapshot; | ||
| const assert = require('assert'); | ||
|
|
||
| // Check that mutation to Error.stackTraceLimit is effective in the snapshot | ||
| // builder script. | ||
| assert.strictEqual(typeof Error.stackTraceLimit, 'number'); | ||
| Error.stackTraceLimit = 0; | ||
| assert.strictEqual(getError('', 30), 'Error'); | ||
|
|
||
| setDeserializeMainFunction(() => { | ||
| // Check that the mutation is preserved in the deserialized main function. | ||
| assert.strictEqual(Error.stackTraceLimit, 0); | ||
| assert.strictEqual(getError('', 30), 'Error'); | ||
|
|
||
| // Check that it can still be mutated. | ||
| Error.stackTraceLimit = 10; | ||
| const error = getError('', 30); | ||
| const matches = [...error.matchAll(/at recurse/g)]; | ||
| assert.strictEqual(matches.length, 10); | ||
| }); | ||
|
|
||
| function getError(message, depth) { | ||
| let counter = 1; | ||
| function recurse() { | ||
| if (counter++ < depth) { | ||
| return recurse(); | ||
| } | ||
| const error = new Error(message); | ||
| return error.stack; | ||
| } | ||
| return recurse(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| 'use strict'; | ||
|
|
||
| // This tests mutation to Error.stackTraceLimit in both the snapshot builder script | ||
| // and the snapshot main script work. | ||
|
|
||
| require('../common'); | ||
| const assert = require('assert'); | ||
| const tmpdir = require('../common/tmpdir'); | ||
| const fixtures = require('../common/fixtures'); | ||
| const { spawnSyncAndAssert, spawnSyncAndExitWithoutError } = require('../common/child_process'); | ||
|
|
||
| const blobPath = tmpdir.resolve('snapshot.blob'); | ||
|
|
||
| { | ||
| tmpdir.refresh(); | ||
| // Check the mutation works without --stack-trace-limit. | ||
| spawnSyncAndAssert(process.execPath, [ | ||
| '--snapshot-blob', | ||
| blobPath, | ||
| '--build-snapshot', | ||
| fixtures.path('snapshot', 'mutate-error-stack-trace-limit.js'), | ||
| ], { | ||
| cwd: tmpdir.path | ||
| }, { | ||
| stderr(output) { | ||
| assert.match(output, /Error\.stackTraceLimit has been modified by the snapshot builder script/); | ||
| assert.match(output, /It will be preserved after snapshot deserialization/); | ||
| } | ||
| }); | ||
| spawnSyncAndExitWithoutError(process.execPath, [ | ||
| '--snapshot-blob', | ||
| blobPath, | ||
| ], { | ||
| cwd: tmpdir.path | ||
| }); | ||
| } | ||
|
|
||
| { | ||
| tmpdir.refresh(); | ||
| // Check the mutation works with --stack-trace-limit. | ||
| spawnSyncAndAssert(process.execPath, [ | ||
| '--stack-trace-limit=50', | ||
| '--snapshot-blob', | ||
| blobPath, | ||
| '--build-snapshot', | ||
| fixtures.path('snapshot', 'mutate-error-stack-trace-limit.js'), | ||
| ], { | ||
| cwd: tmpdir.path | ||
| }, { | ||
| stderr(output) { | ||
| assert.match(output, /Error\.stackTraceLimit has been modified by the snapshot builder script/); | ||
| assert.match(output, /It will be preserved after snapshot deserialization/); | ||
| } | ||
| }); | ||
| spawnSyncAndExitWithoutError(process.execPath, [ | ||
| // This checks that --stack-trace-limit=50 is ignored if the buidler script already mutated | ||
| // Error.stackTraceLimit. | ||
| '--stack-trace-limit=50', | ||
| '--snapshot-blob', | ||
| blobPath, | ||
| ], { | ||
| cwd: tmpdir.path | ||
| }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.