diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/bindings/core/v8/serialization')
9 files changed, 182 insertions, 40 deletions
diff --git a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialization_tag.h b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialization_tag.h index 3cbeb15d057..f65a8add719 100644 --- a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialization_tag.h +++ b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialization_tag.h @@ -68,6 +68,7 @@ enum SerializationTag { // OffscreenCanvas. For OffscreenCanvas // transfer kReadableStreamTransferTag = 'r', // index:uint32_t + kTransformStreamTransferTag = 'm', // index:uint32_t kWritableStreamTransferTag = 'w', // index:uint32_t kDOMPointTag = 'Q', // x:Double, y:Double, z:Double, w:Double kDOMPointReadOnlyTag = 'W', // x:Double, y:Double, z:Double, w:Double diff --git a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.cc b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.cc index 0fbf601bfe2..78a579ae4b4 100644 --- a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.cc +++ b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.cc @@ -49,11 +49,13 @@ #include "third_party/blink/renderer/bindings/core/v8/v8_offscreen_canvas.h" #include "third_party/blink/renderer/bindings/core/v8/v8_readable_stream.h" #include "third_party/blink/renderer/bindings/core/v8/v8_shared_array_buffer.h" +#include "third_party/blink/renderer/bindings/core/v8/v8_transform_stream.h" #include "third_party/blink/renderer/bindings/core/v8/v8_writable_stream.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/imagebitmap/image_bitmap.h" #include "third_party/blink/renderer/core/messaging/message_port.h" #include "third_party/blink/renderer/core/streams/readable_stream.h" +#include "third_party/blink/renderer/core/streams/transform_stream.h" #include "third_party/blink/renderer/core/streams/writable_stream.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h" #include "third_party/blink/renderer/core/typed_arrays/dom_shared_array_buffer.h" @@ -386,32 +388,76 @@ void SerializedScriptValue::TransferReadableStreams( ExceptionState& exception_state) { auto* execution_context = ExecutionContext::From(script_state); for (ReadableStream* readable_stream : readable_streams) { - mojo::MessagePipe pipe; - MessagePort* local_port = MessagePort::Create(*execution_context); - local_port->Entangle(std::move(pipe.handle0)); - readable_stream->Serialize(script_state, local_port, exception_state); + TransferReadableStream(script_state, execution_context, readable_stream, + exception_state); if (exception_state.HadException()) return; - stream_channels_.push_back(MessagePortChannel(std::move(pipe.handle1))); } } +void SerializedScriptValue::TransferReadableStream( + ScriptState* script_state, + ExecutionContext* execution_context, + ReadableStream* readable_stream, + ExceptionState& exception_state) { + MessagePort* local_port = AddStreamChannel(execution_context); + readable_stream->Serialize(script_state, local_port, exception_state); + if (exception_state.HadException()) + return; +} + void SerializedScriptValue::TransferWritableStreams( ScriptState* script_state, const WritableStreamArray& writable_streams, ExceptionState& exception_state) { auto* execution_context = ExecutionContext::From(script_state); for (WritableStream* writable_stream : writable_streams) { - mojo::MessagePipe pipe; - MessagePort* local_port = MessagePort::Create(*execution_context); - local_port->Entangle(std::move(pipe.handle0)); - writable_stream->Serialize(script_state, local_port, exception_state); + TransferWritableStream(script_state, execution_context, writable_stream, + exception_state); + if (exception_state.HadException()) + return; + } +} + +void SerializedScriptValue::TransferWritableStream( + ScriptState* script_state, + ExecutionContext* execution_context, + WritableStream* writable_stream, + ExceptionState& exception_state) { + MessagePort* local_port = AddStreamChannel(execution_context); + writable_stream->Serialize(script_state, local_port, exception_state); + if (exception_state.HadException()) + return; +} + +void SerializedScriptValue::TransferTransformStreams( + ScriptState* script_state, + const TransformStreamArray& transform_streams, + ExceptionState& exception_state) { + auto* execution_context = ExecutionContext::From(script_state); + for (TransformStream* transform_stream : transform_streams) { + TransferReadableStream(script_state, execution_context, + transform_stream->Readable(), exception_state); + if (exception_state.HadException()) + return; + TransferWritableStream(script_state, execution_context, + transform_stream->Writable(), exception_state); if (exception_state.HadException()) return; - stream_channels_.push_back(MessagePortChannel(std::move(pipe.handle1))); } } +// Creates an entangled pair of channels. Adds one end to |stream_channels_| as +// a MessagePortChannel, and returns the other end as a MessagePort. +MessagePort* SerializedScriptValue::AddStreamChannel( + ExecutionContext* execution_context) { + mojo::MessagePipe pipe; + MessagePort* local_port = MessagePort::Create(*execution_context); + local_port->Entangle(std::move(pipe.handle0)); + stream_channels_.push_back(MessagePortChannel(std::move(pipe.handle1))); + return local_port; +} + void SerializedScriptValue::TransferArrayBuffers( v8::Isolate* isolate, const ArrayBufferArray& array_buffers, @@ -592,6 +638,18 @@ bool SerializedScriptValue::ExtractTransferables( return false; } transferables.writable_streams.push_back(stream); + } else if (RuntimeEnabledFeatures::TransferableStreamsEnabled() && + V8TransformStream::HasInstance(transferable_object, isolate)) { + TransformStream* stream = V8TransformStream::ToImpl( + v8::Local<v8::Object>::Cast(transferable_object)); + if (transferables.transform_streams.Contains(stream)) { + exception_state.ThrowDOMException( + DOMExceptionCode::kDataCloneError, + "TransformStream at index " + String::Number(i) + + " is a duplicate of an earlier TransformStream."); + return false; + } + transferables.transform_streams.push_back(stream); } else { exception_state.ThrowTypeError("Value at index " + String::Number(i) + " does not have a transferable type."); diff --git a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h index eea425054ed..0702f58f0bc 100644 --- a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h +++ b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h @@ -53,6 +53,8 @@ namespace blink { class BlobDataHandle; class DOMSharedArrayBuffer; class ExceptionState; +class ExecutionContext; +class MessagePort; class ScriptValue; class SharedBuffer; class StaticBitmapImage; @@ -72,7 +74,7 @@ class CORE_EXPORT SerializedScriptValue using SharedArrayBufferContentsArray = Vector<WTF::ArrayBufferContents, 1>; using ImageBitmapContentsArray = Vector<scoped_refptr<StaticBitmapImage>, 1>; using TransferredWasmModulesArray = - WTF::Vector<v8::WasmCompiledModule::TransferrableModule>; + WTF::Vector<v8::WasmModuleObject::TransferrableModule>; using MessagePortChannelArray = Vector<MessagePortChannel>; // Increment this for each incompatible change to the wire format. @@ -295,9 +297,22 @@ class CORE_EXPORT SerializedScriptValue void TransferReadableStreams(ScriptState*, const ReadableStreamArray&, ExceptionState&); + void TransferReadableStream(ScriptState* script_state, + ExecutionContext* execution_context, + ReadableStream* readable_streams, + ExceptionState& exception_state); void TransferWritableStreams(ScriptState*, const WritableStreamArray&, ExceptionState&); + void TransferWritableStream(ScriptState* script_state, + ExecutionContext* execution_context, + WritableStream* writable_streams, + ExceptionState& exception_state); + void TransferTransformStreams(ScriptState*, + const TransformStreamArray&, + ExceptionState&); + MessagePort* AddStreamChannel(ExecutionContext*); + void CloneSharedArrayBuffers(SharedArrayBufferArray&); DataBufferPtr data_buffer_; size_t data_buffer_size_ = 0; diff --git a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/transferables.h b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/transferables.h index 2408ccf5276..d1937e15699 100644 --- a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/transferables.h +++ b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/transferables.h @@ -19,6 +19,7 @@ class MessagePort; class MojoHandle; class ReadableStream; class WritableStream; +class TransformStream; using ArrayBufferArray = HeapVector<Member<DOMArrayBufferBase>>; using ImageBitmapArray = HeapVector<Member<ImageBitmap>>; @@ -27,6 +28,7 @@ using MessagePortArray = HeapVector<Member<MessagePort>>; using MojoHandleArray = HeapVector<Member<blink::MojoHandle>>; using ReadableStreamArray = HeapVector<Member<ReadableStream>>; using WritableStreamArray = HeapVector<Member<WritableStream>>; +using TransformStreamArray = HeapVector<Member<TransformStream>>; class CORE_EXPORT Transferables final { STACK_ALLOCATED(); @@ -42,6 +44,7 @@ class CORE_EXPORT Transferables final { MojoHandleArray mojo_handles; ReadableStreamArray readable_streams; WritableStreamArray writable_streams; + TransformStreamArray transform_streams; }; // Along with extending |Transferables| to hold a new kind of transferable diff --git a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.cc b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.cc index bf2da93684b..4c6ec62896f 100644 --- a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.cc +++ b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.cc @@ -26,6 +26,7 @@ #include "third_party/blink/renderer/core/mojo/mojo_handle.h" #include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h" #include "third_party/blink/renderer/core/streams/readable_stream.h" +#include "third_party/blink/renderer/core/streams/transform_stream.h" #include "third_party/blink/renderer/core/streams/writable_stream.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h" #include "third_party/blink/renderer/core/typed_arrays/dom_shared_array_buffer.h" @@ -536,6 +537,28 @@ ScriptWrappable* V8ScriptValueDeserializer::ReadDOMObject( script_state_, (*transferred_stream_ports_)[index].Get(), exception_state); } + case kTransformStreamTransferTag: { + if (!RuntimeEnabledFeatures::TransferableStreamsEnabled()) + return nullptr; + uint32_t index = 0; + if (!ReadUint32(&index) || !transferred_stream_ports_ || + index + 1 >= transferred_stream_ports_->size()) { + return nullptr; + } + ReadableStream* readable = ReadableStream::Deserialize( + script_state_, (*transferred_stream_ports_)[index].Get(), + exception_state); + if (!readable) + return nullptr; + + WritableStream* writable = WritableStream::Deserialize( + script_state_, (*transferred_stream_ports_)[index + 1].Get(), + exception_state); + if (!writable) + return nullptr; + + return MakeGarbageCollected<TransformStream>(readable, writable); + } default: break; } @@ -655,15 +678,15 @@ v8::MaybeLocal<v8::Object> V8ScriptValueDeserializer::ReadHostObject( return wrapper.As<v8::Object>(); } -v8::MaybeLocal<v8::WasmCompiledModule> +v8::MaybeLocal<v8::WasmModuleObject> V8ScriptValueDeserializer::GetWasmModuleFromId(v8::Isolate* isolate, uint32_t id) { if (id < serialized_script_value_->WasmModules().size()) { - return v8::WasmCompiledModule::FromTransferrableModule( + return v8::WasmModuleObject::FromTransferrableModule( isolate, serialized_script_value_->WasmModules()[id]); } CHECK(serialized_script_value_->WasmModules().IsEmpty()); - return v8::MaybeLocal<v8::WasmCompiledModule>(); + return v8::MaybeLocal<v8::WasmModuleObject>(); } v8::MaybeLocal<v8::SharedArrayBuffer> diff --git a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.h b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.h index 665dcfe18d7..78511fe2f23 100644 --- a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.h +++ b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.h @@ -100,8 +100,8 @@ class CORE_EXPORT V8ScriptValueDeserializer // v8::ValueDeserializer::Delegate v8::MaybeLocal<v8::Object> ReadHostObject(v8::Isolate*) override; - v8::MaybeLocal<v8::WasmCompiledModule> GetWasmModuleFromId(v8::Isolate*, - uint32_t) override; + v8::MaybeLocal<v8::WasmModuleObject> GetWasmModuleFromId(v8::Isolate*, + uint32_t) override; v8::MaybeLocal<v8::SharedArrayBuffer> GetSharedArrayBufferFromId( v8::Isolate*, uint32_t) override; diff --git a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer.cc b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer.cc index c37928dcd5c..19b2d96dc16 100644 --- a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer.cc +++ b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer.cc @@ -25,6 +25,7 @@ #include "third_party/blink/renderer/bindings/core/v8/v8_readable_stream.h" #include "third_party/blink/renderer/bindings/core/v8/v8_shared_array_buffer.h" #include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h" +#include "third_party/blink/renderer/bindings/core/v8/v8_transform_stream.h" #include "third_party/blink/renderer/bindings/core/v8/v8_writable_stream.h" #include "third_party/blink/renderer/core/geometry/dom_matrix.h" #include "third_party/blink/renderer/core/geometry/dom_matrix_read_only.h" @@ -36,6 +37,7 @@ #include "third_party/blink/renderer/core/html/canvas/image_data.h" #include "third_party/blink/renderer/core/mojo/mojo_handle.h" #include "third_party/blink/renderer/core/streams/readable_stream.h" +#include "third_party/blink/renderer/core/streams/transform_stream.h" #include "third_party/blink/renderer/core/streams/writable_stream.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_base.h" #include "third_party/blink/renderer/platform/file_metadata.h" @@ -170,6 +172,9 @@ void V8ScriptValueSerializer::FinalizeTransfer( return; if (RuntimeEnabledFeatures::TransferableStreamsEnabled()) { + // Order matters here, because the order in which streams are added to the + // |stream_ports_| array must match the indexes which are calculated in + // WriteDOMObject(). serialized_script_value_->TransferReadableStreams( script_state_, transferables_->readable_streams, exception_state); if (exception_state.HadException()) @@ -178,6 +183,10 @@ void V8ScriptValueSerializer::FinalizeTransfer( script_state_, transferables_->writable_streams, exception_state); if (exception_state.HadException()) return; + serialized_script_value_->TransferTransformStreams( + script_state_, transferables_->transform_streams, exception_state); + if (exception_state.HadException()) + return; } } } @@ -193,7 +202,7 @@ void V8ScriptValueSerializer::WriteUTF8String(const String& string) { bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, ExceptionState& exception_state) { const WrapperTypeInfo* wrapper_type_info = wrappable->GetWrapperTypeInfo(); - if (wrapper_type_info == &V8Blob::wrapper_type_info) { + if (wrapper_type_info == V8Blob::GetWrapperTypeInfo()) { Blob* blob = wrappable->ToImpl<Blob>(); serialized_script_value_->BlobDataHandles().Set(blob->Uuid(), blob->GetBlobDataHandle()); @@ -212,11 +221,11 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, } return true; } - if (wrapper_type_info == &V8File::wrapper_type_info) { + if (wrapper_type_info == V8File::GetWrapperTypeInfo()) { WriteTag(blob_info_array_ ? kFileIndexTag : kFileTag); return WriteFile(wrappable->ToImpl<File>(), exception_state); } - if (wrapper_type_info == &V8FileList::wrapper_type_info) { + if (wrapper_type_info == V8FileList::GetWrapperTypeInfo()) { // This does not presently deduplicate a File object and its entry in a // FileList, which is non-standard behavior. FileList* file_list = wrappable->ToImpl<FileList>(); @@ -229,7 +238,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, } return true; } - if (wrapper_type_info == &V8ImageBitmap::wrapper_type_info) { + if (wrapper_type_info == V8ImageBitmap::GetWrapperTypeInfo()) { ImageBitmap* image_bitmap = wrappable->ToImpl<ImageBitmap>(); if (image_bitmap->IsNeutered()) { exception_state.ThrowDOMException( @@ -270,7 +279,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, WriteRawBytes(pixels->Data(), pixels->length()); return true; } - if (wrapper_type_info == &V8ImageData::wrapper_type_info) { + if (wrapper_type_info == V8ImageData::GetWrapperTypeInfo()) { ImageData* image_data = wrappable->ToImpl<ImageData>(); WriteTag(kImageDataTag); SerializedColorParams color_params(image_data->GetCanvasColorParams(), @@ -289,7 +298,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, WriteRawBytes(pixel_buffer->Data(), pixel_buffer_length); return true; } - if (wrapper_type_info == &V8DOMPoint::wrapper_type_info) { + if (wrapper_type_info == V8DOMPoint::GetWrapperTypeInfo()) { DOMPoint* point = wrappable->ToImpl<DOMPoint>(); WriteTag(kDOMPointTag); WriteDouble(point->x()); @@ -298,7 +307,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, WriteDouble(point->w()); return true; } - if (wrapper_type_info == &V8DOMPointReadOnly::wrapper_type_info) { + if (wrapper_type_info == V8DOMPointReadOnly::GetWrapperTypeInfo()) { DOMPointReadOnly* point = wrappable->ToImpl<DOMPointReadOnly>(); WriteTag(kDOMPointReadOnlyTag); WriteDouble(point->x()); @@ -307,7 +316,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, WriteDouble(point->w()); return true; } - if (wrapper_type_info == &V8DOMRect::wrapper_type_info) { + if (wrapper_type_info == V8DOMRect::GetWrapperTypeInfo()) { DOMRect* rect = wrappable->ToImpl<DOMRect>(); WriteTag(kDOMRectTag); WriteDouble(rect->x()); @@ -316,7 +325,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, WriteDouble(rect->height()); return true; } - if (wrapper_type_info == &V8DOMRectReadOnly::wrapper_type_info) { + if (wrapper_type_info == V8DOMRectReadOnly::GetWrapperTypeInfo()) { DOMRectReadOnly* rect = wrappable->ToImpl<DOMRectReadOnly>(); WriteTag(kDOMRectReadOnlyTag); WriteDouble(rect->x()); @@ -325,7 +334,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, WriteDouble(rect->height()); return true; } - if (wrapper_type_info == &V8DOMQuad::wrapper_type_info) { + if (wrapper_type_info == V8DOMQuad::GetWrapperTypeInfo()) { DOMQuad* quad = wrappable->ToImpl<DOMQuad>(); WriteTag(kDOMQuadTag); for (const DOMPoint* point : @@ -337,7 +346,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, } return true; } - if (wrapper_type_info == &V8DOMMatrix::wrapper_type_info) { + if (wrapper_type_info == V8DOMMatrix::GetWrapperTypeInfo()) { DOMMatrix* matrix = wrappable->ToImpl<DOMMatrix>(); if (matrix->is2D()) { WriteTag(kDOMMatrix2DTag); @@ -368,7 +377,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, } return true; } - if (wrapper_type_info == &V8DOMMatrixReadOnly::wrapper_type_info) { + if (wrapper_type_info == V8DOMMatrixReadOnly::GetWrapperTypeInfo()) { DOMMatrixReadOnly* matrix = wrappable->ToImpl<DOMMatrixReadOnly>(); if (matrix->is2D()) { WriteTag(kDOMMatrix2DReadOnlyTag); @@ -399,7 +408,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, } return true; } - if (wrapper_type_info == &V8MessagePort::wrapper_type_info) { + if (wrapper_type_info == V8MessagePort::GetWrapperTypeInfo()) { MessagePort* message_port = wrappable->ToImpl<MessagePort>(); size_t index = kNotFound; if (transferables_) @@ -415,7 +424,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, WriteUint32(static_cast<uint32_t>(index)); return true; } - if (wrapper_type_info == &V8MojoHandle::wrapper_type_info && + if (wrapper_type_info == V8MojoHandle::GetWrapperTypeInfo() && RuntimeEnabledFeatures::MojoJSEnabled()) { MojoHandle* mojo_handle = wrappable->ToImpl<MojoHandle>(); size_t index = kNotFound; @@ -435,7 +444,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, WriteUint32(static_cast<uint32_t>(index)); return true; } - if (wrapper_type_info == &V8OffscreenCanvas::wrapper_type_info) { + if (wrapper_type_info == V8OffscreenCanvas::GetWrapperTypeInfo()) { OffscreenCanvas* canvas = wrappable->ToImpl<OffscreenCanvas>(); size_t index = kNotFound; if (transferables_) @@ -468,7 +477,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, WriteUint32(canvas->SinkId()); return true; } - if (wrapper_type_info == &V8ReadableStream::wrapper_type_info && + if (wrapper_type_info == V8ReadableStream::GetWrapperTypeInfo() && RuntimeEnabledFeatures::TransferableStreamsEnabled()) { ReadableStream* stream = wrappable->ToImpl<ReadableStream>(); size_t index = kNotFound; @@ -492,7 +501,7 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, WriteUint32(static_cast<uint32_t>(index)); return true; } - if (wrapper_type_info == &V8WritableStream::wrapper_type_info && + if (wrapper_type_info == V8WritableStream::GetWrapperTypeInfo() && RuntimeEnabledFeatures::TransferableStreamsEnabled()) { WritableStream* stream = wrappable->ToImpl<WritableStream>(); size_t index = kNotFound; @@ -521,6 +530,41 @@ bool V8ScriptValueSerializer::WriteDOMObject(ScriptWrappable* wrappable, static_cast<uint32_t>(index + transferables_->readable_streams.size())); return true; } + if (wrapper_type_info == V8TransformStream::GetWrapperTypeInfo() && + RuntimeEnabledFeatures::TransferableStreamsEnabled()) { + TransformStream* stream = wrappable->ToImpl<TransformStream>(); + size_t index = kNotFound; + if (transferables_) + index = transferables_->transform_streams.Find(stream); + if (index == kNotFound) { + exception_state.ThrowDOMException(DOMExceptionCode::kDataCloneError, + "A TransformStream could not be cloned " + "because it was not transferred."); + return false; + } + if (stream->Readable() + ->IsLocked(script_state_, exception_state) + .value_or(true) || + stream->Writable() + ->IsLocked(script_state_, exception_state) + .value_or(true)) { + if (exception_state.HadException()) + return false; + exception_state.ThrowDOMException( + DOMExceptionCode::kDataCloneError, + "A TransformStream could not be cloned because it was locked"); + return false; + } + WriteTag(kTransformStreamTransferTag); + DCHECK(transferables_); + // TransformStreams use two ports each. The stored index is the index of the + // first one. The first TransformStream is stored in the array after all the + // ReadableStreams and WritableStreams. + WriteUint32(static_cast<uint32_t>(index * 2 + + transferables_->readable_streams.size() + + transferables_->writable_streams.size())); + return true; + } return false; } @@ -635,7 +679,7 @@ v8::Maybe<uint32_t> V8ScriptValueSerializer::GetSharedArrayBufferId( v8::Maybe<uint32_t> V8ScriptValueSerializer::GetWasmModuleTransferId( v8::Isolate* isolate, - v8::Local<v8::WasmCompiledModule> module) { + v8::Local<v8::WasmModuleObject> module) { if (for_storage_) { DCHECK(exception_state_); DCHECK_EQ(isolate, script_state_->GetIsolate()); diff --git a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer.h b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer.h index 7d8031fd428..e159a1e0115 100644 --- a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer.h +++ b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer.h @@ -92,7 +92,7 @@ class CORE_EXPORT V8ScriptValueSerializer v8::Maybe<uint32_t> GetWasmModuleTransferId( v8::Isolate*, - v8::Local<v8::WasmCompiledModule>) override; + v8::Local<v8::WasmModuleObject>) override; // Reallocates memory at |ptr| to the new size and returns the new pointer or // nullptr on failure. |actual_size| will hold the actual size of allocation // requested. diff --git a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer_test.cc b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer_test.cc index 861eb3a1dce..276b094b120 100644 --- a/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer_test.cc +++ b/chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer_test.cc @@ -1031,8 +1031,7 @@ TEST(V8ScriptValueSerializerTest, RoundTripImageBitmapWithColorSpaceInfo) { // Make a 10x7 red ImageBitmap in P3 color space. SkImageInfo info = SkImageInfo::Make( 10, 7, kRGBA_F16_SkColorType, kPremul_SkAlphaType, - SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, - SkColorSpace::kDCIP3_D65_Gamut)); + SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, SkNamedGamut::kDCIP3)); sk_sp<SkSurface> surface = SkSurface::MakeRaster(info); surface->getCanvas()->clear(SK_ColorRED); ImageBitmap* image_bitmap = ImageBitmap::Create( @@ -1138,8 +1137,7 @@ TEST(V8ScriptValueSerializerTest, DecodeImageBitmapV18) { uint8_t pixel[8] = {}; SkImageInfo info = SkImageInfo::Make( 1, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType, - SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, - SkColorSpace::kDCIP3_D65_Gamut)); + SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, SkNamedGamut::kDCIP3)); ASSERT_TRUE(new_image_bitmap->BitmapImage() ->PaintImageForCurrentFrame() .GetSkImage() @@ -1843,7 +1841,7 @@ TEST(V8ScriptValueSerializerTest, DecodeWithInefficientVersionEnvelope) { } // Sanity check for transferring ReadableStreams. This is mostly tested via -// layout tests. +// web tests. TEST(V8ScriptValueSerializerTest, RoundTripReadableStream) { ScopedTransferableStreamsForTest enable_transferable_streams(true); |