|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const { once } = require('events'); |
| 5 | +const v8 = require('v8'); |
| 6 | +const { Worker } = require('worker_threads'); |
| 7 | + |
| 8 | +// Verify that Workers don't care about --stack-size, as they have their own |
| 9 | +// fixed and known stack sizes. |
| 10 | + |
| 11 | +async function runWorker() { |
| 12 | + const empiricalStackDepth = new Uint32Array(new SharedArrayBuffer(4)); |
| 13 | + const worker = new Worker(` |
| 14 | + const { workerData: { empiricalStackDepth } } = require('worker_threads'); |
| 15 | + function f() { |
| 16 | + empiricalStackDepth[0]++; |
| 17 | + f(); |
| 18 | + } |
| 19 | + f();`, { |
| 20 | + eval: true, |
| 21 | + workerData: { empiricalStackDepth } |
| 22 | + }); |
| 23 | + |
| 24 | + const [ error ] = await once(worker, 'error'); |
| 25 | + |
| 26 | + common.expectsError({ |
| 27 | + constructor: RangeError, |
| 28 | + message: 'Maximum call stack size exceeded' |
| 29 | + })(error); |
| 30 | + |
| 31 | + return empiricalStackDepth[0]; |
| 32 | +} |
| 33 | + |
| 34 | +(async function() { |
| 35 | + v8.setFlagsFromString('--stack-size=500'); |
| 36 | + const w1stack = await runWorker(); |
| 37 | + v8.setFlagsFromString('--stack-size=1000'); |
| 38 | + const w2stack = await runWorker(); |
| 39 | + // Make sure the two stack sizes are within 10 % of each other, i.e. not |
| 40 | + // affected by the different `--stack-size` settings. |
| 41 | + assert(Math.max(w1stack, w2stack) / Math.min(w1stack, w2stack) < 1.1, |
| 42 | + `w1stack = ${w1stack}, w2stack ${w2stack} are too far apart`); |
| 43 | +})().then(common.mustCall()); |
0 commit comments