mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Move binding_class_declaration_evaluation out of ClassDeclaration
This commit is contained in:
parent
39b134e8c1
commit
232a8432b7
Notes:
sideshowbarker
2024-07-17 20:29:18 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/232a8432b7f Pull-request: https://github.com/SerenityOS/serenity/pull/11957 Reviewed-by: https://github.com/emanuele6 Reviewed-by: https://github.com/linusg
2 changed files with 38 additions and 26 deletions
|
@ -1701,6 +1701,43 @@ Completion ClassExpression::execute(Interpreter& interpreter, GlobalObject& glob
|
|||
return Value { value };
|
||||
}
|
||||
|
||||
// 15.7.15 Runtime Semantics: BindingClassDeclarationEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-bindingclassdeclarationevaluation
|
||||
static ThrowCompletionOr<Value> binding_class_declaration_evaluation(Interpreter& interpreter, GlobalObject& global_object, ClassExpression const& class_expression)
|
||||
{
|
||||
// ClassDeclaration : class ClassTail
|
||||
if (!class_expression.has_name()) {
|
||||
// 1. Let value be ? ClassDefinitionEvaluation of ClassTail with arguments undefined and "default".
|
||||
auto value = TRY(class_expression.class_definition_evaluation(interpreter, global_object, {}, "default"));
|
||||
|
||||
// 2. Set value.[[SourceText]] to the source text matched by ClassDeclaration.
|
||||
value->set_source_text(class_expression.source_text());
|
||||
|
||||
// 3. Return value.
|
||||
return value;
|
||||
}
|
||||
|
||||
// ClassDeclaration : class BindingIdentifier ClassTail
|
||||
|
||||
// 1. Let className be StringValue of BindingIdentifier.
|
||||
auto class_name = class_expression.name();
|
||||
VERIFY(!class_name.is_empty());
|
||||
|
||||
// 2. Let value be ? ClassDefinitionEvaluation of ClassTail with arguments className and className.
|
||||
auto value = TRY(class_expression.class_definition_evaluation(interpreter, global_object, class_name, class_name));
|
||||
|
||||
// 3. Set value.[[SourceText]] to the source text matched by ClassDeclaration.
|
||||
value->set_source_text(class_expression.source_text());
|
||||
|
||||
// 4. Let env be the running execution context's LexicalEnvironment.
|
||||
auto* env = interpreter.lexical_environment();
|
||||
|
||||
// 5. Perform ? InitializeBoundName(className, value, env).
|
||||
TRY(initialize_bound_name(global_object, class_name, value, env));
|
||||
|
||||
// 6. Return value.
|
||||
return value;
|
||||
}
|
||||
|
||||
// 15.7.16 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-class-definitions-runtime-semantics-evaluation
|
||||
// ClassDeclaration : class BindingIdentifier ClassTail
|
||||
Completion ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& global_object) const
|
||||
|
@ -1708,7 +1745,7 @@ Completion ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& glo
|
|||
InterpreterNodeScope node_scope { interpreter, *this };
|
||||
|
||||
// 1. Perform ? BindingClassDeclarationEvaluation of this ClassDeclaration.
|
||||
(void)TRY(binding_class_declaration_evaluation(interpreter, global_object));
|
||||
(void)TRY(binding_class_declaration_evaluation(interpreter, global_object, m_class_expression));
|
||||
|
||||
// 2. Return NormalCompletion(empty).
|
||||
return normal_completion({});
|
||||
|
@ -1879,29 +1916,6 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_e
|
|||
return class_constructor;
|
||||
}
|
||||
|
||||
// 15.7.15 Runtime Semantics: BindingClassDeclarationEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-bindingclassdeclarationevaluation
|
||||
ThrowCompletionOr<Value> ClassDeclaration::binding_class_declaration_evaluation(Interpreter& interpreter, GlobalObject& global_object) const
|
||||
{
|
||||
// 1. Let className be StringValue of BindingIdentifier.
|
||||
auto class_name = m_class_expression->name();
|
||||
VERIFY(!class_name.is_empty());
|
||||
|
||||
// 2. Let value be ? ClassDefinitionEvaluation of ClassTail with arguments className and className.
|
||||
auto* value = TRY(m_class_expression->class_definition_evaluation(interpreter, global_object, class_name, class_name));
|
||||
|
||||
// 3. Set value.[[SourceText]] to the source text matched by ClassDeclaration.
|
||||
value->set_source_text(m_class_expression->source_text());
|
||||
|
||||
// 4. Let env be the running execution context's LexicalEnvironment.
|
||||
auto* env = interpreter.lexical_environment();
|
||||
|
||||
// 5. Perform ? InitializeBoundName(className, value, env).
|
||||
TRY(initialize_bound_name(global_object, class_name, value, env));
|
||||
|
||||
// 6. Return value.
|
||||
return value;
|
||||
}
|
||||
|
||||
void ASTNode::dump(int indent) const
|
||||
{
|
||||
print_indent(indent);
|
||||
|
|
|
@ -1284,8 +1284,6 @@ public:
|
|||
|
||||
StringView name() const { return m_class_expression->name(); }
|
||||
|
||||
ThrowCompletionOr<Value> binding_class_declaration_evaluation(Interpreter& interpreter, GlobalObject& global_object) const;
|
||||
|
||||
private:
|
||||
NonnullRefPtr<ClassExpression> m_class_expression;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue