mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 20:25:07 +00:00
LibJS: Set name of anonymous functions during assignment
This commit is contained in:
parent
5e66f1900b
commit
25cf0da2fb
3 changed files with 56 additions and 6 deletions
|
@ -46,6 +46,23 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
static void update_function_name(Value& value, const FlyString& name)
|
||||
{
|
||||
if (!value.is_object())
|
||||
return;
|
||||
auto& object = value.as_object();
|
||||
if (object.is_function()) {
|
||||
auto& function = static_cast<ScriptFunction&>(object);
|
||||
if (function.name().is_empty())
|
||||
function.set_name(name);
|
||||
} else if (object.is_array()) {
|
||||
auto& array = static_cast<Array&>(object);
|
||||
for (size_t i = 0; i < array.elements().size(); ++i) {
|
||||
update_function_name(array.elements()[i], name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Value ScopeNode::execute(Interpreter& interpreter) const
|
||||
{
|
||||
return interpreter.run(*this);
|
||||
|
@ -861,6 +878,7 @@ Value AssignmentExpression::execute(Interpreter& interpreter) const
|
|||
if (reference.is_unresolvable())
|
||||
return interpreter.throw_exception<ReferenceError>("Invalid left-hand side in assignment");
|
||||
|
||||
update_function_name(rhs_result, reference.name().as_string());
|
||||
reference.put(interpreter, rhs_result);
|
||||
|
||||
if (interpreter.exception())
|
||||
|
@ -965,7 +983,9 @@ Value VariableDeclaration::execute(Interpreter& interpreter) const
|
|||
auto initalizer_result = init->execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
interpreter.set_variable(declarator.id().string(), initalizer_result, true);
|
||||
auto variable_name = declarator.id().string();
|
||||
update_function_name(initalizer_result, variable_name);
|
||||
interpreter.set_variable(variable_name, initalizer_result, true);
|
||||
}
|
||||
}
|
||||
return js_undefined();
|
||||
|
@ -1075,6 +1095,7 @@ Value ObjectExpression::execute(Interpreter& interpreter) const
|
|||
auto value = property.value().execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
update_function_name(value, key);
|
||||
object->put(key, value);
|
||||
}
|
||||
return object;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue