mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 09:02:40 +00:00

It turns out that using `v8::Locker` undoes the effects of passing an explicit stack limit as part of the `Isolate`’s resource constraints. Therefore, reset the stack limit manually after entering a Locker. Refs: https://github.com/nodejs/node/pull/26049#issuecomment-580668530 PR-URL: https://github.com/nodejs/node/pull/31593 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { once } = require('events');
|
|
const v8 = require('v8');
|
|
const { Worker } = require('worker_threads');
|
|
|
|
// Verify that Workers don't care about --stack-size, as they have their own
|
|
// fixed and known stack sizes.
|
|
|
|
async function runWorker() {
|
|
const empiricalStackDepth = new Uint32Array(new SharedArrayBuffer(4));
|
|
const worker = new Worker(`
|
|
const { workerData: { empiricalStackDepth } } = require('worker_threads');
|
|
function f() {
|
|
empiricalStackDepth[0]++;
|
|
f();
|
|
}
|
|
f();`, {
|
|
eval: true,
|
|
workerData: { empiricalStackDepth }
|
|
});
|
|
|
|
const [ error ] = await once(worker, 'error');
|
|
|
|
common.expectsError({
|
|
constructor: RangeError,
|
|
message: 'Maximum call stack size exceeded'
|
|
})(error);
|
|
|
|
return empiricalStackDepth[0];
|
|
}
|
|
|
|
(async function() {
|
|
v8.setFlagsFromString('--stack-size=500');
|
|
const w1stack = await runWorker();
|
|
v8.setFlagsFromString('--stack-size=1000');
|
|
const w2stack = await runWorker();
|
|
// Make sure the two stack sizes are within 10 % of each other, i.e. not
|
|
// affected by the different `--stack-size` settings.
|
|
assert(Math.max(w1stack, w2stack) / Math.min(w1stack, w2stack) < 1.1,
|
|
`w1stack = ${w1stack}, w2stack ${w2stack} are too far apart`);
|
|
})().then(common.mustCall());
|