LibWeb/Streams: Convert UnderlyingSink to IDL bindings conversion
This commit is contained in:
parent
08b77d0465
commit
23a910fcf2
9 changed files with 19 additions and 68 deletions
|
|
@ -965,7 +965,6 @@ set(SOURCES
|
|||
Streams/TransformStream.cpp
|
||||
Streams/TransformStreamDefaultController.cpp
|
||||
Streams/TransformStreamOperations.cpp
|
||||
Streams/UnderlyingSink.cpp
|
||||
Streams/UnderlyingSource.cpp
|
||||
Streams/WritableStream.cpp
|
||||
Streams/WritableStreamDefaultController.cpp
|
||||
|
|
|
|||
|
|
@ -1142,7 +1142,6 @@ class WritableStreamDefaultWriter;
|
|||
struct PullIntoDescriptor;
|
||||
|
||||
struct Transformer;
|
||||
struct UnderlyingSink;
|
||||
struct UnderlyingSource;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/Streams/UnderlyingSink.h>
|
||||
#include <LibWeb/WebIDL/CallbackType.h>
|
||||
|
||||
namespace Web::Streams {
|
||||
|
||||
JS::ThrowCompletionOr<UnderlyingSink> UnderlyingSink::from_value(JS::VM& vm, JS::Value value)
|
||||
{
|
||||
if (!value.is_object())
|
||||
return UnderlyingSink {};
|
||||
|
||||
auto& object = value.as_object();
|
||||
|
||||
UnderlyingSink underlying_sink {
|
||||
.start = TRY(WebIDL::property_to_callback(vm, value, "start"_utf16_fly_string, WebIDL::OperationReturnsPromise::No)),
|
||||
.write = TRY(WebIDL::property_to_callback(vm, value, "write"_utf16_fly_string, WebIDL::OperationReturnsPromise::Yes)),
|
||||
.close = TRY(WebIDL::property_to_callback(vm, value, "close"_utf16_fly_string, WebIDL::OperationReturnsPromise::Yes)),
|
||||
.abort = TRY(WebIDL::property_to_callback(vm, value, "abort"_utf16_fly_string, WebIDL::OperationReturnsPromise::Yes)),
|
||||
.type = {},
|
||||
};
|
||||
|
||||
if (TRY(object.has_property("type"_utf16_fly_string)))
|
||||
underlying_sink.type = TRY(object.get("type"_utf16_fly_string));
|
||||
|
||||
return underlying_sink;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Forward.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibWeb/Export.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::Streams {
|
||||
|
||||
// https://streams.spec.whatwg.org/#dictdef-underlyingsink
|
||||
struct WEB_API UnderlyingSink {
|
||||
GC::Ptr<WebIDL::CallbackType> start;
|
||||
GC::Ptr<WebIDL::CallbackType> write;
|
||||
GC::Ptr<WebIDL::CallbackType> close;
|
||||
GC::Ptr<WebIDL::CallbackType> abort;
|
||||
Optional<JS::Value> type;
|
||||
|
||||
static JS::ThrowCompletionOr<UnderlyingSink> from_value(JS::VM&, JS::Value);
|
||||
};
|
||||
|
||||
}
|
||||
13
Libraries/LibWeb/Streams/UnderlyingSink.idl
Normal file
13
Libraries/LibWeb/Streams/UnderlyingSink.idl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// https://streams.spec.whatwg.org/#dictdef-underlyingsink
|
||||
dictionary UnderlyingSink {
|
||||
UnderlyingSinkStartCallback start;
|
||||
UnderlyingSinkWriteCallback write;
|
||||
UnderlyingSinkCloseCallback close;
|
||||
UnderlyingSinkAbortCallback abort;
|
||||
any type;
|
||||
};
|
||||
|
||||
callback UnderlyingSinkStartCallback = any (WritableStreamDefaultController controller);
|
||||
callback UnderlyingSinkWriteCallback = Promise<undefined> (any chunk, WritableStreamDefaultController controller);
|
||||
callback UnderlyingSinkCloseCallback = Promise<undefined> ();
|
||||
callback UnderlyingSinkAbortCallback = Promise<undefined> (optional any reason);
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <LibJS/Runtime/PromiseCapability.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/UnderlyingSink.h>
|
||||
#include <LibWeb/Bindings/WritableStream.h>
|
||||
#include <LibWeb/HTML/MessagePort.h>
|
||||
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
|
||||
|
|
@ -13,7 +14,6 @@
|
|||
#include <LibWeb/Streams/AbstractOperations.h>
|
||||
#include <LibWeb/Streams/ReadableStream.h>
|
||||
#include <LibWeb/Streams/ReadableStreamOperations.h>
|
||||
#include <LibWeb/Streams/UnderlyingSink.h>
|
||||
#include <LibWeb/Streams/WritableStream.h>
|
||||
#include <LibWeb/Streams/WritableStreamDefaultController.h>
|
||||
#include <LibWeb/Streams/WritableStreamDefaultWriter.h>
|
||||
|
|
@ -35,7 +35,7 @@ WebIDL::ExceptionOr<GC::Ref<WritableStream>> WritableStream::construct_impl(JS::
|
|||
auto underlying_sink = underlying_sink_object.has_value() ? JS::Value(underlying_sink_object.value()) : JS::js_null();
|
||||
|
||||
// 2. Let underlyingSinkDict be underlyingSink, converted to an IDL value of type UnderlyingSink.
|
||||
auto underlying_sink_dict = TRY(UnderlyingSink::from_value(vm, underlying_sink));
|
||||
auto underlying_sink_dict = TRY(Bindings::convert_to_idl_value_for_underlying_sink(vm, underlying_sink));
|
||||
|
||||
// 3. If underlyingSinkDict["type"] exists, throw a RangeError exception.
|
||||
if (underlying_sink_dict.type.has_value())
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
|
||||
#include <AK/GenericShorthands.h>
|
||||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||
#include <LibWeb/Bindings/UnderlyingSink.h>
|
||||
#include <LibWeb/DOM/AbortSignal.h>
|
||||
#include <LibWeb/Streams/AbstractOperations.h>
|
||||
#include <LibWeb/Streams/UnderlyingSink.h>
|
||||
#include <LibWeb/Streams/WritableStream.h>
|
||||
#include <LibWeb/Streams/WritableStreamDefaultController.h>
|
||||
#include <LibWeb/Streams/WritableStreamDefaultWriter.h>
|
||||
|
|
@ -954,7 +954,7 @@ WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller(WritableStre
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#set-up-writable-stream-default-controller-from-underlying-sink
|
||||
WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller_from_underlying_sink(WritableStream& stream, JS::Value underlying_sink_value, UnderlyingSink& underlying_sink, double high_water_mark, GC::Ref<SizeAlgorithm> size_algorithm)
|
||||
WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller_from_underlying_sink(WritableStream& stream, JS::Value underlying_sink_value, Bindings::UnderlyingSink& underlying_sink, double high_water_mark, GC::Ref<SizeAlgorithm> size_algorithm)
|
||||
{
|
||||
auto& realm = stream.realm();
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ GC::Ref<WebIDL::Promise> writable_stream_default_writer_write(WritableStreamDefa
|
|||
|
||||
// 5.5.4. Default controllers, https://streams.spec.whatwg.org/#ws-default-controller-abstract-ops
|
||||
WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller(WritableStream&, WritableStreamDefaultController&, GC::Ref<StartAlgorithm>, GC::Ref<WriteAlgorithm>, GC::Ref<CloseAlgorithm>, GC::Ref<AbortAlgorithm>, double high_water_mark, GC::Ref<SizeAlgorithm>);
|
||||
WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller_from_underlying_sink(WritableStream&, JS::Value underlying_sink_value, UnderlyingSink&, double high_water_mark, GC::Ref<SizeAlgorithm> size_algorithm);
|
||||
WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller_from_underlying_sink(WritableStream&, JS::Value underlying_sink_value, Bindings::UnderlyingSink&, double high_water_mark, GC::Ref<SizeAlgorithm> size_algorithm);
|
||||
void writable_stream_default_controller_advance_queue_if_needed(WritableStreamDefaultController&);
|
||||
void writable_stream_default_controller_clear_algorithms(WritableStreamDefaultController&);
|
||||
void writable_stream_default_controller_close(WritableStreamDefaultController&);
|
||||
|
|
|
|||
|
|
@ -636,6 +636,7 @@ libweb_support_idl(Streams/GenericTransformStream)
|
|||
libweb_support_idl(Streams/QueuingStrategy)
|
||||
libweb_support_idl(Streams/QueuingStrategyInit)
|
||||
libweb_support_idl(Streams/ReadableStreamGenericReader)
|
||||
libweb_support_idl(Streams/UnderlyingSink)
|
||||
libweb_support_idl(UIEvents/EventModifier)
|
||||
libweb_support_idl(UIEvents/PointerEventHandlers)
|
||||
libweb_support_idl(WebGL/Types)
|
||||
|
|
|
|||
Loading…
Reference in a new issue