diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index bdc6d149bdd..daaf7afd578 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -513,6 +513,7 @@ set(SOURCES Streams/ReadableStreamDefaultController.cpp Streams/ReadableStreamDefaultReader.cpp Streams/ReadableStreamGenericReader.cpp + Streams/Transformer.cpp Streams/UnderlyingSink.cpp Streams/UnderlyingSource.cpp Streams/WritableStream.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index ab6d0dde553..30c11411400 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -564,6 +564,7 @@ struct PullIntoDescriptor; struct QueuingStrategy; struct QueuingStrategyInit; struct ReadableStreamGetReaderOptions; +struct Transformer; struct UnderlyingSink; struct UnderlyingSource; } diff --git a/Userland/Libraries/LibWeb/Streams/Transformer.cpp b/Userland/Libraries/LibWeb/Streams/Transformer.cpp new file mode 100644 index 00000000000..b3e2a483b0e --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/Transformer.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023, Kenneth Myhra + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::Streams { + +JS::ThrowCompletionOr Transformer::from_value(JS::VM& vm, JS::Value value) +{ + if (!value.is_object()) + return Transformer {}; + + auto& object = value.as_object(); + + Transformer transformer { + .start = TRY(property_to_callback(vm, value, "start", WebIDL::OperationReturnsPromise::No)), + .transform = TRY(property_to_callback(vm, value, "transform", WebIDL::OperationReturnsPromise::Yes)), + .flush = TRY(property_to_callback(vm, value, "flush", WebIDL::OperationReturnsPromise::Yes)), + .readable_type = {}, + .writable_type = {}, + }; + + if (TRY(object.has_property("readableType"))) + transformer.readable_type = TRY(object.get("readableType")); + + if (TRY(object.has_property("writableType"))) + transformer.writable_type = TRY(object.get("writableType")); + + return transformer; +} + +} diff --git a/Userland/Libraries/LibWeb/Streams/Transformer.h b/Userland/Libraries/LibWeb/Streams/Transformer.h new file mode 100644 index 00000000000..940a11a60c2 --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/Transformer.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023, Kenneth Myhra + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Web::Streams { + +// https://streams.spec.whatwg.org/#dictdef-transformer +struct Transformer { + // https://streams.spec.whatwg.org/#dom-transformer-start + JS::Handle start; + // https://streams.spec.whatwg.org/#dom-transformer-transform + JS::Handle transform; + // https://streams.spec.whatwg.org/#dom-transformer-flush + JS::Handle flush; + + // https://streams.spec.whatwg.org/#dom-transformer-readabletype + Optional readable_type; + // https://streams.spec.whatwg.org/#dom-transformer-writabletype + Optional writable_type; + + static JS::ThrowCompletionOr from_value(JS::VM&, JS::Value); +}; + +}