mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:27:35 +00:00
LibJS: Make intrinsics getters return NonnullGCPtr
Some of these are allocated upon initialization of the intrinsics, and some lazily, but in neither case the getters actually return a nullptr. This saves us a whole bunch of pointer dereferences (as NonnullGCPtr has an `operator T&()`), and also has the interesting side effect of forcing us to explicitly use the FunctionObject& overload of call(), as passing a NonnullGCPtr is ambigous - it could implicitly be turned into a Value _or_ a FunctionObject& (so we have to dereference manually).
This commit is contained in:
parent
ed9e2366da
commit
b84f8fb55b
182 changed files with 564 additions and 567 deletions
|
@ -15,7 +15,7 @@
|
|||
namespace Web::Bindings {
|
||||
|
||||
AudioConstructor::AudioConstructor(JS::Realm& realm)
|
||||
: NativeFunction(*realm.intrinsics().function_prototype())
|
||||
: NativeFunction(realm.intrinsics().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
namespace Web::Bindings {
|
||||
|
||||
ImageConstructor::ImageConstructor(JS::Realm& realm)
|
||||
: NativeFunction(*realm.intrinsics().function_prototype())
|
||||
: NativeFunction(realm.intrinsics().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
namespace Web::Bindings {
|
||||
|
||||
OptionConstructor::OptionConstructor(JS::Realm& realm)
|
||||
: NativeFunction(*realm.intrinsics().function_prototype())
|
||||
: NativeFunction(realm.intrinsics().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<IDLEventListener>> IDLEventListener::create
|
|||
}
|
||||
|
||||
IDLEventListener::IDLEventListener(JS::Realm& realm, JS::NonnullGCPtr<WebIDL::CallbackType> callback)
|
||||
: JS::Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
|
||||
: JS::Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
|
||||
, m_callback(move(callback))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<NodeFilter>> NodeFilter::create(JS::Realm&
|
|||
}
|
||||
|
||||
NodeFilter::NodeFilter(JS::Realm& realm, WebIDL::CallbackType& callback)
|
||||
: PlatformObject(*realm.intrinsics().object_prototype())
|
||||
: PlatformObject(realm.intrinsics().object_prototype())
|
||||
, m_callback(callback)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ WebIDL::ExceptionOr<JS::Value> parse_json_string_to_javascript_value(JS::Realm&
|
|||
auto& vm = realm.vm();
|
||||
|
||||
// 1. Return ? Call(%JSON.parse%, undefined, « string »).
|
||||
return TRY(JS::call(vm, realm.intrinsics().json_parse_function(), JS::js_undefined(), MUST_OR_THROW_OOM(JS::PrimitiveString::create(vm, string))));
|
||||
return TRY(JS::call(vm, *realm.intrinsics().json_parse_function(), JS::js_undefined(), MUST_OR_THROW_OOM(JS::PrimitiveString::create(vm, string))));
|
||||
}
|
||||
|
||||
// https://infra.spec.whatwg.org/#parse-json-bytes-to-a-javascript-value
|
||||
|
@ -42,7 +42,7 @@ WebIDL::ExceptionOr<String> serialize_javascript_value_to_json_string(JS::VM& vm
|
|||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let result be ? Call(%JSON.stringify%, undefined, « value »).
|
||||
auto result = TRY(JS::call(vm, realm.intrinsics().json_stringify_function(), JS::js_undefined(), value));
|
||||
auto result = TRY(JS::call(vm, *realm.intrinsics().json_stringify_function(), JS::js_undefined(), value));
|
||||
|
||||
// 2. If result is undefined, then throw a TypeError.
|
||||
if (result.is_undefined())
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -362,7 +362,7 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
|
|||
return ExecuteScriptResult { ExecuteScriptResultType::PromiseResolved, JS::js_null() };
|
||||
|
||||
// 9. Let scriptPromise be PromiseResolve(Promise, scriptResult.[[Value]]).
|
||||
auto script_promise_or_error = JS::promise_resolve(vm, *realm.intrinsics().promise_constructor(), script_result.value());
|
||||
auto script_promise_or_error = JS::promise_resolve(vm, realm.intrinsics().promise_constructor(), script_result.value());
|
||||
if (script_promise_or_error.is_throw_completion())
|
||||
return ExecuteScriptResult { ExecuteScriptResultType::PromiseRejected, *script_promise_or_error.throw_completion().value() };
|
||||
auto& script_promise = static_cast<JS::Promise&>(*script_promise_or_error.value());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -22,7 +22,7 @@ JS::NonnullGCPtr<Promise> create_promise(JS::Realm& realm)
|
|||
auto& vm = realm.vm();
|
||||
|
||||
// 1. Let constructor be realm.[[Intrinsics]].[[%Promise%]].
|
||||
auto* constructor = realm.intrinsics().promise_constructor();
|
||||
auto constructor = realm.intrinsics().promise_constructor();
|
||||
|
||||
// Return ? NewPromiseCapability(constructor).
|
||||
// NOTE: When called with %Promise%, NewPromiseCapability can't throw.
|
||||
|
@ -37,7 +37,7 @@ JS::NonnullGCPtr<Promise> create_resolved_promise(JS::Realm& realm, JS::Value va
|
|||
// 1. Let value be the result of converting x to an ECMAScript value.
|
||||
|
||||
// 2. Let constructor be realm.[[Intrinsics]].[[%Promise%]].
|
||||
auto* constructor = realm.intrinsics().promise_constructor();
|
||||
auto constructor = realm.intrinsics().promise_constructor();
|
||||
|
||||
// 3. Let promiseCapability be ? NewPromiseCapability(constructor).
|
||||
// NOTE: When called with %Promise%, NewPromiseCapability can't throw.
|
||||
|
@ -56,7 +56,7 @@ JS::NonnullGCPtr<Promise> create_rejected_promise(JS::Realm& realm, JS::Value re
|
|||
auto& vm = realm.vm();
|
||||
|
||||
// 1. Let constructor be realm.[[Intrinsics]].[[%Promise%]].
|
||||
auto* constructor = realm.intrinsics().promise_constructor();
|
||||
auto constructor = realm.intrinsics().promise_constructor();
|
||||
|
||||
// 2. Let promiseCapability be ? NewPromiseCapability(constructor).
|
||||
// NOTE: When called with %Promise%, NewPromiseCapability can't throw.
|
||||
|
@ -132,7 +132,7 @@ JS::NonnullGCPtr<JS::Promise> react_to_promise(Promise const& promise, Optional<
|
|||
auto on_rejected = JS::NativeFunction::create(realm, move(on_rejected_steps), 1, "");
|
||||
|
||||
// 5. Let constructor be promise.[[Promise]].[[Realm]].[[Intrinsics]].[[%Promise%]].
|
||||
auto* constructor = realm.intrinsics().promise_constructor();
|
||||
auto constructor = realm.intrinsics().promise_constructor();
|
||||
|
||||
// 6. Let newCapability be ? NewPromiseCapability(constructor).
|
||||
// NOTE: When called with %Promise%, NewPromiseCapability can't throw.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue