Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ecf6ae8

Browse filesBrowse files
addaleaxtargos
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 <zyszys98@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 4b57088 commit ecf6ae8
Copy full SHA for ecf6ae8

File tree

Expand file treeCollapse file tree

1 file changed

+19
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-14
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-worker-sharedarraybuffer-from-worker-thread.js
+19-14Lines 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-
const w = new Worker(`
12-
const { parentPort } = require('worker_threads');
13-
const sharedArrayBuffer = new SharedArrayBuffer(4);
14-
parentPort.postMessage(sharedArrayBuffer);
15-
`, { eval: true });
11+
for (const ctor of ['ArrayBuffer', 'SharedArrayBuffer']) {
12+
const w = new Worker(`
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-
let sharedArrayBuffer;
18-
w.once('message', common.mustCall((message) => sharedArrayBuffer = message));
19-
w.once('exit', common.mustCall(() => {
20-
const uint8array = new Uint8Array(sharedArrayBuffer);
21-
uint8array[0] = 42;
22-
assert.deepStrictEqual(uint8array, new Uint8Array([42, 0, 0, 0]));
23-
}));
20+
let arrayBuffer;
21+
w.once('message', common.mustCall((message) => arrayBuffer = message));
22+
w.once('exit', common.mustCall(() => {
23+
assert.strictEqual(arrayBuffer.constructor.name, ctor);
24+
const uint8array = new Uint8Array(arrayBuffer);
25+
uint8array[0] = 42;
26+
assert.deepStrictEqual(uint8array, new Uint8Array([42, 0, 0, 0]));
27+
}));
28+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.