summaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-message-port-multiple-sharedarraybuffers.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-07-06 22:09:52 +0200
committerRich Trott <rtrott@gmail.com>2019-07-08 21:03:05 -0700
commitdb55c3cfc14775cda810efc58bb8d7c1b7c356c4 (patch)
treec9f7570cd46dfddace659fae1eabb9edcf65e0c3 /test/parallel/test-worker-message-port-multiple-sharedarraybuffers.js
parent7e50bb3dce11988284c7ca9e2316c086aefac1e1 (diff)
downloadandroid-node-v8-db55c3cfc14775cda810efc58bb8d7c1b7c356c4.tar.gz
android-node-v8-db55c3cfc14775cda810efc58bb8d7c1b7c356c4.tar.bz2
android-node-v8-db55c3cfc14775cda810efc58bb8d7c1b7c356c4.zip
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>
Diffstat (limited to 'test/parallel/test-worker-message-port-multiple-sharedarraybuffers.js')
-rw-r--r--test/parallel/test-worker-message-port-multiple-sharedarraybuffers.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/parallel/test-worker-message-port-multiple-sharedarraybuffers.js b/test/parallel/test-worker-message-port-multiple-sharedarraybuffers.js
new file mode 100644
index 0000000000..eb68236e4d
--- /dev/null
+++ b/test/parallel/test-worker-message-port-multiple-sharedarraybuffers.js
@@ -0,0 +1,17 @@
+'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);