Index: src/value-serializer.cc |
diff --git a/src/value-serializer.cc b/src/value-serializer.cc |
index c33dc8ed729af65f5869895b37091a88a1af744d..0e3a6a6e1e04346a71f287364bf6408238f63d73 100644 |
--- a/src/value-serializer.cc |
+++ b/src/value-serializer.cc |
@@ -110,8 +110,8 @@ enum class SerializationTag : uint8_t { |
// ObjectReference to one) serialized just before it. This is a quirk arising |
// from the previous stack-based implementation. |
kArrayBufferView = 'V', |
- // Shared array buffer (transferred). transferID:uint32_t |
- kSharedArrayBufferTransfer = 'u', |
+ // Shared array buffer. transferID:uint32_t |
+ kSharedArrayBuffer = 'u', |
// Compiled WebAssembly module. encodingType:(one-byte tag). |
// If encodingType == 'y' (raw bytes): |
// wasmWireByteLength:uint32_t, then raw data |
@@ -269,6 +269,7 @@ std::pair<uint8_t*, size_t> ValueSerializer::Release() { |
void ValueSerializer::TransferArrayBuffer(uint32_t transfer_id, |
Handle<JSArrayBuffer> array_buffer) { |
DCHECK(!array_buffer_transfer_map_.Find(array_buffer)); |
+ DCHECK(!array_buffer->is_shared()); |
array_buffer_transfer_map_.Set(array_buffer, transfer_id); |
} |
@@ -442,7 +443,7 @@ Maybe<bool> ValueSerializer::WriteJSReceiver(Handle<JSReceiver> receiver) { |
case JS_SET_TYPE: |
return WriteJSSet(Handle<JSSet>::cast(receiver)); |
case JS_ARRAY_BUFFER_TYPE: |
- return WriteJSArrayBuffer(JSArrayBuffer::cast(*receiver)); |
+ return WriteJSArrayBuffer(Handle<JSArrayBuffer>::cast(receiver)); |
case JS_TYPED_ARRAY_TYPE: |
case JS_DATA_VIEW_TYPE: |
return WriteJSArrayBufferView(JSArrayBufferView::cast(*receiver)); |
@@ -724,28 +725,37 @@ Maybe<bool> ValueSerializer::WriteJSSet(Handle<JSSet> set) { |
return Just(true); |
} |
-Maybe<bool> ValueSerializer::WriteJSArrayBuffer(JSArrayBuffer* array_buffer) { |
+Maybe<bool> ValueSerializer::WriteJSArrayBuffer( |
+ Handle<JSArrayBuffer> array_buffer) { |
+ if (array_buffer->is_shared()) { |
+ if (!delegate_) { |
+ ThrowDataCloneError(MessageTemplate::kDataCloneError, array_buffer); |
+ return Nothing<bool>(); |
+ } |
+ |
+ v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_); |
+ Maybe<uint32_t> index = delegate_->GetSharedArrayBufferId( |
+ v8_isolate, Utils::ToLocalShared(array_buffer)); |
+ RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate_, Nothing<bool>()); |
+ |
+ WriteTag(SerializationTag::kSharedArrayBuffer); |
+ WriteVarint(index.FromJust()); |
+ return Just(true); |
+ } |
+ |
uint32_t* transfer_entry = array_buffer_transfer_map_.Find(array_buffer); |
if (transfer_entry) { |
- WriteTag(array_buffer->is_shared() |
- ? SerializationTag::kSharedArrayBufferTransfer |
- : SerializationTag::kArrayBufferTransfer); |
+ WriteTag(SerializationTag::kArrayBufferTransfer); |
WriteVarint(*transfer_entry); |
return Just(true); |
} |
- |
- if (array_buffer->is_shared()) { |
- ThrowDataCloneError( |
- MessageTemplate::kDataCloneErrorSharedArrayBufferNotTransferred); |
- return Nothing<bool>(); |
- } |
if (array_buffer->was_neutered()) { |
ThrowDataCloneError(MessageTemplate::kDataCloneErrorNeuteredArrayBuffer); |
return Nothing<bool>(); |
} |
double byte_length = array_buffer->byte_length()->Number(); |
if (byte_length > std::numeric_limits<uint32_t>::max()) { |
- ThrowDataCloneError(MessageTemplate::kDataCloneError, handle(array_buffer)); |
+ ThrowDataCloneError(MessageTemplate::kDataCloneError, array_buffer); |
return Nothing<bool>(); |
} |
WriteTag(SerializationTag::kArrayBuffer); |
@@ -1105,7 +1115,7 @@ MaybeHandle<Object> ValueDeserializer::ReadObjectInternal() { |
const bool is_shared = false; |
return ReadTransferredJSArrayBuffer(is_shared); |
} |
- case SerializationTag::kSharedArrayBufferTransfer: { |
+ case SerializationTag::kSharedArrayBuffer: { |
const bool is_shared = true; |
return ReadTransferredJSArrayBuffer(is_shared); |
} |