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: fixup Error.stackTraceLimit for user-land snapshot #44203

Merged
merged 4 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ function lazyBuffer() {
}

function isErrorStackTraceLimitWritable() {
// Do no touch Error.stackTraceLimit as V8 would attempt to install
// it again during deserialization.
if (require('v8').startupSnapshot.isBuildingSnapshot()) {
return false;
}

const desc = ObjectGetOwnPropertyDescriptor(Error, 'stackTraceLimit');
if (desc === undefined) {
return ObjectIsExtensible(Error);
Expand Down
31 changes: 29 additions & 2 deletions lib/internal/main/mksnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
const {
Error,
SafeSet,
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
SafeArrayIterator
SafeArrayIterator,
ObjectPrototypeHasOwnProperty,
ObjectGetOwnPropertyDescriptor,
ObjectDefineProperty
} = primordials;

const binding = internalBinding('mksnapshot');
Expand Down Expand Up @@ -125,7 +128,21 @@ function main() {
const source = readFileSync(file, 'utf-8');
const serializeMainFunction = compileSerializeMain(filename, source);

require('internal/v8/startup_snapshot').initializeCallbacks();
const {
initializeCallbacks,
namespace: {
addSerializeCallback,
addDeserializeCallback,
},
} = require('internal/v8/startup_snapshot');
initializeCallbacks();

let stackTraceLimitDesc;
addDeserializeCallback(() => {
if (stackTraceLimitDesc !== undefined) {
ObjectDefineProperty(Error, 'stackTraceLimit', stackTraceLimitDesc);
}
});

if (getOptionValue('--inspect-brk')) {
internalBinding('inspector').callAndPauseOnStart(
Expand All @@ -134,6 +151,16 @@ function main() {
} else {
serializeMainFunction(requireForUserSnapshot, filename, dirname);
}

addSerializeCallback(() => {
if (ObjectPrototypeHasOwnProperty(Error, 'stackTraceLimit')) {
stackTraceLimitDesc =
ObjectGetOwnPropertyDescriptor(Error, 'stackTraceLimit');
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
process._rawDebug('Deleting Error.stackTraceLimit from the snapshot. ' +
'It will be re-installed after deserialization');
delete Error.stackTraceLimit;
}
});
}

main();
2 changes: 0 additions & 2 deletions lib/internal/v8/startup_snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ function runSerializeCallbacks() {
const { 0: callback, 1: data } = serializeCallbacks.shift();
callback(data);
}
// Remove the hooks from the snapshot.
require('v8').startupSnapshot = undefined;
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
}

function addSerializeCallback(callback, data) {
Expand Down
7 changes: 1 addition & 6 deletions test/parallel/test-snapshot-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

// This tests the TypeScript compiler in the snapshot.

const common = require('../common');

if (process.features.debug) {
common.skip('V8 snapshot does not work with mutated globals yet: ' +
'https://bugs.chromium.org/p/v8/issues/detail?id=12772');
}
require('../common');

const assert = require('assert');
const { spawnSync } = require('child_process');
Expand Down
7 changes: 1 addition & 6 deletions test/parallel/test-snapshot-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
// during snapshot serialization and installed again during
// deserialization.

const common = require('../common');

if (process.features.debug) {
common.skip('V8 snapshot does not work with mutated globals yet: ' +
'https://bugs.chromium.org/p/v8/issues/detail?id=12772');
}
require('../common');

const assert = require('assert');
const { spawnSync } = require('child_process');
Expand Down