0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-worker-message-port-multiple-sharedarraybuffers.js
Anna Henningsen db55c3cfc1 worker: fix passing multiple SharedArrayBuffers at once
V8 has a handle scope below each `GetSharedArrayBufferId()` call,
so using a `v8::Local` that outlives that handle scope to store
references to `SharedArrayBuffer`s is invalid and may cause accidental
de-duplication of passed `SharedArrayBuffer`s.

Use a persistent handle instead to address this issue.

Fixes: https://github.com/nodejs/node/issues/28559

PR-URL: https://github.com/nodejs/node/pull/28582
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2019-07-08 21:03:05 -07:00

18 lines
510 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { MessageChannel } = require('worker_threads');
// Regression test for https://github.com/nodejs/node/issues/28559
const obj = [
[ new SharedArrayBuffer(0), new SharedArrayBuffer(1) ],
[ new SharedArrayBuffer(2), new SharedArrayBuffer(3) ]
];
const { port1, port2 } = new MessageChannel();
port1.once('message', common.mustCall((message) => {
assert.deepStrictEqual(message, obj);
}));
port2.postMessage(obj);