diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp index 2392f3950b..ecbbf8efb7 100644 --- a/Libraries/LibJS/Interpreter.cpp +++ b/Libraries/LibJS/Interpreter.cpp @@ -195,15 +195,15 @@ void Interpreter::gather_roots(Badge, HashTable& roots) } } -Value Interpreter::call(Function* function, Value this_value, Optional arguments) +Value Interpreter::call(Function& function, Value this_value, Optional arguments) { auto& call_frame = push_call_frame(); - call_frame.function_name = function->name(); + call_frame.function_name = function.name(); call_frame.this_value = this_value; if (arguments.has_value()) call_frame.arguments = arguments.value().values(); - call_frame.environment = function->create_environment(); - auto result = function->call(*this); + call_frame.environment = function.create_environment(); + auto result = function.call(*this); pop_call_frame(); return result; } diff --git a/Libraries/LibJS/Interpreter.h b/Libraries/LibJS/Interpreter.h index 0640b5a919..8ec4b6de15 100644 --- a/Libraries/LibJS/Interpreter.h +++ b/Libraries/LibJS/Interpreter.h @@ -103,7 +103,7 @@ public: void enter_scope(const ScopeNode&, ArgumentVector, ScopeType); void exit_scope(const ScopeNode&); - Value call(Function*, Value this_value = {}, Optional arguments = {}); + Value call(Function&, Value this_value = {}, Optional arguments = {}); CallFrame& push_call_frame() { diff --git a/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 29505a270c..003013b1a0 100644 --- a/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -105,7 +105,7 @@ Value ArrayPrototype::filter(Interpreter& interpreter) arguments.append(value); arguments.append(Value((i32)i)); arguments.append(array); - auto result = interpreter.call(callback, this_value, move(arguments)); + auto result = interpreter.call(*callback, this_value, move(arguments)); if (interpreter.exception()) return {}; if (result.to_boolean()) @@ -134,7 +134,7 @@ Value ArrayPrototype::for_each(Interpreter& interpreter) arguments.append(value); arguments.append(Value((i32)i)); arguments.append(array); - interpreter.call(callback, this_value, move(arguments)); + interpreter.call(*callback, this_value, move(arguments)); if (interpreter.exception()) return {}; } @@ -171,7 +171,7 @@ Value ArrayPrototype::map(Interpreter& interpreter) arguments.append(Value((i32)i)); arguments.append(array); - auto result = interpreter.call(callback, this_value, move(arguments)); + auto result = interpreter.call(*callback, this_value, move(arguments)); if (interpreter.exception()) return {}; @@ -465,7 +465,7 @@ Value ArrayPrototype::find(Interpreter& interpreter) arguments.append(Value((i32)i)); arguments.append(array); - auto result = interpreter.call(callback, this_value, move(arguments)); + auto result = interpreter.call(*callback, this_value, move(arguments)); if (interpreter.exception()) return {}; @@ -502,7 +502,7 @@ Value ArrayPrototype::find_index(Interpreter& interpreter) arguments.append(Value((i32)i)); arguments.append(array); - auto result = interpreter.call(callback, this_value, move(arguments)); + auto result = interpreter.call(*callback, this_value, move(arguments)); if (interpreter.exception()) return {}; @@ -539,7 +539,7 @@ Value ArrayPrototype::some(Interpreter& interpreter) arguments.append(Value((i32)i)); arguments.append(array); - auto result = interpreter.call(callback, this_value, move(arguments)); + auto result = interpreter.call(*callback, this_value, move(arguments)); if (interpreter.exception()) return {}; diff --git a/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Libraries/LibJS/Runtime/FunctionPrototype.cpp index b7d6b114b7..68a90b57d3 100644 --- a/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -64,7 +64,7 @@ Value FunctionPrototype::apply(Interpreter& interpreter) return {}; if (!this_object->is_function()) return interpreter.throw_exception("Not a Function object"); - auto function = static_cast(this_object); + auto& function = static_cast(*this_object); auto this_arg = interpreter.argument(0); auto arg_array = interpreter.argument(1); if (arg_array.is_null() || arg_array.is_undefined()) @@ -112,7 +112,7 @@ Value FunctionPrototype::call(Interpreter& interpreter) return {}; if (!this_object->is_function()) return interpreter.throw_exception("Not a Function object"); - auto function = static_cast(this_object); + auto& function = static_cast(*this_object); auto this_arg = interpreter.argument(0); MarkedValueList arguments(interpreter.heap()); if (interpreter.argument_count() > 1) { diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index 1be11f70f2..5144e75444 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -359,7 +359,7 @@ Value Object::to_string() const && to_string_property.is_object() && to_string_property.as_object().is_function()) { auto& to_string_function = static_cast(to_string_property.as_object()); - return const_cast(this)->interpreter().call(&to_string_function, const_cast(this)); + return const_cast(this)->interpreter().call(to_string_function, const_cast(this)); } return js_string(heap(), String::format("[object %s]", class_name())); } diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 3f35713458..a7f1871322 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -146,7 +146,7 @@ void Node::dispatch_event(NonnullRefPtr event) auto* event_wrapper = wrap(heap, *event); JS::MarkedValueList arguments(heap); arguments.append(event_wrapper); - document().interpreter().call(&function, this_value, move(arguments)); + document().interpreter().call(function, this_value, move(arguments)); } } diff --git a/Libraries/LibWeb/DOM/Window.cpp b/Libraries/LibWeb/DOM/Window.cpp index 22f307a7c9..adac5c5068 100644 --- a/Libraries/LibWeb/DOM/Window.cpp +++ b/Libraries/LibWeb/DOM/Window.cpp @@ -63,8 +63,8 @@ void Window::set_interval(JS::Function& callback, i32 interval) { // FIXME: This leaks the interval timer and makes it unstoppable. (void)Core::Timer::construct(interval, [handle = make_handle(&callback)] { - auto* function = const_cast(static_cast(handle.cell())); - auto& interpreter = function->interpreter(); + auto& function = const_cast(static_cast(*handle.cell())); + auto& interpreter = function.interpreter(); interpreter.call(function); }).leak_ref(); } @@ -73,8 +73,8 @@ void Window::set_timeout(JS::Function& callback, i32 interval) { // FIXME: This leaks the interval timer and makes it unstoppable. auto& timer = Core::Timer::construct(interval, [handle = make_handle(&callback)] { - auto* function = const_cast(static_cast(handle.cell())); - auto& interpreter = function->interpreter(); + auto& function = const_cast(static_cast(*handle.cell())); + auto& interpreter = function.interpreter(); interpreter.call(function); }).leak_ref(); timer.set_single_shot(true); @@ -86,8 +86,8 @@ i32 Window::request_animation_frame(JS::Function& callback) static double fake_timestamp = 0; i32 link_id = GUI::DisplayLink::register_callback([handle = make_handle(&callback)](i32 link_id) { - auto* function = const_cast(static_cast(handle.cell())); - auto& interpreter = function->interpreter(); + auto& function = const_cast(static_cast(*handle.cell())); + auto& interpreter = function.interpreter(); JS::MarkedValueList arguments(interpreter.heap()); arguments.append(JS::Value(fake_timestamp)); fake_timestamp += 10; diff --git a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp index c19d0c892f..885c56fa26 100644 --- a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp +++ b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp @@ -97,7 +97,7 @@ void XMLHttpRequest::dispatch_event(NonnullRefPtr event) auto* this_value = wrap(heap, *this); JS::MarkedValueList arguments(heap); arguments.append(wrap(heap, *event)); - function.interpreter().call(&function, this_value, move(arguments)); + function.interpreter().call(function, this_value, move(arguments)); } } }