LibWeb: Generate Optional<NonnullGCPtr<T>> as GCPtr<T>

This is the general pattern which has been adopted in LibWeb, so let's
generate our IDL like this too.
This commit is contained in:
Shannon Booth 2024-04-07 15:10:36 +02:00 committed by Andreas Kling
parent 3a0e69d86f
commit 80658743d3
Notes: sideshowbarker 2024-07-17 10:54:57 +09:00
7 changed files with 11 additions and 11 deletions

View file

@ -513,7 +513,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
)~~~");
} else {
scoped_generator.append(R"~~~(
Optional<JS::NonnullGCPtr<@parameter.type.name@>> @cpp_name@;
JS::GCPtr<@parameter.type.name@> @cpp_name@;
if (!@js_name@@js_suffix@.is_undefined()) {
if (!@js_name@@js_suffix@.is_object() || !is<@parameter.type.name@>(@js_name@@js_suffix@.as_object()))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");

View file

@ -135,8 +135,8 @@ static FlattenedAddEventListenerOptions flatten_add_event_listener_options(Varia
once = add_event_listener_options.once;
// 2. If options["signal"] exists, then set signal to options["signal"].
if (add_event_listener_options.signal.has_value())
signal = add_event_listener_options.signal.value().ptr();
if (add_event_listener_options.signal)
signal = add_event_listener_options.signal;
}
// 5. Return capture, passive, once, and signal.

View file

@ -21,7 +21,7 @@ struct EventListenerOptions {
struct AddEventListenerOptions : public EventListenerOptions {
bool passive { false };
bool once { false };
Optional<JS::NonnullGCPtr<AbortSignal>> signal;
JS::GCPtr<AbortSignal> signal;
};
class IDLEventListener final : public JS::Object {

View file

@ -121,7 +121,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> ReadableStream::pipe_throu
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Failed to execute 'pipeThrough' on 'ReadableStream': parameter 1's 'writable' is locked"sv };
// 3. Let signal be options["signal"] if it exists, or undefined otherwise.
auto signal = options.signal.has_value() ? JS::Value(options.signal.value().ptr()) : JS::js_undefined();
auto signal = options.signal ? JS::Value(options.signal) : JS::js_undefined();
// 4. Let promise be ! ReadableStreamPipeTo(this, transform["writable"], options["preventClose"], options["preventAbort"], options["preventCancel"], signal).
auto promise = MUST(readable_stream_pipe_to(*this, *transform.writable, options.prevent_close, options.prevent_abort, options.prevent_cancel, signal));
@ -152,7 +152,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Object>> ReadableStream::pipe_to(Writab
}
// 3. Let signal be options["signal"] if it exists, or undefined otherwise.
auto signal = options.signal.has_value() ? JS::Value(options.signal.value().ptr()) : JS::js_undefined();
auto signal = options.signal ? JS::Value(options.signal) : JS::js_undefined();
// 4. Return ! ReadableStreamPipeTo(this, destination, options["preventClose"], options["preventAbort"], options["preventCancel"], signal).
return MUST(readable_stream_pipe_to(*this, destination, options.prevent_close, options.prevent_abort, options.prevent_cancel, signal))->promise();

View file

@ -36,7 +36,7 @@ struct StreamPipeOptions {
bool prevent_close { false };
bool prevent_abort { false };
bool prevent_cancel { false };
Optional<JS::NonnullGCPtr<DOM::AbortSignal>> signal;
JS::GCPtr<DOM::AbortSignal> signal;
};
struct ReadableStreamPair {

View file

@ -18,13 +18,13 @@ namespace Web::XHR {
JS_DEFINE_ALLOCATOR(FormData);
// https://xhr.spec.whatwg.org/#dom-formdata
WebIDL::ExceptionOr<JS::NonnullGCPtr<FormData>> FormData::construct_impl(JS::Realm& realm, Optional<JS::NonnullGCPtr<HTML::HTMLFormElement>> form)
WebIDL::ExceptionOr<JS::NonnullGCPtr<FormData>> FormData::construct_impl(JS::Realm& realm, JS::GCPtr<HTML::HTMLFormElement> form)
{
Vector<FormDataEntry> list;
// 1. If form is given, then:
if (form.has_value()) {
if (form) {
// 1. Let list be the result of constructing the entry list for form.
auto entry_list = TRY(construct_entry_list(realm, form.value()));
auto entry_list = TRY(construct_entry_list(realm, *form));
// 2. If list is null, then throw an "InvalidStateError" DOMException.
if (!entry_list.has_value())
return WebIDL::InvalidStateError::create(realm, "Form element does not contain any entries."_fly_string);

View file

@ -23,7 +23,7 @@ class FormData : public Bindings::PlatformObject {
public:
virtual ~FormData() override;
static WebIDL::ExceptionOr<JS::NonnullGCPtr<FormData>> construct_impl(JS::Realm&, Optional<JS::NonnullGCPtr<HTML::HTMLFormElement>> form = {});
static WebIDL::ExceptionOr<JS::NonnullGCPtr<FormData>> construct_impl(JS::Realm&, JS::GCPtr<HTML::HTMLFormElement> form = {});
static WebIDL::ExceptionOr<JS::NonnullGCPtr<FormData>> construct_impl(JS::Realm&, Vector<FormDataEntry> entry_list);
WebIDL::ExceptionOr<void> append(String const& name, String const& value);