mirror of
https://github.com/nodejs/node.git
synced 2024-11-24 20:29:23 +01:00
33bbf3751b
When V8 creates a context for snapshot building, it does not install Error.stackTraceLimit. As a result, error.stack would be undefined in the snapshot builder script unless users explicitly initialize Error.stackTraceLimit, which may be surprising. This patch initializes Error.stackTraceLimit based on the value of --stack-trace-limit to prevent the surprise. If users have modified Error.stackTraceLimit in the builder script, the modified value would be restored during deserialization. Otherwise, the fixed up limit would be deleted since V8 expects to find it unset and re-initialize it during snapshot deserialization. PR-URL: https://github.com/nodejs/node/pull/55121 Fixes: https://github.com/nodejs/node/issues/55100 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
'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');
|
|
|
|
function test(additionalArguments = [], additionalEnv = {}) {
|
|
tmpdir.refresh();
|
|
// Check the mutation works without --stack-trace-limit.
|
|
spawnSyncAndAssert(process.execPath, [
|
|
...additionalArguments,
|
|
'--snapshot-blob',
|
|
blobPath,
|
|
'--build-snapshot',
|
|
fixtures.path('snapshot', 'mutate-error-stack-trace-limit.js'),
|
|
], {
|
|
cwd: tmpdir.path,
|
|
env: {
|
|
...process.env,
|
|
...additionalEnv,
|
|
}
|
|
}, {
|
|
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
|
|
});
|
|
}
|
|
|
|
test();
|
|
test([], { TEST_IN_SERIALIZER: 1 });
|
|
test(['--stack-trace-limit=50']);
|
|
test(['--stack-trace-limit=50'], { TEST_IN_SERIALIZER: 1 });
|