mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
LibJS: Forward a string aproximation of the CallExpression to Call Ops
This gives us better debug output when analysing calls to `undefined` and also fixes multiple test-js cases expecting an `(evaluated from $Expression)` in the error message. This also refactors out the generation of that string, to avoid code duplication with the AST interpreter.
This commit is contained in:
parent
a2ccf31a62
commit
490c097bc4
5 changed files with 42 additions and 17 deletions
|
@ -404,21 +404,25 @@ Completion NewExpression::execute(Interpreter& interpreter) const
|
|||
return Value { TRY(construct(vm, constructor.as_function(), move(arg_list))) };
|
||||
}
|
||||
|
||||
Optional<String> CallExpression::expression_string() const
|
||||
{
|
||||
if (is<Identifier>(*m_callee))
|
||||
return static_cast<Identifier const&>(*m_callee).string();
|
||||
|
||||
if (is<MemberExpression>(*m_callee))
|
||||
return static_cast<MemberExpression const&>(*m_callee).to_string_approximation();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Completion CallExpression::throw_type_error_for_callee(Interpreter& interpreter, Value callee_value, StringView call_type) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
|
||||
if (is<Identifier>(*m_callee) || is<MemberExpression>(*m_callee)) {
|
||||
String expression_string;
|
||||
if (is<Identifier>(*m_callee)) {
|
||||
expression_string = static_cast<Identifier const&>(*m_callee).string();
|
||||
} else {
|
||||
expression_string = static_cast<MemberExpression const&>(*m_callee).to_string_approximation();
|
||||
}
|
||||
return vm.throw_completion<TypeError>(ErrorType::IsNotAEvaluatedFrom, callee_value.to_string_without_side_effects(), call_type, expression_string);
|
||||
} else {
|
||||
return vm.throw_completion<TypeError>(ErrorType::IsNotA, callee_value.to_string_without_side_effects(), call_type);
|
||||
}
|
||||
if (auto expression_string = this->expression_string(); expression_string.has_value())
|
||||
return vm.throw_completion<TypeError>(ErrorType::IsNotAEvaluatedFrom, callee_value.to_string_without_side_effects(), call_type, expression_string.release_value());
|
||||
|
||||
return vm.throw_completion<TypeError>(ErrorType::IsNotA, callee_value.to_string_without_side_effects(), call_type);
|
||||
}
|
||||
|
||||
// 13.3.6.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-function-calls-runtime-semantics-evaluation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue