diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp index 525d1e21d8..e8f21782f6 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -3923,6 +3924,18 @@ bool can_transfer_array_buffer(JS::ArrayBuffer const& array_buffer) return true; } +// https://streams.spec.whatwg.org/#abstract-opdef-structuredclone +WebIDL::ExceptionOr structured_clone(JS::Realm& realm, JS::Value value) +{ + auto& vm = realm.vm(); + + // 1. Let serialized be ? StructuredSerialize(v). + auto serialized = TRY(HTML::structured_serialize(vm, value)); + + // 2. Return ? StructuredDeserialize(serialized, the current Realm). + return TRY(HTML::structured_deserialize(vm, serialized, realm, {})); +} + // https://streams.spec.whatwg.org/#close-sentinel // Non-standard function that implements the "close sentinel" value. JS::Value create_close_sentinel() diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h index c7d0d7d31d..2a93eaad28 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h @@ -175,6 +175,7 @@ WebIDL::ExceptionOr transform_stream_set_backpressure(TransformStream&, bo bool is_non_negative_number(JS::Value); bool can_transfer_array_buffer(JS::ArrayBuffer const& array_buffer); +WebIDL::ExceptionOr structured_clone(JS::Realm&, JS::Value value); JS::Value create_close_sentinel(); bool is_close_sentinel(JS::Value);