LibWeb: Specify the correct argument type in IDL for AbortSignal::any()

This allows some boilerplate code to be generated automatically.
This commit is contained in:
Tim Ledbetter 2024-05-13 18:52:46 +01:00 committed by Luke Wilde
parent ff2c6cab55
commit a8c60d65fc
Notes: sideshowbarker 2024-07-17 11:30:05 +09:00
3 changed files with 4 additions and 20 deletions

View file

@ -147,25 +147,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> AbortSignal::timeout(JS::VM&
}
// https://dom.spec.whatwg.org/#dom-abortsignal-any
WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> AbortSignal::any(JS::VM& vm, JS::Value signals)
WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> AbortSignal::any(JS::VM& vm, Vector<JS::Handle<AbortSignal>> const& signals)
{
Vector<JS::Handle<AbortSignal>> signals_list;
auto iterator_record = TRY(get_iterator(vm, signals, JS::IteratorHint::Sync));
while (true) {
auto next = TRY(iterator_step_value(vm, iterator_record));
if (!next.has_value())
break;
auto value = next.release_value();
if (!value.is_object() || !is<AbortSignal>(value.as_object()))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "AbortSignal");
auto& signal = static_cast<AbortSignal&>(value.as_object());
signals_list.append(JS::make_handle(signal));
}
// The static any(signals) method steps are to return the result of creating a dependent abort signal from signals using AbortSignal and the current realm.
return create_dependent_abort_signal(*vm.current_realm(), signals_list);
return create_dependent_abort_signal(*vm.current_realm(), signals);
}
// https://dom.spec.whatwg.org/#create-a-dependent-abort-signal

View file

@ -45,7 +45,7 @@ public:
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> abort(JS::VM&, JS::Value reason);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> timeout(JS::VM&, Web::WebIDL::UnsignedLongLong milliseconds);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> any(JS::VM&, JS::Value signals);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> any(JS::VM&, Vector<JS::Handle<AbortSignal>> const&);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> create_dependent_abort_signal(JS::Realm&, Vector<JS::Handle<AbortSignal>> const&);

View file

@ -6,8 +6,7 @@
interface AbortSignal : EventTarget {
[NewObject] static AbortSignal abort(optional any reason);
[Exposed=(Window,Worker), NewObject] static AbortSignal timeout([EnforceRange] unsigned long long milliseconds);
// FIXME: Argument should be of type: sequence<AbortSignal>.
[NewObject] static AbortSignal _any(any signals);
[NewObject] static AbortSignal _any(sequence<AbortSignal> signals);
readonly attribute boolean aborted;
readonly attribute any reason;