LibJS: Don't use null DFS for binding_name parameters in ClassExpression

This commit is contained in:
Dan Klishch 2024-01-24 14:55:56 -05:00 committed by Andrew Kaster
parent d558468d03
commit 026c1caba0
3 changed files with 9 additions and 9 deletions

View file

@ -293,7 +293,7 @@ ThrowCompletionOr<ClassElement::ClassValue> StaticInitializer::class_element_eva
return ClassValue { normal_completion(body_function) };
}
ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::create_class_constructor(VM& vm, Environment* class_environment, Environment* environment, Value super_class, DeprecatedFlyString const& binding_name, DeprecatedFlyString const& class_name) const
ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::create_class_constructor(VM& vm, Environment* class_environment, Environment* environment, Value super_class, Optional<DeprecatedFlyString> const& binding_name, DeprecatedFlyString const& class_name) const
{
auto& realm = *vm.current_realm();
@ -421,8 +421,8 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::create_class_const
vm.running_execution_context().lexical_environment = environment;
restore_environment.disarm();
if (!binding_name.is_null())
MUST(class_environment->initialize_binding(vm, binding_name, class_constructor, Environment::InitializeBindingHint::Normal));
if (binding_name.has_value())
MUST(class_environment->initialize_binding(vm, binding_name.value(), class_constructor, Environment::InitializeBindingHint::Normal));
for (auto& field : instance_fields)
class_constructor->add_field(field);
@ -451,7 +451,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::create_class_const
return { class_constructor };
}
ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_evaluation(VM& vm, DeprecatedFlyString const& binding_name, DeprecatedFlyString const& class_name) const
ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_evaluation(VM& vm, Optional<DeprecatedFlyString> const& binding_name, DeprecatedFlyString const& class_name) const
{
auto* environment = vm.lexical_environment();
VERIFY(environment);
@ -459,8 +459,8 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_e
Value super_class;
if (!binding_name.is_null())
MUST(class_environment->create_immutable_binding(vm, binding_name, true));
if (binding_name.has_value())
MUST(class_environment->create_immutable_binding(vm, binding_name.value(), true));
if (!m_super_class.is_null()) {
vm.running_execution_context().lexical_environment = class_environment;

View file

@ -1418,8 +1418,8 @@ public:
bool has_name() const { return m_name; }
ThrowCompletionOr<ECMAScriptFunctionObject*> class_definition_evaluation(VM&, DeprecatedFlyString const& binding_name = {}, DeprecatedFlyString const& class_name = {}) const;
ThrowCompletionOr<ECMAScriptFunctionObject*> create_class_constructor(VM&, Environment* class_environment, Environment* environment, Value super_class, DeprecatedFlyString const& binding_name = {}, DeprecatedFlyString const& class_name = {}) const;
ThrowCompletionOr<ECMAScriptFunctionObject*> class_definition_evaluation(VM&, Optional<DeprecatedFlyString> const& binding_name = {}, DeprecatedFlyString const& class_name = {}) const;
ThrowCompletionOr<ECMAScriptFunctionObject*> create_class_constructor(VM&, Environment* class_environment, Environment* environment, Value super_class, Optional<DeprecatedFlyString> const& binding_name = {}, DeprecatedFlyString const& class_name = {}) const;
private:
virtual bool is_class_expression() const override { return true; }

View file

@ -611,7 +611,7 @@ inline ThrowCompletionOr<ECMAScriptFunctionObject*> new_class(VM& vm, Value supe
auto* class_environment = vm.lexical_environment();
vm.running_execution_context().lexical_environment = interpreter.saved_lexical_environment_stack().take_last();
DeprecatedFlyString binding_name;
Optional<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());