LibWeb: Use (de)serialization with transfer AOs for structured cloning

This is important, for example, to detach transferred array buffers.
This commit is contained in:
Timothy Flynn 2025-04-17 09:00:36 -04:00
commit e2881ec817
2 changed files with 6 additions and 9 deletions

View file

@ -93,19 +93,16 @@ void UniversalGlobalScopeMixin::queue_microtask(WebIDL::CallbackType& callback)
// https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone // https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone
WebIDL::ExceptionOr<JS::Value> UniversalGlobalScopeMixin::structured_clone(JS::Value value, StructuredSerializeOptions const& options) const WebIDL::ExceptionOr<JS::Value> UniversalGlobalScopeMixin::structured_clone(JS::Value value, StructuredSerializeOptions const& options) const
{ {
auto& vm = this_impl().vm(); auto& realm = HTML::relevant_realm(this_impl());
(void)options;
// 1. Let serialized be ? StructuredSerializeWithTransfer(value, options["transfer"]). // 1. Let serialized be ? StructuredSerializeWithTransfer(value, options["transfer"]).
// FIXME: Use WithTransfer variant of the AO auto serialized = TRY(structured_serialize_with_transfer(realm.vm(), value, options.transfer));
auto serialized = TRY(structured_serialize(vm, value));
// 2. Let deserializeRecord be ? StructuredDeserializeWithTransfer(serialized, this's relevant realm). // 2. Let deserializeRecord be ? StructuredDeserializeWithTransfer(serialized, this's relevant realm).
// FIXME: Use WithTransfer variant of the AO auto deserialized = TRY(structured_deserialize_with_transfer(serialized, realm));
auto deserialized = TRY(structured_deserialize(vm, serialized, relevant_realm(this_impl())));
// 3. Return deserializeRecord.[[Deserialized]]. // 3. Return deserializeRecord.[[Deserialized]].
return deserialized; return deserialized.deserialized;
} }
// https://streams.spec.whatwg.org/#count-queuing-strategy-size-function // https://streams.spec.whatwg.org/#count-queuing-strategy-size-function

View file

@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests Found 1 tests
1 Fail 1 Pass
Fail enqueue after detaching byobRequest.view.buffer should throw Pass enqueue after detaching byobRequest.view.buffer should throw