LibWeb: Move CallbackType from Bindings/ to WebIDL/

Let's stop putting generic types and AOs from the Web IDL spec into
the Bindings namespace and directory in LibWeb, and instead follow our
usual naming rules of 'directory = namespace = spec name'. The IDL
namespace is already used by LibIDL, so Web::WebIDL seems like a good
choice.
This commit is contained in:
Linus Groh 2022-09-24 16:02:41 +01:00
parent dc44effd44
commit 4f73851afc
Notes: sideshowbarker 2024-07-17 18:06:52 +09:00
43 changed files with 168 additions and 165 deletions

View file

@ -317,7 +317,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (!@js_name@@js_suffix@.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects());
auto* callback_type = vm.heap().allocate_without_realm<CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
auto* callback_type = vm.heap().allocate_without_realm<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
@cpp_name@ = @cpp_type@::create(realm, *callback_type).ptr();
}
)~~~");
@ -326,7 +326,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (!@js_name@@js_suffix@.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects());
auto* callback_type = vm.heap().allocate_without_realm<CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
auto* callback_type = vm.heap().allocate_without_realm<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
auto @cpp_name@ = adopt_ref(*new @cpp_type@(move(callback_type)));
)~~~");
}
@ -675,13 +675,13 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
// 2. Return the IDL callback function type value that represents a reference to the same object that V represents, with the incumbent settings object as the callback context.
if (callback_function.is_legacy_treat_non_object_as_null) {
callback_function_generator.append(R"~~~(
Bindings::CallbackType* @cpp_name@ = nullptr;
WebIDL::CallbackType* @cpp_name@ = nullptr;
if (@js_name@@js_suffix@.is_object())
@cpp_name@ = vm.heap().allocate_without_realm<CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
@cpp_name@ = vm.heap().allocate_without_realm<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
)~~~");
} else {
callback_function_generator.append(R"~~~(
auto @cpp_name@ = vm.heap().allocate_without_realm<CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
auto @cpp_name@ = vm.heap().allocate_without_realm<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
)~~~");
}
} else if (parameter.type->name() == "sequence") {

View file

@ -82,7 +82,7 @@ ErrorOr<ByteBuffer> get_buffer_source_copy(JS::Object const& buffer_source)
}
// https://webidl.spec.whatwg.org/#invoke-a-callback-function
JS::Completion invoke_callback(Bindings::CallbackType& callback, Optional<JS::Value> this_argument, JS::MarkedVector<JS::Value> args)
JS::Completion invoke_callback(WebIDL::CallbackType& callback, Optional<JS::Value> this_argument, JS::MarkedVector<JS::Value> args)
{
// 1. Let completion be an uninitialized variable.
JS::Completion completion;

View file

@ -11,8 +11,8 @@
#include <LibJS/Forward.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibWeb/Bindings/CallbackType.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/WebIDL/CallbackType.h>
namespace Web::Bindings::IDL {
@ -44,7 +44,7 @@ inline JS::Completion clean_up_on_return(HTML::EnvironmentSettingsObject& stored
// https://webidl.spec.whatwg.org/#call-a-user-objects-operation
template<typename... Args>
JS::Completion call_user_object_operation(Bindings::CallbackType& callback, String const& operation_name, Optional<JS::Value> this_argument, Args&&... args)
JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, String const& operation_name, Optional<JS::Value> this_argument, Args&&... args)
{
// 1. Let completion be an uninitialized variable.
JS::Completion completion;
@ -120,11 +120,11 @@ JS::Completion call_user_object_operation(Bindings::CallbackType& callback, Stri
return clean_up_on_return(stored_settings, relevant_settings, completion);
}
JS::Completion invoke_callback(Bindings::CallbackType& callback, Optional<JS::Value> this_argument, JS::MarkedVector<JS::Value> args);
JS::Completion invoke_callback(WebIDL::CallbackType& callback, Optional<JS::Value> this_argument, JS::MarkedVector<JS::Value> args);
// https://webidl.spec.whatwg.org/#invoke-a-callback-function
template<typename... Args>
JS::Completion invoke_callback(Bindings::CallbackType& callback, Optional<JS::Value> this_argument, Args&&... args)
JS::Completion invoke_callback(WebIDL::CallbackType& callback, Optional<JS::Value> this_argument, Args&&... args)
{
auto& function_object = callback.callback;

View file

@ -3,7 +3,6 @@ include(libweb_generators)
set(SOURCES
Bindings/AudioConstructor.cpp
Bindings/CSSNamespace.cpp
Bindings/CallbackType.cpp
Bindings/IDLAbstractOperations.cpp
Bindings/IDLOverloadResolution.cpp
Bindings/ImageConstructor.cpp
@ -413,6 +412,7 @@ set(SOURCES
WebGL/WebGLContextEvent.cpp
WebGL/WebGLRenderingContext.cpp
WebGL/WebGLRenderingContextBase.cpp
WebIDL/CallbackType.cpp
WebSockets/WebSocket.cpp
XHR/EventNames.cpp
XHR/ProgressEvent.cpp

View file

@ -82,12 +82,12 @@ void MediaQueryList::remove_listener(DOM::IDLEventListener* listener)
remove_event_listener_without_options(HTML::EventNames::change, *listener);
}
void MediaQueryList::set_onchange(Bindings::CallbackType* event_handler)
void MediaQueryList::set_onchange(WebIDL::CallbackType* event_handler)
{
set_event_handler_attribute(HTML::EventNames::change, event_handler);
}
Bindings::CallbackType* MediaQueryList::onchange()
WebIDL::CallbackType* MediaQueryList::onchange()
{
return event_handler_attribute(HTML::EventNames::change);
}

View file

@ -28,8 +28,8 @@ public:
void add_listener(DOM::IDLEventListener*);
void remove_listener(DOM::IDLEventListener*);
void set_onchange(Bindings::CallbackType*);
Bindings::CallbackType* onchange();
void set_onchange(WebIDL::CallbackType*);
WebIDL::CallbackType* onchange();
private:
MediaQueryList(DOM::Document&, NonnullRefPtrVector<MediaQuery>&&);

View file

@ -57,12 +57,12 @@ void AbortSignal::signal_abort(JS::Value reason)
dispatch_event(*Event::create(global_object(), HTML::EventNames::abort));
}
void AbortSignal::set_onabort(Bindings::CallbackType* event_handler)
void AbortSignal::set_onabort(WebIDL::CallbackType* event_handler)
{
set_event_handler_attribute(HTML::EventNames::abort, event_handler);
}
Bindings::CallbackType* AbortSignal::onabort()
WebIDL::CallbackType* AbortSignal::onabort()
{
return event_handler_attribute(HTML::EventNames::abort);
}

View file

@ -31,8 +31,8 @@ public:
void signal_abort(JS::Value reason);
void set_onabort(Bindings::CallbackType*);
Bindings::CallbackType* onabort();
void set_onabort(WebIDL::CallbackType*);
WebIDL::CallbackType* onabort();
// https://dom.spec.whatwg.org/#dom-abortsignal-reason
JS::Value reason() const { return m_abort_reason; }

View file

@ -299,7 +299,7 @@ static EventTarget* determine_target_of_event_handler(EventTarget& event_target,
}
// https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-attributes:event-handler-idl-attributes-2
Bindings::CallbackType* EventTarget::event_handler_attribute(FlyString const& name)
WebIDL::CallbackType* EventTarget::event_handler_attribute(FlyString const& name)
{
// 1. Let eventTarget be the result of determining the target of an event handler given this object and name.
auto target = determine_target_of_event_handler(*this, name);
@ -313,7 +313,7 @@ Bindings::CallbackType* EventTarget::event_handler_attribute(FlyString const& na
}
// https://html.spec.whatwg.org/multipage/webappapis.html#getting-the-current-value-of-the-event-handler
Bindings::CallbackType* EventTarget::get_current_value_of_event_handler(FlyString const& name)
WebIDL::CallbackType* EventTarget::get_current_value_of_event_handler(FlyString const& name)
{
// 1. Let handlerMap be eventTarget's event handler map. (NOTE: Not necessary)
@ -464,16 +464,16 @@ Bindings::CallbackType* EventTarget::get_current_value_of_event_handler(FlyStrin
function->set_script_or_module({});
// 12. Set eventHandler's value to the result of creating a Web IDL EventHandler callback function object whose object reference is function and whose callback context is settings object.
event_handler->value = realm.heap().allocate_without_realm<Bindings::CallbackType>(*function, settings_object);
event_handler->value = realm.heap().allocate_without_realm<WebIDL::CallbackType>(*function, settings_object);
}
// 4. Return eventHandler's value.
VERIFY(event_handler->value.has<Bindings::CallbackType*>());
return *event_handler->value.get_pointer<Bindings::CallbackType*>();
VERIFY(event_handler->value.has<WebIDL::CallbackType*>());
return *event_handler->value.get_pointer<WebIDL::CallbackType*>();
}
// https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-attributes:event-handler-idl-attributes-3
void EventTarget::set_event_handler_attribute(FlyString const& name, Bindings::CallbackType* value)
void EventTarget::set_event_handler_attribute(FlyString const& name, WebIDL::CallbackType* value)
{
// 1. Let eventTarget be the result of determining the target of an event handler given this object and name.
auto event_target = determine_target_of_event_handler(*this, name);
@ -556,7 +556,7 @@ void EventTarget::activate_event_handler(FlyString const& name, HTML::EventHandl
0, "", &realm);
// NOTE: As per the spec, the callback context is arbitrary.
auto* callback = realm.heap().allocate_without_realm<Bindings::CallbackType>(*callback_function, verify_cast<HTML::EnvironmentSettingsObject>(*realm.host_defined()));
auto* callback = realm.heap().allocate_without_realm<WebIDL::CallbackType>(*callback_function, verify_cast<HTML::EnvironmentSettingsObject>(*realm.host_defined()));
// 5. Let listener be a new event listener whose type is the event handler event type corresponding to eventHandler and callback is callback.
auto* listener = realm.heap().allocate_without_realm<DOMEventListener>();

View file

@ -51,8 +51,8 @@ public:
virtual void legacy_cancelled_activation_behavior() { }
virtual void legacy_cancelled_activation_behavior_was_not_called() { }
Bindings::CallbackType* event_handler_attribute(FlyString const& name);
void set_event_handler_attribute(FlyString const& name, Bindings::CallbackType*);
WebIDL::CallbackType* event_handler_attribute(FlyString const& name);
void set_event_handler_attribute(FlyString const& name, WebIDL::CallbackType*);
protected:
explicit EventTarget(JS::Realm&);
@ -68,7 +68,7 @@ private:
// Spec Note: The order of the entries of event handler map could be arbitrary. It is not observable through any algorithms that operate on the map.
HashMap<FlyString, JS::GCPtr<HTML::EventHandler>> m_event_handler_map;
Bindings::CallbackType* get_current_value_of_event_handler(FlyString const& name);
WebIDL::CallbackType* get_current_value_of_event_handler(FlyString const& name);
void activate_event_handler(FlyString const& name, HTML::EventHandler& event_handler);
void deactivate_event_handler(FlyString const& name);
JS::ThrowCompletionOr<void> process_event_handler_for_event(FlyString const& name, Event& event);

View file

@ -9,12 +9,12 @@
namespace Web::DOM {
JS::NonnullGCPtr<IDLEventListener> IDLEventListener::create(JS::Realm& realm, JS::NonnullGCPtr<Bindings::CallbackType> callback)
JS::NonnullGCPtr<IDLEventListener> IDLEventListener::create(JS::Realm& realm, JS::NonnullGCPtr<WebIDL::CallbackType> callback)
{
return *realm.heap().allocate<IDLEventListener>(realm, realm, move(callback));
}
IDLEventListener::IDLEventListener(JS::Realm& realm, JS::NonnullGCPtr<Bindings::CallbackType> callback)
IDLEventListener::IDLEventListener(JS::Realm& realm, JS::NonnullGCPtr<WebIDL::CallbackType> callback)
: JS::Object(*realm.intrinsics().object_prototype())
, m_callback(move(callback))
{

View file

@ -8,8 +8,8 @@
#include <AK/RefCounted.h>
#include <LibJS/Heap/Handle.h>
#include <LibWeb/Bindings/CallbackType.h>
#include <LibWeb/DOM/AbortSignal.h>
#include <LibWeb/WebIDL/CallbackType.h>
namespace Web::DOM {
@ -28,17 +28,17 @@ class IDLEventListener final : public JS::Object {
JS_OBJECT(IDLEventListener, JS::Object);
public:
static JS::NonnullGCPtr<IDLEventListener> create(JS::Realm&, JS::NonnullGCPtr<Bindings::CallbackType>);
IDLEventListener(JS::Realm&, JS::NonnullGCPtr<Bindings::CallbackType>);
static JS::NonnullGCPtr<IDLEventListener> create(JS::Realm&, JS::NonnullGCPtr<WebIDL::CallbackType>);
IDLEventListener(JS::Realm&, JS::NonnullGCPtr<WebIDL::CallbackType>);
virtual ~IDLEventListener() = default;
Bindings::CallbackType& callback() { return *m_callback; }
WebIDL::CallbackType& callback() { return *m_callback; }
private:
virtual void visit_edges(Cell::Visitor&) override;
JS::NonnullGCPtr<Bindings::CallbackType> m_callback;
JS::NonnullGCPtr<WebIDL::CallbackType> m_callback;
};
}

View file

@ -11,13 +11,13 @@
namespace Web::DOM {
JS::NonnullGCPtr<MutationObserver> MutationObserver::create_with_global_object(HTML::Window& window, JS::GCPtr<Bindings::CallbackType> callback)
JS::NonnullGCPtr<MutationObserver> MutationObserver::create_with_global_object(HTML::Window& window, JS::GCPtr<WebIDL::CallbackType> callback)
{
return *window.heap().allocate<MutationObserver>(window.realm(), window, callback);
}
// https://dom.spec.whatwg.org/#dom-mutationobserver-mutationobserver
MutationObserver::MutationObserver(HTML::Window& window, JS::GCPtr<Bindings::CallbackType> callback)
MutationObserver::MutationObserver(HTML::Window& window, JS::GCPtr<WebIDL::CallbackType> callback)
: PlatformObject(window.realm())
, m_callback(move(callback))
{

View file

@ -10,9 +10,9 @@
#include <AK/NonnullRefPtrVector.h>
#include <AK/RefCounted.h>
#include <LibJS/Heap/Handle.h>
#include <LibWeb/Bindings/CallbackType.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/MutationRecord.h>
#include <LibWeb/WebIDL/CallbackType.h>
namespace Web::DOM {
@ -32,7 +32,7 @@ class MutationObserver final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(MutationObserver, Bindings::PlatformObject);
public:
static JS::NonnullGCPtr<MutationObserver> create_with_global_object(HTML::Window&, JS::GCPtr<Bindings::CallbackType>);
static JS::NonnullGCPtr<MutationObserver> create_with_global_object(HTML::Window&, JS::GCPtr<WebIDL::CallbackType>);
virtual ~MutationObserver() override;
ExceptionOr<void> observe(Node& target, MutationObserverInit options = {});
@ -42,7 +42,7 @@ public:
Vector<WeakPtr<Node>>& node_list() { return m_node_list; }
Vector<WeakPtr<Node>> const& node_list() const { return m_node_list; }
Bindings::CallbackType& callback() { return *m_callback; }
WebIDL::CallbackType& callback() { return *m_callback; }
void enqueue_record(Badge<Node>, JS::NonnullGCPtr<MutationRecord> mutation_record)
{
@ -50,12 +50,12 @@ public:
}
private:
MutationObserver(HTML::Window&, JS::GCPtr<Bindings::CallbackType>);
MutationObserver(HTML::Window&, JS::GCPtr<WebIDL::CallbackType>);
virtual void visit_edges(Cell::Visitor&) override;
// https://dom.spec.whatwg.org/#concept-mo-callback
JS::GCPtr<Bindings::CallbackType> m_callback;
JS::GCPtr<WebIDL::CallbackType> m_callback;
// https://dom.spec.whatwg.org/#mutationobserver-node-list
// NOTE: These are weak, per https://dom.spec.whatwg.org/#garbage-collection

View file

@ -10,12 +10,12 @@
namespace Web::DOM {
JS::NonnullGCPtr<NodeFilter> NodeFilter::create(JS::Realm& realm, Bindings::CallbackType& callback)
JS::NonnullGCPtr<NodeFilter> NodeFilter::create(JS::Realm& realm, WebIDL::CallbackType& callback)
{
return *realm.heap().allocate<NodeFilter>(realm, realm, callback);
}
NodeFilter::NodeFilter(JS::Realm& realm, Bindings::CallbackType& callback)
NodeFilter::NodeFilter(JS::Realm& realm, WebIDL::CallbackType& callback)
: PlatformObject(*realm.intrinsics().object_prototype())
, m_callback(callback)
{

View file

@ -6,8 +6,8 @@
#pragma once
#include <LibWeb/Bindings/CallbackType.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/WebIDL/CallbackType.h>
namespace Web::DOM {
@ -15,11 +15,11 @@ class NodeFilter final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(NodeFilter, Bindings::PlatformObject);
public:
static JS::NonnullGCPtr<NodeFilter> create(JS::Realm&, Bindings::CallbackType&);
static JS::NonnullGCPtr<NodeFilter> create(JS::Realm&, WebIDL::CallbackType&);
virtual ~NodeFilter() = default;
Bindings::CallbackType& callback() { return m_callback; }
WebIDL::CallbackType& callback() { return m_callback; }
enum Result {
FILTER_ACCEPT = 1,
@ -28,11 +28,11 @@ public:
};
private:
NodeFilter(JS::Realm&, Bindings::CallbackType&);
NodeFilter(JS::Realm&, WebIDL::CallbackType&);
virtual void visit_edges(Cell::Visitor&) override;
Bindings::CallbackType& m_callback;
WebIDL::CallbackType& m_callback;
};
}

View file

@ -393,6 +393,10 @@ class SVGRectElement;
class SVGSVGElement;
}
namespace Web::WebIDL {
class CallbackType;
}
namespace Web::WebSockets {
class WebSocket;
}
@ -460,7 +464,6 @@ class URLSearchParamsIterator;
}
namespace Web::Bindings {
class CallbackType;
class LocationObject;
class OptionConstructor;
class RangePrototype;

View file

@ -15,7 +15,7 @@ EventHandler::EventHandler(String s)
{
}
EventHandler::EventHandler(Bindings::CallbackType& c)
EventHandler::EventHandler(WebIDL::CallbackType& c)
: value(&c)
{
}
@ -25,7 +25,7 @@ void EventHandler::visit_edges(Cell::Visitor& visitor)
Cell::visit_edges(visitor);
visitor.visit(listener);
if (auto* callback = value.get_pointer<Bindings::CallbackType*>())
if (auto* callback = value.get_pointer<WebIDL::CallbackType*>())
visitor.visit(*callback);
}

View file

@ -9,21 +9,21 @@
#include <AK/String.h>
#include <AK/Variant.h>
#include <LibJS/Heap/Cell.h>
#include <LibWeb/Bindings/CallbackType.h>
#include <LibWeb/WebIDL/CallbackType.h>
namespace Web::HTML {
class EventHandler final : public JS::Cell {
public:
explicit EventHandler(String);
explicit EventHandler(Bindings::CallbackType&);
explicit EventHandler(WebIDL::CallbackType&);
// Either uncompiled source code or a callback.
// https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-value
// NOTE: This does not contain Empty as part of the optimization of not allocating all event handler attributes up front.
// FIXME: The string should actually be an "internal raw uncompiled handler" struct. This struct is just the uncompiled source code plus a source location for reporting parse errors.
// https://html.spec.whatwg.org/multipage/webappapis.html#internal-raw-uncompiled-handler
Variant<String, Bindings::CallbackType*> value;
Variant<String, WebIDL::CallbackType*> value;
// https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-listener
DOM::DOMEventListener* listener { nullptr };

View file

@ -13,11 +13,11 @@ namespace Web::HTML {
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void GlobalEventHandlers::set_##attribute_name(Bindings::CallbackType* value) \
void GlobalEventHandlers::set_##attribute_name(WebIDL::CallbackType* value) \
{ \
global_event_handlers_to_event_target(event_name).set_event_handler_attribute(event_name, value); \
} \
Bindings::CallbackType* GlobalEventHandlers::attribute_name() \
WebIDL::CallbackType* GlobalEventHandlers::attribute_name() \
{ \
return global_event_handlers_to_event_target(event_name).event_handler_attribute(event_name); \
}

View file

@ -84,9 +84,9 @@ public:
virtual ~GlobalEventHandlers();
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(Bindings::CallbackType*); \
Bindings::CallbackType* attribute_name();
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(WebIDL::CallbackType*); \
WebIDL::CallbackType* attribute_name();
ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -112,14 +112,14 @@ void MessagePort::close()
}
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void MessagePort::set_##attribute_name(Bindings::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, value); \
} \
Bindings::CallbackType* MessagePort::attribute_name() \
{ \
return event_handler_attribute(event_name); \
#define __ENUMERATE(attribute_name, event_name) \
void MessagePort::set_##attribute_name(WebIDL::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, value); \
} \
WebIDL::CallbackType* MessagePort::attribute_name() \
{ \
return event_handler_attribute(event_name); \
}
ENUMERATE_MESSAGE_PORT_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -37,9 +37,9 @@ public:
void close();
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(Bindings::CallbackType*); \
Bindings::CallbackType* attribute_name();
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(WebIDL::CallbackType*); \
WebIDL::CallbackType* attribute_name();
ENUMERATE_MESSAGE_PORT_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -213,7 +213,7 @@ i32 Window::run_timer_initialization_steps(TimerHandler handler, i32 timeout, JS
handler.visit(
// 2. If handler is a Function, then invoke handler given arguments with the callback this value set to thisArg. If this throws an exception, catch it, and report the exception.
[&](JS::Handle<Bindings::CallbackType> callback) {
[&](JS::Handle<WebIDL::CallbackType> callback) {
if (auto result = Bindings::IDL::invoke_callback(*callback, window.ptr(), arguments); result.is_error())
HTML::report_exception(result);
},
@ -277,7 +277,7 @@ i32 Window::run_timer_initialization_steps(TimerHandler handler, i32 timeout, JS
}
// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#run-the-animation-frame-callbacks
i32 Window::request_animation_frame_impl(Bindings::CallbackType& js_callback)
i32 Window::request_animation_frame_impl(WebIDL::CallbackType& js_callback)
{
return m_animation_frame_callback_driver.add([this, js_callback = JS::make_handle(js_callback)](auto) mutable {
// 3. Invoke callback, passing now as the only argument,
@ -506,7 +506,7 @@ void Window::fire_a_page_transition_event(FlyString const& event_name, bool pers
}
// https://html.spec.whatwg.org/#dom-queuemicrotask
void Window::queue_microtask_impl(Bindings::CallbackType& callback)
void Window::queue_microtask_impl(WebIDL::CallbackType& callback)
{
// The queueMicrotask(callback) method must queue a microtask to invoke callback,
HTML::queue_a_microtask(&associated_document(), [&callback]() mutable {
@ -686,7 +686,7 @@ void Window::invoke_idle_callbacks()
}
// https://w3c.github.io/requestidlecallback/#the-requestidlecallback-method
u32 Window::request_idle_callback_impl(Bindings::CallbackType& callback)
u32 Window::request_idle_callback_impl(WebIDL::CallbackType& callback)
{
// 1. Let window be this Window object.
auto& window = *this;
@ -696,7 +696,7 @@ u32 Window::request_idle_callback_impl(Bindings::CallbackType& callback)
auto handle = window.m_idle_callback_identifier;
// 4. Push callback to the end of window's list of idle request callbacks, associated with handle.
auto handler = [callback = JS::make_handle(callback)](JS::NonnullGCPtr<RequestIdleCallback::IdleDeadline> deadline) -> JS::Completion {
return Bindings::IDL::invoke_callback(const_cast<Bindings::CallbackType&>(*callback), {}, deadline.ptr());
return Bindings::IDL::invoke_callback(const_cast<WebIDL::CallbackType&>(*callback), {}, deadline.ptr());
};
window.m_idle_request_callbacks.append(adopt_ref(*new IdleCallback(move(handler), handle)));
// 5. Return handle and then continue running this algorithm asynchronously.
@ -914,7 +914,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::prompt)
static JS::ThrowCompletionOr<TimerHandler> make_timer_handler(JS::VM& vm, JS::Value handler)
{
if (handler.is_function())
return JS::make_handle(vm.heap().allocate_without_realm<Bindings::CallbackType>(handler.as_function(), HTML::incumbent_settings_object()));
return JS::make_handle(vm.heap().allocate_without_realm<WebIDL::CallbackType>(handler.as_function(), HTML::incumbent_settings_object()));
return TRY(handler.to_string(vm));
}
@ -996,7 +996,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::request_animation_frame)
auto* callback_object = TRY(vm.argument(0).to_object(vm));
if (!callback_object->is_function())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
auto* callback = vm.heap().allocate_without_realm<Bindings::CallbackType>(*callback_object, HTML::incumbent_settings_object());
auto* callback = vm.heap().allocate_without_realm<WebIDL::CallbackType>(*callback_object, HTML::incumbent_settings_object());
return JS::Value(impl->request_animation_frame_impl(*callback));
}
@ -1019,7 +1019,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::queue_microtask)
if (!callback_object->is_function())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
auto* callback = vm.heap().allocate_without_realm<Bindings::CallbackType>(*callback_object, HTML::incumbent_settings_object());
auto* callback = vm.heap().allocate_without_realm<WebIDL::CallbackType>(*callback_object, HTML::incumbent_settings_object());
impl->queue_microtask_impl(*callback);
return JS::js_undefined();
@ -1035,7 +1035,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::request_idle_callback)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
// FIXME: accept options object
auto* callback = vm.heap().allocate_without_realm<Bindings::CallbackType>(*callback_object, HTML::incumbent_settings_object());
auto* callback = vm.heap().allocate_without_realm<WebIDL::CallbackType>(*callback_object, HTML::incumbent_settings_object());
return JS::Value(impl->request_idle_callback_impl(*callback));
}
@ -1461,26 +1461,26 @@ JS_DEFINE_NATIVE_FUNCTION(Window::name_setter)
return JS::js_undefined();
}
#define __ENUMERATE(attribute, event_name) \
JS_DEFINE_NATIVE_FUNCTION(Window::attribute##_getter) \
{ \
auto* impl = TRY(impl_from(vm)); \
auto retval = impl->attribute(); \
if (!retval) \
return JS::js_null(); \
return &retval->callback; \
} \
JS_DEFINE_NATIVE_FUNCTION(Window::attribute##_setter) \
{ \
auto* impl = TRY(impl_from(vm)); \
auto value = vm.argument(0); \
Bindings::CallbackType* cpp_value = nullptr; \
if (value.is_object()) { \
cpp_value = vm.heap().allocate_without_realm<Bindings::CallbackType>( \
value.as_object(), HTML::incumbent_settings_object()); \
} \
impl->set_##attribute(cpp_value); \
return JS::js_undefined(); \
#define __ENUMERATE(attribute, event_name) \
JS_DEFINE_NATIVE_FUNCTION(Window::attribute##_getter) \
{ \
auto* impl = TRY(impl_from(vm)); \
auto retval = impl->attribute(); \
if (!retval) \
return JS::js_null(); \
return &retval->callback; \
} \
JS_DEFINE_NATIVE_FUNCTION(Window::attribute##_setter) \
{ \
auto* impl = TRY(impl_from(vm)); \
auto value = vm.argument(0); \
WebIDL::CallbackType* cpp_value = nullptr; \
if (value.is_object()) { \
cpp_value = vm.heap().allocate_without_realm<WebIDL::CallbackType>( \
value.as_object(), HTML::incumbent_settings_object()); \
} \
impl->set_##attribute(cpp_value); \
return JS::js_undefined(); \
}
ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE)
ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE)

View file

@ -25,7 +25,7 @@ namespace Web::HTML {
class IdleCallback;
// https://html.spec.whatwg.org/#timerhandler
using TimerHandler = Variant<JS::Handle<Bindings::CallbackType>, String>;
using TimerHandler = Variant<JS::Handle<WebIDL::CallbackType>, String>;
class Window final
: public DOM::EventTarget
@ -57,7 +57,7 @@ public:
void alert_impl(String const&);
bool confirm_impl(String const&);
String prompt_impl(String const&, String const&);
i32 request_animation_frame_impl(Bindings::CallbackType& js_callback);
i32 request_animation_frame_impl(WebIDL::CallbackType& js_callback);
void cancel_animation_frame_impl(i32);
bool has_animation_frame_callbacks() const { return m_animation_frame_callback_driver.has_callbacks(); }
@ -66,7 +66,7 @@ public:
void clear_timeout_impl(i32);
void clear_interval_impl(i32);
void queue_microtask_impl(Bindings::CallbackType& callback);
void queue_microtask_impl(WebIDL::CallbackType& callback);
int inner_width() const;
int inner_height() const;
@ -115,7 +115,7 @@ public:
void start_an_idle_period();
u32 request_idle_callback_impl(Bindings::CallbackType& callback);
u32 request_idle_callback_impl(WebIDL::CallbackType& callback);
void cancel_idle_callback_impl(u32);
AnimationFrameCallbackDriver& animation_frame_callback_driver() { return m_animation_frame_callback_driver; }

View file

@ -12,11 +12,11 @@ namespace Web::HTML {
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void WindowEventHandlers::set_##attribute_name(Bindings::CallbackType* value) \
void WindowEventHandlers::set_##attribute_name(WebIDL::CallbackType* value) \
{ \
window_event_handlers_to_event_target().set_event_handler_attribute(event_name, value); \
} \
Bindings::CallbackType* WindowEventHandlers::attribute_name() \
WebIDL::CallbackType* WindowEventHandlers::attribute_name() \
{ \
return window_event_handlers_to_event_target().event_handler_attribute(event_name); \
}

View file

@ -34,9 +34,9 @@ public:
virtual ~WindowEventHandlers();
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(Bindings::CallbackType*); \
Bindings::CallbackType* attribute_name();
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(WebIDL::CallbackType*); \
WebIDL::CallbackType* attribute_name();
ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -333,14 +333,14 @@ void Worker::post_message(JS::Value message, JS::Value)
}
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void Worker::set_##attribute_name(Bindings::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, move(value)); \
} \
Bindings::CallbackType* Worker::attribute_name() \
{ \
return event_handler_attribute(event_name); \
#define __ENUMERATE(attribute_name, event_name) \
void Worker::set_##attribute_name(WebIDL::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, move(value)); \
} \
WebIDL::CallbackType* Worker::attribute_name() \
{ \
return event_handler_attribute(event_name); \
}
ENUMERATE_WORKER_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -52,9 +52,9 @@ public:
JS::GCPtr<MessagePort> outside_message_port() { return m_outside_port; }
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(Bindings::CallbackType*); \
Bindings::CallbackType* attribute_name();
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(WebIDL::CallbackType*); \
WebIDL::CallbackType* attribute_name();
ENUMERATE_WORKER_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -85,14 +85,14 @@ JS::NonnullGCPtr<WorkerNavigator> WorkerGlobalScope::navigator() const
}
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void WorkerGlobalScope::set_##attribute_name(Bindings::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, move(value)); \
} \
Bindings::CallbackType* WorkerGlobalScope::attribute_name() \
{ \
return event_handler_attribute(event_name); \
#define __ENUMERATE(attribute_name, event_name) \
void WorkerGlobalScope::set_##attribute_name(WebIDL::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, move(value)); \
} \
WebIDL::CallbackType* WorkerGlobalScope::attribute_name() \
{ \
return event_handler_attribute(event_name); \
}
ENUMERATE_WORKER_GLOBAL_SCOPE_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -45,9 +45,9 @@ public:
DOM::ExceptionOr<void> import_scripts(Vector<String> urls);
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(Bindings::CallbackType*); \
Bindings::CallbackType* attribute_name();
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(WebIDL::CallbackType*); \
WebIDL::CallbackType* attribute_name();
ENUMERATE_WORKER_GLOBAL_SCOPE_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -11,7 +11,7 @@
namespace Web::IntersectionObserver {
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-intersectionobserver
JS::NonnullGCPtr<IntersectionObserver> IntersectionObserver::create_with_global_object(HTML::Window& window, Bindings::CallbackType* callback, IntersectionObserverInit const& options)
JS::NonnullGCPtr<IntersectionObserver> IntersectionObserver::create_with_global_object(HTML::Window& window, WebIDL::CallbackType* callback, IntersectionObserverInit const& options)
{
// FIXME: Implement
(void)callback;

View file

@ -22,7 +22,7 @@ class IntersectionObserver : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(IntersectionObserver, Bindings::PlatformObject);
public:
static JS::NonnullGCPtr<IntersectionObserver> create_with_global_object(HTML::Window&, Bindings::CallbackType* callback, IntersectionObserverInit const& options = {});
static JS::NonnullGCPtr<IntersectionObserver> create_with_global_object(HTML::Window&, WebIDL::CallbackType* callback, IntersectionObserverInit const& options = {});
virtual ~IntersectionObserver() override;

View file

@ -11,7 +11,7 @@
namespace Web::ResizeObserver {
// https://drafts.csswg.org/resize-observer/#dom-resizeobserver-resizeobserver
JS::NonnullGCPtr<ResizeObserver> ResizeObserver::create_with_global_object(HTML::Window& window, Bindings::CallbackType* callback)
JS::NonnullGCPtr<ResizeObserver> ResizeObserver::create_with_global_object(HTML::Window& window, WebIDL::CallbackType* callback)
{
// FIXME: Implement
(void)callback;

View file

@ -19,7 +19,7 @@ class ResizeObserver : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(ResizeObserver, Bindings::PlatformObject);
public:
static JS::NonnullGCPtr<ResizeObserver> create_with_global_object(HTML::Window&, Bindings::CallbackType* callback);
static JS::NonnullGCPtr<ResizeObserver> create_with_global_object(HTML::Window&, WebIDL::CallbackType* callback);
virtual ~ResizeObserver() override;

View file

@ -5,9 +5,9 @@
*/
#include <LibJS/Runtime/Object.h>
#include <LibWeb/Bindings/CallbackType.h>
#include <LibWeb/WebIDL/CallbackType.h>
namespace Web::Bindings {
namespace Web::WebIDL {
CallbackType::CallbackType(JS::Object& callback, HTML::EnvironmentSettingsObject& callback_context)
: callback(callback)

View file

@ -10,7 +10,7 @@
#include <LibJS/Heap/Cell.h>
#include <LibWeb/Forward.h>
namespace Web::Bindings {
namespace Web::WebIDL {
// https://heycam.github.io/webidl/#idl-callback-interface
class CallbackType final : public JS::Cell {

View file

@ -231,14 +231,14 @@ void WebSocket::on_message(ByteBuffer message, bool is_text)
}
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void WebSocket::set_##attribute_name(Bindings::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, value); \
} \
Bindings::CallbackType* WebSocket::attribute_name() \
{ \
return event_handler_attribute(event_name); \
#define __ENUMERATE(attribute_name, event_name) \
void WebSocket::set_##attribute_name(WebIDL::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, value); \
} \
WebIDL::CallbackType* WebSocket::attribute_name() \
{ \
return event_handler_attribute(event_name); \
}
ENUMERATE_WEBSOCKET_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -44,9 +44,9 @@ public:
String url() const { return m_url.to_string(); }
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(Bindings::CallbackType*); \
Bindings::CallbackType* attribute_name();
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(WebIDL::CallbackType*); \
WebIDL::CallbackType* attribute_name();
ENUMERATE_WEBSOCKET_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -519,12 +519,12 @@ DOM::ExceptionOr<void> XMLHttpRequest::send(Optional<Fetch::XMLHttpRequestBodyIn
return {};
}
Bindings::CallbackType* XMLHttpRequest::onreadystatechange()
WebIDL::CallbackType* XMLHttpRequest::onreadystatechange()
{
return event_handler_attribute(Web::XHR::EventNames::readystatechange);
}
void XMLHttpRequest::set_onreadystatechange(Bindings::CallbackType* value)
void XMLHttpRequest::set_onreadystatechange(WebIDL::CallbackType* value)
{
set_event_handler_attribute(Web::XHR::EventNames::readystatechange, value);
}

View file

@ -55,8 +55,8 @@ public:
String get_response_header(String const& name) { return m_response_headers.get(name).value_or({}); }
String get_all_response_headers() const;
Bindings::CallbackType* onreadystatechange();
void set_onreadystatechange(Bindings::CallbackType*);
WebIDL::CallbackType* onreadystatechange();
void set_onreadystatechange(WebIDL::CallbackType*);
DOM::ExceptionOr<void> override_mime_type(String const& mime);

View file

@ -11,14 +11,14 @@
namespace Web::XHR {
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void XMLHttpRequestEventTarget::set_##attribute_name(Bindings::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, value); \
} \
Bindings::CallbackType* XMLHttpRequestEventTarget::attribute_name() \
{ \
return event_handler_attribute(event_name); \
#define __ENUMERATE(attribute_name, event_name) \
void XMLHttpRequestEventTarget::set_##attribute_name(WebIDL::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, value); \
} \
WebIDL::CallbackType* XMLHttpRequestEventTarget::attribute_name() \
{ \
return event_handler_attribute(event_name); \
}
ENUMERATE_XML_HTTP_REQUEST_EVENT_TARGET_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -27,9 +27,9 @@ public:
virtual ~XMLHttpRequestEventTarget() override {};
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(Bindings::CallbackType*); \
Bindings::CallbackType* attribute_name();
#define __ENUMERATE(attribute_name, event_name) \
void set_##attribute_name(WebIDL::CallbackType*); \
WebIDL::CallbackType* attribute_name();
ENUMERATE_XML_HTTP_REQUEST_EVENT_TARGET_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE