Skip to content
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,
Comment thread
joyeecheung marked this conversation as resolved.
Outdated
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');
Comment thread
joyeecheung marked this conversation as resolved.
Outdated
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;
Comment thread
joyeecheung marked this conversation as 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