Skip to content

Commit f155dfe

Browse files
addaleaxMylesBorins
authored andcommitted
test: expand Worker test for non-shared ArrayBuffer
This test would be broken by V8 7.9 due to the changed `ArrayBuffer` backing store management (the same way that V8 7.8 broke this for `SharedArrayBuffer`s). While working on a solution, it would be good to already have this test in Node.js to avoid unnecessary accidental breakage. Refs: nodejs/node-v8#115 PR-URL: #30044 Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 0c88dc1 commit f155dfe

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

‎test/parallel/test-worker-sharedarraybuffer-from-worker-thread.js‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ const assert = require('assert');
55
const{ Worker }=require('worker_threads');
66

77
// Regression test for https://github.com/nodejs/node/issues/28777
8-
// Make sure that SharedArrayBuffers created in Worker threads are accessible
9-
// after the creating thread ended.
8+
// Make sure that SharedArrayBuffers and transferred ArrayBuffers created in
9+
// Worker threads are accessible after the creating thread ended.
1010

11-
constw=newWorker(`
12-
const{parentPort } = require('worker_threads');
13-
const sharedArrayBuffer = new SharedArrayBuffer(4);
14-
parentPort.postMessage(sharedArrayBuffer);
15-
`,{eval: true});
11+
for(constctorof['ArrayBuffer','SharedArrayBuffer']){
12+
constw=newWorker(`
13+
const{parentPort } = require('worker_threads');
14+
const arrayBuffer = new ${ctor}(4);
15+
parentPort.postMessage(
16+
arrayBuffer,
17+
'${ctor}' === 'SharedArrayBuffer' ? [] : [arrayBuffer]);
18+
`,{eval: true});
1619

17-
letsharedArrayBuffer;
18-
w.once('message',common.mustCall((message)=>sharedArrayBuffer=message));
19-
w.once('exit',common.mustCall(()=>{
20-
constuint8array=newUint8Array(sharedArrayBuffer);
21-
uint8array[0]=42;
22-
assert.deepStrictEqual(uint8array,newUint8Array([42,0,0,0]));
23-
}));
20+
letarrayBuffer;
21+
w.once('message',common.mustCall((message)=>arrayBuffer=message));
22+
w.once('exit',common.mustCall(()=>{
23+
assert.strictEqual(arrayBuffer.constructor.name,ctor);
24+
constuint8array=newUint8Array(arrayBuffer);
25+
uint8array[0]=42;
26+
assert.deepStrictEqual(uint8array,newUint8Array([42,0,0,0]));
27+
}));
28+
}

0 commit comments

Comments
(0)