1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 10:04:59 +00:00

LibJS/Bytecode: Move NewClass impl to CommonImplementations

This commit is contained in:
Simon Wanner 2023-10-29 02:40:55 +02:00 committed by Andreas Kling
parent ddce5e03c2
commit f9fbb8cff2
3 changed files with 24 additions and 19 deletions

View file

@ -449,4 +449,26 @@ ThrowCompletionOr<void> create_variable(VM& vm, DeprecatedFlyString const& name,
return verify_cast<GlobalEnvironment>(vm.variable_environment())->create_global_var_binding(name, false);
}
ThrowCompletionOr<ECMAScriptFunctionObject*> new_class(VM& vm, ClassExpression const& class_expression, Optional<IdentifierTableIndex> const& lhs_name)
{
auto& interpreter = vm.bytecode_interpreter();
auto name = class_expression.name();
auto super_class = interpreter.accumulator();
// NOTE: NewClass expects classEnv to be active lexical environment
auto* class_environment = vm.lexical_environment();
vm.running_execution_context().lexical_environment = interpreter.saved_lexical_environment_stack().take_last();
DeprecatedFlyString binding_name;
DeprecatedFlyString class_name;
if (!class_expression.has_name() && lhs_name.has_value()) {
class_name = interpreter.current_executable().get_identifier(lhs_name.value());
} else {
binding_name = name;
class_name = name.is_null() ? ""sv : name;
}
return TRY(class_expression.create_class_constructor(vm, class_environment, vm.lexical_environment(), super_class, binding_name, class_name));
}
}