1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 09:07:44 +00:00

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
43 changed files with 168 additions and 165 deletions

View file

@ -1,25 +0,0 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/Object.h>
#include <LibWeb/Bindings/CallbackType.h>
namespace Web::Bindings {
CallbackType::CallbackType(JS::Object& callback, HTML::EnvironmentSettingsObject& callback_context)
: callback(callback)
, callback_context(callback_context)
{
}
StringView CallbackType::class_name() const { return "CallbackType"sv; }
void CallbackType::visit_edges(Cell::Visitor& visitor)
{
Cell::visit_edges(visitor);
visitor.visit(&callback);
}
}

View file

@ -1,30 +0,0 @@
/*
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Heap/Cell.h>
#include <LibWeb/Forward.h>
namespace Web::Bindings {
// https://heycam.github.io/webidl/#idl-callback-interface
class CallbackType final : public JS::Cell {
public:
CallbackType(JS::Object& callback, HTML::EnvironmentSettingsObject& callback_context);
JS::Object& callback;
// https://heycam.github.io/webidl/#dfn-callback-context
HTML::EnvironmentSettingsObject& callback_context;
private:
virtual StringView class_name() const override;
virtual void visit_edges(Cell::Visitor&) override;
};
}

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;