mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
BindingsGenerator+LibWeb: Pass a VM to static IDL-based functions
This saves us from having to yoink the VM out of thin air.
This commit is contained in:
parent
8a78679152
commit
0823a3c422
Notes:
sideshowbarker
2024-07-17 06:11:48 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/0823a3c422 Pull-request: https://github.com/SerenityOS/serenity/pull/15483 Reviewed-by: https://github.com/linusg ✅
4 changed files with 14 additions and 11 deletions
|
@ -1668,6 +1668,12 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@@overload_suffi
|
|||
[[maybe_unused]] auto retval = TRY(throw_dom_exception_if_needed(vm, [&] { return impl->@function.cpp_name@(@.arguments@); }));
|
||||
)~~~");
|
||||
} else {
|
||||
// Make sure first argument for static functions is the Realm.
|
||||
if (arguments_builder.is_empty())
|
||||
function_generator.set(".arguments", "vm");
|
||||
else
|
||||
function_generator.set(".arguments", String::formatted("vm, {}", arguments_builder.string_view()));
|
||||
|
||||
function_generator.append(R"~~~(
|
||||
[[maybe_unused]] auto retval = TRY(throw_dom_exception_if_needed(vm, [&] { return @interface_fully_qualified_name@::@function.cpp_name@(@.arguments@); }));
|
||||
)~~~");
|
||||
|
|
|
@ -152,19 +152,17 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::construct_impl(JS::Rea
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-response-error
|
||||
JS::NonnullGCPtr<Response> Response::error()
|
||||
JS::NonnullGCPtr<Response> Response::error(JS::VM& vm)
|
||||
{
|
||||
auto& vm = Bindings::main_thread_vm();
|
||||
|
||||
// The static error() method steps are to return the result of creating a Response object, given a new network error, "immutable", and this’s relevant Realm.
|
||||
// FIXME: How can we reliably get 'this', i.e. the object the function was called on, in IDL-defined functions?
|
||||
return Response::create(Infrastructure::Response::network_error(), Headers::Guard::Immutable, *vm.current_realm());
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-response-redirect
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::redirect(String const& url, u16 status)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::redirect(JS::VM& vm, String const& url, u16 status)
|
||||
{
|
||||
auto& realm = HTML::current_settings_object().realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let parsedURL be the result of parsing url with current settings object’s API base URL.
|
||||
auto api_base_url = HTML::current_settings_object().api_base_url();
|
||||
|
@ -200,9 +198,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::redirect(String const&
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-response-json
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::json(JS::Value data, ResponseInit const& init)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::json(JS::VM& vm, JS::Value data, ResponseInit const& init)
|
||||
{
|
||||
auto& vm = Bindings::main_thread_vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let bytes the result of running serialize a JavaScript value to JSON bytes on data.
|
||||
|
|
|
@ -44,9 +44,9 @@ public:
|
|||
[[nodiscard]] NonnullRefPtr<Infrastructure::Response> response() const { return m_response; }
|
||||
|
||||
// JS API functions
|
||||
[[nodiscard]] static JS::NonnullGCPtr<Response> error();
|
||||
[[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> redirect(String const& url, u16 status);
|
||||
[[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> json(JS::Value data, ResponseInit const& init = {});
|
||||
[[nodiscard]] static JS::NonnullGCPtr<Response> error(JS::VM&);
|
||||
[[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> redirect(JS::VM&, String const& url, u16 status);
|
||||
[[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> json(JS::VM&, JS::Value data, ResponseInit const& init = {});
|
||||
[[nodiscard]] Bindings::ResponseType type() const;
|
||||
[[nodiscard]] String url() const;
|
||||
[[nodiscard]] bool redirected() const;
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
virtual void inserted() override;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/scripting.html#dom-script-supports
|
||||
static bool supports(String const& type)
|
||||
static bool supports(JS::VM&, String const& type)
|
||||
{
|
||||
return type.is_one_of("classic", "module");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue