LibWeb: Move ad hoc CallbackType helper method to CallbackType header

Abstract operations of a stream does not seem like the correct home for
this function.
This commit is contained in:
Shannon Booth 2024-12-08 17:43:24 +13:00 committed by Jelle Raaijmakers
commit 99073c0561
Notes: github-actions[bot] 2024-12-11 14:12:23 +00:00
7 changed files with 29 additions and 28 deletions

View file

@ -5302,21 +5302,6 @@ WebIDL::ExceptionOr<JS::Value> structured_clone(JS::Realm& realm, JS::Value valu
return TRY(HTML::structured_deserialize(vm, serialized, realm));
}
// Non-standard function to aid in converting a user-provided function into a WebIDL::Callback. This is essentially
// what the Bindings generator would do at compile time, but at runtime instead.
JS::ThrowCompletionOr<GC::Root<WebIDL::CallbackType>> property_to_callback(JS::VM& vm, JS::Value value, JS::PropertyKey const& property_key, WebIDL::OperationReturnsPromise operation_returns_promise)
{
auto property = TRY(value.get(vm, property_key));
if (property.is_undefined())
return GC::Root<WebIDL::CallbackType> {};
if (!property.is_function())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, property.to_string_without_side_effects());
return vm.heap().allocate<WebIDL::CallbackType>(property.as_object(), HTML::incumbent_realm(), operation_returns_promise);
}
// https://streams.spec.whatwg.org/#set-up-readable-byte-stream-controller-from-underlying-source
WebIDL::ExceptionOr<void> set_up_readable_byte_stream_controller_from_underlying_source(ReadableStream& stream, JS::Value underlying_source, UnderlyingSource const& underlying_source_dict, double high_water_mark)
{