1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 11:18:13 +00:00

LibJS: Pass JS::Function around by reference more

This commit is contained in:
Andreas Kling 2020-04-29 13:43:57 +02:00
parent 97382677bd
commit aaf35112a4
8 changed files with 22 additions and 22 deletions

View file

@ -195,15 +195,15 @@ void Interpreter::gather_roots(Badge<Heap>, HashTable<Cell*>& roots)
}
}
Value Interpreter::call(Function* function, Value this_value, Optional<MarkedValueList> arguments)
Value Interpreter::call(Function& function, Value this_value, Optional<MarkedValueList> 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;
}

View file

@ -103,7 +103,7 @@ public:
void enter_scope(const ScopeNode&, ArgumentVector, ScopeType);
void exit_scope(const ScopeNode&);
Value call(Function*, Value this_value = {}, Optional<MarkedValueList> arguments = {});
Value call(Function&, Value this_value = {}, Optional<MarkedValueList> arguments = {});
CallFrame& push_call_frame()
{

View file

@ -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 {};

View file

@ -64,7 +64,7 @@ Value FunctionPrototype::apply(Interpreter& interpreter)
return {};
if (!this_object->is_function())
return interpreter.throw_exception<TypeError>("Not a Function object");
auto function = static_cast<Function*>(this_object);
auto& function = static_cast<Function&>(*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<TypeError>("Not a Function object");
auto function = static_cast<Function*>(this_object);
auto& function = static_cast<Function&>(*this_object);
auto this_arg = interpreter.argument(0);
MarkedValueList arguments(interpreter.heap());
if (interpreter.argument_count() > 1) {

View file

@ -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<Function&>(to_string_property.as_object());
return const_cast<Object*>(this)->interpreter().call(&to_string_function, const_cast<Object*>(this));
return const_cast<Object*>(this)->interpreter().call(to_string_function, const_cast<Object*>(this));
}
return js_string(heap(), String::format("[object %s]", class_name()));
}