Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker: fix passing multiple SharedArrayBuffers at once #28582

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using v8::Exception;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Global;
using v8::HandleScope;
using v8::Isolate;
using v8::Just;
Expand Down Expand Up @@ -241,8 +242,10 @@ class SerializerDelegate : public ValueSerializer::Delegate {
Local<SharedArrayBuffer> shared_array_buffer) override {
uint32_t i;
for (i = 0; i < seen_shared_array_buffers_.size(); ++i) {
if (seen_shared_array_buffers_[i] == shared_array_buffer)
if (PersistentToLocal::Strong(seen_shared_array_buffers_[i]) ==
shared_array_buffer) {
return Just(i);
}
}

auto reference = SharedArrayBufferMetadata::ForSharedArrayBuffer(
Expand All @@ -252,7 +255,8 @@ class SerializerDelegate : public ValueSerializer::Delegate {
if (!reference) {
return Nothing<uint32_t>();
}
seen_shared_array_buffers_.push_back(shared_array_buffer);
seen_shared_array_buffers_.emplace_back(
Global<SharedArrayBuffer> { isolate, shared_array_buffer });
msg_->AddSharedArrayBuffer(reference);
return Just(i);
}
Expand Down Expand Up @@ -289,7 +293,7 @@ class SerializerDelegate : public ValueSerializer::Delegate {
Environment* env_;
Local<Context> context_;
Message* msg_;
std::vector<Local<SharedArrayBuffer>> seen_shared_array_buffers_;
std::vector<Global<SharedArrayBuffer>> seen_shared_array_buffers_;
std::vector<MessagePort*> ports_;

friend class worker::Message;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);