forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-worker-stack-overflow-stack-size.js
More file actions
40 lines (34 loc) · 1.08 KB
/
test-worker-stack-overflow-stack-size.js
File metadata and controls
40 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'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();
assert.strictEqual(w1stack, w2stack);
})().then(common.mustCall());