mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 13:11:46 +03:00
LibWeb: Add Transformer API
This adds the Transformer API which the TransformStream() constructor accepts as its first argument.
This commit is contained in:
parent
3ec9fd0aae
commit
12ff48047f
Notes:
sideshowbarker
2024-07-17 03:27:40 +09:00
Author: https://github.com/kennethmyhra Commit: https://github.com/SerenityOS/serenity/commit/12ff48047f Pull-request: https://github.com/SerenityOS/serenity/pull/19998 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/shannonbooth
@ -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
|
||||
|
@ -564,6 +564,7 @@ struct PullIntoDescriptor;
|
||||
struct QueuingStrategy;
|
||||
struct QueuingStrategyInit;
|
||||
struct ReadableStreamGetReaderOptions;
|
||||
struct Transformer;
|
||||
struct UnderlyingSink;
|
||||
struct UnderlyingSource;
|
||||
}
|
||||
|
38
Userland/Libraries/LibWeb/Streams/Transformer.cpp
Normal file
38
Userland/Libraries/LibWeb/Streams/Transformer.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/Streams/AbstractOperations.h>
|
||||
#include <LibWeb/Streams/Transformer.h>
|
||||
#include <LibWeb/WebIDL/CallbackType.h>
|
||||
|
||||
namespace Web::Streams {
|
||||
|
||||
JS::ThrowCompletionOr<Transformer> 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;
|
||||
}
|
||||
|
||||
}
|
32
Userland/Libraries/LibWeb/Streams/Transformer.h
Normal file
32
Userland/Libraries/LibWeb/Streams/Transformer.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::Streams {
|
||||
|
||||
// https://streams.spec.whatwg.org/#dictdef-transformer
|
||||
struct Transformer {
|
||||
// https://streams.spec.whatwg.org/#dom-transformer-start
|
||||
JS::Handle<WebIDL::CallbackType> start;
|
||||
// https://streams.spec.whatwg.org/#dom-transformer-transform
|
||||
JS::Handle<WebIDL::CallbackType> transform;
|
||||
// https://streams.spec.whatwg.org/#dom-transformer-flush
|
||||
JS::Handle<WebIDL::CallbackType> flush;
|
||||
|
||||
// https://streams.spec.whatwg.org/#dom-transformer-readabletype
|
||||
Optional<JS::Value> readable_type;
|
||||
// https://streams.spec.whatwg.org/#dom-transformer-writabletype
|
||||
Optional<JS::Value> writable_type;
|
||||
|
||||
static JS::ThrowCompletionOr<Transformer> from_value(JS::VM&, JS::Value);
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user