|
@@ -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));
|
|
|
+}
|
|
|
+
|
|
|
}
|