1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:57:35 +00:00

LibJS: Remove GlobalObject parameter from native functions

This commit is contained in:
Linus Groh 2022-08-22 11:48:08 +01:00
parent 7b990c27a1
commit b465f46e00
77 changed files with 240 additions and 215 deletions

View file

@ -126,7 +126,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
// 2. If IsCallable(value) is true, then set value to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the IDL operation P on object O.
if (value->is_function()) {
value = JS::NativeFunction::create(
realm, [function = JS::make_handle(*value)](auto& vm, auto&) {
realm, [function = JS::make_handle(*value)](auto& vm) {
return JS::call(vm, function.value(), JS::js_undefined());
},
0, "");
@ -143,7 +143,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
// 2. If e.[[NeedsGet]] is true, then set crossOriginGet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the getter of the IDL attribute P on object O.
if (*entry.needs_get) {
cross_origin_get = JS::NativeFunction::create(
realm, [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto& vm, auto&) {
realm, [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto& vm) {
return JS::call(vm, getter.cell(), object_ptr);
},
0, "");
@ -155,7 +155,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
// If e.[[NeedsSet]] is true, then set crossOriginSet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the setter of the IDL attribute P on object O.
if (*entry.needs_set) {
cross_origin_set = JS::NativeFunction::create(
realm, [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto& vm, auto&) {
realm, [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto& vm) {
return JS::call(vm, setter.cell(), object_ptr);
},
0, "");

View file

@ -95,6 +95,8 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter)
// https://html.spec.whatwg.org/multipage/history.html#the-location-interface:dom-location-href-2
JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
auto& window = static_cast<WindowObject&>(global_object);
// FIXME: 1. If this's relevant Document is null, then return.
@ -218,6 +220,8 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::port_getter)
// https://html.spec.whatwg.org/multipage/history.html#dom-location-reload
JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
auto& window = static_cast<WindowObject&>(global_object);
window.impl().did_call_location_reload({});
return JS::js_undefined();
@ -226,6 +230,8 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload)
// https://html.spec.whatwg.org/multipage/history.html#dom-location-replace
JS_DEFINE_NATIVE_FUNCTION(LocationObject::replace)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
auto& window = static_cast<WindowObject&>(global_object);
auto url = TRY(vm.argument(0).to_string(vm));
// FIXME: This needs spec compliance work.

View file

@ -626,7 +626,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll)
// https://www.w3.org/TR/cssom-view/#dom-window-scrollby
JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto* impl = TRY(impl_from(vm));
if (!impl->page())

View file

@ -524,7 +524,7 @@ void EventTarget::activate_event_handler(FlyString const& name, HTML::EventHandl
// document.body.remove();
// location.reload();
// The body element is no longer in the DOM and there is no variable holding onto it. However, the onunload handler is still called, meaning the callback keeps the body element alive.
auto callback_function = JS::NativeFunction::create(realm, "", [event_target = NonnullRefPtr(*this), name](JS::VM& vm, auto&) mutable -> JS::ThrowCompletionOr<JS::Value> {
auto callback_function = JS::NativeFunction::create(realm, "", [event_target = NonnullRefPtr(*this), name](JS::VM& vm) mutable -> JS::ThrowCompletionOr<JS::Value> {
// The event dispatcher should only call this with one argument.
VERIFY(vm.argument_count() == 1);

View file

@ -122,7 +122,7 @@ void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_setti
// FIXME: This should be done with IDL
u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable;
m_worker_scope->define_native_function(
"postMessage", [this](auto& vm, auto&) {
"postMessage", [this](auto& vm) {
// This is the implementation of the function that the spawned worked calls
// https://html.spec.whatwg.org/multipage/workers.html#dom-dedicatedworkerglobalscope-postmessage

View file

@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto* this_object = TRY(vm.this_value().to_object(vm));
if (!is<WebAssemblyMemoryObject>(this_object))

View file

@ -154,7 +154,7 @@ JS::ThrowCompletionOr<size_t> parse_module(JS::VM& vm, JS::Object* buffer_object
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// FIXME: This shouldn't block!
auto buffer_or_error = vm.argument(0).to_object(vm);
@ -317,7 +317,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(JS::VM& vm,
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// FIXME: This shouldn't block!
auto buffer_or_error = vm.argument(0).to_object(vm);
@ -449,8 +449,8 @@ JS::NativeFunction* create_native_function(JS::VM& vm, Wasm::FunctionAddress add
auto function = JS::NativeFunction::create(
realm,
name,
[address, type = type.release_value()](JS::VM& vm, JS::GlobalObject& global_object) -> JS::ThrowCompletionOr<JS::Value> {
auto& realm = *global_object.associated_realm();
[address, type = type.release_value()](JS::VM& vm) -> JS::ThrowCompletionOr<JS::Value> {
auto& realm = *vm.current_realm();
Vector<Wasm::Value> values;
values.ensure_capacity(type.parameters().size());