1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 14:25:08 +00:00

LibJS: Add Value::{is, as}_function()

This commit is contained in:
Linus Groh 2020-05-06 11:52:53 +01:00 committed by Andreas Kling
parent 419bce6915
commit eea62dd365
6 changed files with 26 additions and 15 deletions

View file

@ -114,8 +114,7 @@ Value CallExpression::execute(Interpreter& interpreter) const
ASSERT(!callee.is_empty());
if (!callee.is_object()
|| !callee.as_object().is_function()
if (!callee.is_function()
|| (is_new_expression() && (callee.as_object().is_native_function() && !static_cast<NativeFunction&>(callee.as_object()).has_constructor()))) {
String error_message;
auto call_type = is_new_expression() ? "constructor" : "function";
@ -132,7 +131,7 @@ Value CallExpression::execute(Interpreter& interpreter) const
return interpreter.throw_exception<TypeError>(error_message);
}
auto& function = static_cast<Function&>(callee.as_object());
auto& function = callee.as_function();
MarkedValueList arguments(interpreter.heap());
arguments.values().append(function.bound_arguments());
@ -469,7 +468,7 @@ Value UnaryExpression::execute(Interpreter& interpreter) const
case Value::Type::String:
return js_string(interpreter, "string");
case Value::Type::Object:
if (lhs_result.as_object().is_function())
if (lhs_result.is_function())
return js_string(interpreter, "function");
return js_string(interpreter, "object");
case Value::Type::Boolean: