summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-07-06 22:09:52 +0200
committerMichaƫl Zasso <targos@protonmail.com>2019-07-20 11:05:23 +0200
commit0e2cbe620312c6e14b450d32fa5186f3a064b780 (patch)
tree6a4f6460086a0a6605a3030623e398b9dc2fad28 /test
parent70c3116783a90c983795ffa9441479ead558b9a3 (diff)
downloadandroid-node-v8-0e2cbe620312c6e14b450d32fa5186f3a064b780.tar.gz
android-node-v8-0e2cbe620312c6e14b450d32fa5186f3a064b780.tar.bz2
android-node-v8-0e2cbe620312c6e14b450d32fa5186f3a064b780.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')
-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);