summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/AST.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibJS/AST.cpp')
-rw-r--r--Userland/Libraries/LibJS/AST.cpp130
1 files changed, 65 insertions, 65 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp
index 2c662597b8..641f0f8eaa 100644
--- a/Userland/Libraries/LibJS/AST.cpp
+++ b/Userland/Libraries/LibJS/AST.cpp
@@ -107,7 +107,7 @@ Completion ScopeNode::evaluate_statements(Interpreter& interpreter) const
{
auto completion = normal_completion({});
for (auto const& node : children()) {
- completion = node.execute(interpreter).update_empty(completion.value());
+ completion = node->execute(interpreter).update_empty(completion.value());
if (completion.is_abrupt())
break;
}
@@ -958,12 +958,12 @@ struct ForInOfHeadState {
VERIFY(expression_lhs);
if (is<VariableDeclaration>(*expression_lhs)) {
auto& declaration = static_cast<VariableDeclaration const&>(*expression_lhs);
- VERIFY(declaration.declarations().first().target().has<NonnullRefPtr<Identifier const>>());
- lhs_reference = TRY(declaration.declarations().first().target().get<NonnullRefPtr<Identifier const>>()->to_reference(interpreter));
+ VERIFY(declaration.declarations().first()->target().has<NonnullRefPtr<Identifier const>>());
+ lhs_reference = TRY(declaration.declarations().first()->target().get<NonnullRefPtr<Identifier const>>()->to_reference(interpreter));
} else if (is<UsingDeclaration>(*expression_lhs)) {
auto& declaration = static_cast<UsingDeclaration const&>(*expression_lhs);
- VERIFY(declaration.declarations().first().target().has<NonnullRefPtr<Identifier const>>());
- lhs_reference = TRY(declaration.declarations().first().target().get<NonnullRefPtr<Identifier const>>()->to_reference(interpreter));
+ VERIFY(declaration.declarations().first()->target().has<NonnullRefPtr<Identifier const>>());
+ lhs_reference = TRY(declaration.declarations().first()->target().get<NonnullRefPtr<Identifier const>>()->to_reference(interpreter));
} else {
VERIFY(is<Identifier>(*expression_lhs) || is<MemberExpression>(*expression_lhs) || is<CallExpression>(*expression_lhs));
auto& expression = static_cast<Expression const&>(*expression_lhs);
@@ -1032,7 +1032,7 @@ struct ForInOfHeadState {
}
VERIFY(expression_lhs && is<VariableDeclaration>(*expression_lhs));
auto& for_declaration = static_cast<VariableDeclaration const&>(*expression_lhs);
- auto& binding_pattern = for_declaration.declarations().first().target().get<NonnullRefPtr<BindingPattern const>>();
+ auto& binding_pattern = for_declaration.declarations().first()->target().get<NonnullRefPtr<BindingPattern const>>();
VERIFY(lhs_kind == VarBinding || iteration_environment);
// At this point iteration_environment is undefined if lhs_kind == VarBinding which means this does both
@@ -1063,16 +1063,16 @@ static ThrowCompletionOr<ForInOfHeadState> for_in_of_head_execute(Interpreter& i
if (is<VariableDeclaration>(ast_ptr->ptr())) {
auto& variable_declaration = static_cast<VariableDeclaration const&>(*(*ast_ptr));
VERIFY(variable_declaration.declarations().size() == 1);
- state.destructuring = variable_declaration.declarations().first().target().has<NonnullRefPtr<BindingPattern const>>();
+ state.destructuring = variable_declaration.declarations().first()->target().has<NonnullRefPtr<BindingPattern const>>();
if (variable_declaration.declaration_kind() == DeclarationKind::Var) {
state.lhs_kind = ForInOfHeadState::VarBinding;
auto& variable = variable_declaration.declarations().first();
// B.3.5 Initializers in ForIn Statement Heads, https://tc39.es/ecma262/#sec-initializers-in-forin-statement-heads
- if (variable.init()) {
- VERIFY(variable.target().has<NonnullRefPtr<Identifier const>>());
- auto& binding_id = variable.target().get<NonnullRefPtr<Identifier const>>()->string();
+ if (variable->init()) {
+ VERIFY(variable->target().has<NonnullRefPtr<Identifier const>>());
+ auto& binding_id = variable->target().get<NonnullRefPtr<Identifier const>>()->string();
auto reference = TRY(interpreter.vm().resolve_binding(binding_id));
- auto result = TRY(interpreter.vm().named_evaluation_if_anonymous_function(*variable.init(), binding_id));
+ auto result = TRY(interpreter.vm().named_evaluation_if_anonymous_function(*variable->init(), binding_id));
TRY(reference.put_value(vm, result));
}
} else {
@@ -1950,7 +1950,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_e
auto class_private_environment = new_private_environment(vm, outer_private_environment);
for (auto const& element : m_elements) {
- auto opt_private_name = element.private_bound_identifier();
+ auto opt_private_name = element->private_bound_identifier();
if (opt_private_name.has_value())
class_private_environment->add_private_name({}, opt_private_name.release_value());
}
@@ -2026,10 +2026,10 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_e
for (auto const& element : m_elements) {
// Note: All ClassElementEvaluation start with evaluating the name (or we fake it).
- auto element_value = TRY(element.class_element_evaluation(interpreter, element.is_static() ? *class_constructor : *prototype));
+ auto element_value = TRY(element->class_element_evaluation(interpreter, element->is_static() ? *class_constructor : *prototype));
if (element_value.has<PrivateElement>()) {
- auto& container = element.is_static() ? static_private_methods : instance_private_methods;
+ auto& container = element->is_static() ? static_private_methods : instance_private_methods;
auto& private_element = element_value.get<PrivateElement>();
@@ -2051,11 +2051,11 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_e
if (!added_to_existing)
container.append(move(element_value.get<PrivateElement>()));
} else if (auto* class_field_definition_ptr = element_value.get_pointer<ClassFieldDefinition>()) {
- if (element.is_static())
+ if (element->is_static())
static_elements.append(move(*class_field_definition_ptr));
else
instance_fields.append(move(*class_field_definition_ptr));
- } else if (element.class_element_kind() == ClassElement::ElementKind::StaticInitializer) {
+ } else if (element->class_element_kind() == ClassElement::ElementKind::StaticInitializer) {
// We use Completion to hold the ClassStaticBlockDefinition Record.
VERIFY(element_value.has<Completion>() && element_value.get<Completion>().value().has_value());
auto& element_object = element_value.get<Completion>().value()->as_object();
@@ -2108,28 +2108,28 @@ void ScopeNode::dump(int indent) const
print_indent(indent + 1);
outln("(Lexical declarations)");
for (auto& declaration : m_lexical_declarations)
- declaration.dump(indent + 2);
+ declaration->dump(indent + 2);
}
if (!m_var_declarations.is_empty()) {
print_indent(indent + 1);
outln("(Variable declarations)");
for (auto& declaration : m_var_declarations)
- declaration.dump(indent + 2);
+ declaration->dump(indent + 2);
}
if (!m_functions_hoistable_with_annexB_extension.is_empty()) {
print_indent(indent + 1);
outln("(Hoisted functions via annexB extension)");
for (auto& declaration : m_functions_hoistable_with_annexB_extension)
- declaration.dump(indent + 2);
+ declaration->dump(indent + 2);
}
if (!m_children.is_empty()) {
print_indent(indent + 1);
outln("(Children)");
for (auto& child : children())
- child.dump(indent + 2);
+ child->dump(indent + 2);
}
}
@@ -2322,7 +2322,7 @@ void ClassExpression::dump(int indent) const
print_indent(indent);
outln("(Elements)");
for (auto& method : m_elements)
- method.dump(indent + 1);
+ method->dump(indent + 1);
}
void ClassMethod::dump(int indent) const
@@ -3033,8 +3033,8 @@ Completion VariableDeclaration::execute(Interpreter& interpreter) const
auto& vm = interpreter.vm();
for (auto& declarator : m_declarations) {
- if (auto* init = declarator.init()) {
- TRY(declarator.target().visit(
+ if (auto* init = declarator->init()) {
+ TRY(declarator->target().visit(
[&](NonnullRefPtr<Identifier const> const& id) -> ThrowCompletionOr<void> {
auto reference = TRY(id->to_reference(interpreter));
auto initializer_result = TRY(interpreter.vm().named_evaluation_if_anonymous_function(*init, id->string()));
@@ -3053,8 +3053,8 @@ Completion VariableDeclaration::execute(Interpreter& interpreter) const
return vm.binding_initialization(pattern, initializer_result, environment);
}));
} else if (m_declaration_kind != DeclarationKind::Var) {
- VERIFY(declarator.target().has<NonnullRefPtr<Identifier const>>());
- auto& identifier = declarator.target().get<NonnullRefPtr<Identifier const>>();
+ VERIFY(declarator->target().has<NonnullRefPtr<Identifier const>>());
+ auto& identifier = declarator->target().get<NonnullRefPtr<Identifier const>>();
auto reference = TRY(identifier->to_reference(interpreter));
TRY(reference.initialize_referenced_binding(vm, js_undefined()));
}
@@ -3073,7 +3073,7 @@ Completion VariableDeclarator::execute(Interpreter& interpreter) const
ThrowCompletionOr<void> VariableDeclaration::for_each_bound_name(ThrowCompletionOrVoidCallback<DeprecatedFlyString const&>&& callback) const
{
for (auto const& entry : declarations()) {
- TRY(entry.target().visit(
+ TRY(entry->target().visit(
[&](NonnullRefPtr<Identifier const> const& id) {
return callback(id->string());
},
@@ -3107,7 +3107,7 @@ void VariableDeclaration::dump(int indent) const
outln("{}", declaration_kind_string);
for (auto& declarator : m_declarations)
- declarator.dump(indent + 1);
+ declarator->dump(indent + 1);
}
// 6.2.1.2 Runtime Semantics: Evaluation, https://tc39.es/proposal-explicit-resource-management/#sec-let-and-const-declarations-runtime-semantics-evaluation
@@ -3118,14 +3118,14 @@ Completion UsingDeclaration::execute(Interpreter& interpreter) const
auto& vm = interpreter.vm();
for (auto& declarator : m_declarations) {
- VERIFY(declarator.target().has<NonnullRefPtr<Identifier const>>());
- VERIFY(declarator.init());
+ VERIFY(declarator->target().has<NonnullRefPtr<Identifier const>>());
+ VERIFY(declarator->init());
- auto& id = declarator.target().get<NonnullRefPtr<Identifier const>>();
+ auto& id = declarator->target().get<NonnullRefPtr<Identifier const>>();
// 2. ReturnIfAbrupt(next).
auto reference = TRY(id->to_reference(interpreter));
- auto initializer_result = TRY(interpreter.vm().named_evaluation_if_anonymous_function(*declarator.init(), id->string()));
+ auto initializer_result = TRY(interpreter.vm().named_evaluation_if_anonymous_function(*declarator->init(), id->string()));
VERIFY(!initializer_result.is_empty());
TRY(reference.initialize_referenced_binding(vm, initializer_result, Environment::InitializeBindingHint::SyncDispose));
}
@@ -3137,8 +3137,8 @@ Completion UsingDeclaration::execute(Interpreter& interpreter) const
ThrowCompletionOr<void> UsingDeclaration::for_each_bound_name(ThrowCompletionOrVoidCallback<DeprecatedFlyString const&>&& callback) const
{
for (auto const& entry : m_declarations) {
- VERIFY(entry.target().has<NonnullRefPtr<Identifier const>>());
- TRY(callback(entry.target().get<NonnullRefPtr<Identifier const>>()->string()));
+ VERIFY(entry->target().has<NonnullRefPtr<Identifier const>>());
+ TRY(callback(entry->target().get<NonnullRefPtr<Identifier const>>()->string()));
}
return {};
@@ -3149,7 +3149,7 @@ void UsingDeclaration::dump(int indent) const
ASTNode::dump(indent);
print_indent(indent + 1);
for (auto& declarator : m_declarations)
- declarator.dump(indent + 1);
+ declarator->dump(indent + 1);
}
void VariableDeclarator::dump(int indent) const
@@ -3178,7 +3178,7 @@ void ObjectExpression::dump(int indent) const
{
ASTNode::dump(indent);
for (auto& property : m_properties) {
- property.dump(indent + 1);
+ property->dump(indent + 1);
}
}
@@ -3208,10 +3208,10 @@ Completion ObjectExpression::execute(Interpreter& interpreter) const
// 2. Perform ? PropertyDefinitionEvaluation of PropertyDefinitionList with argument obj.
for (auto& property : m_properties) {
- auto key = TRY(property.key().execute(interpreter)).release_value();
+ auto key = TRY(property->key().execute(interpreter)).release_value();
// PropertyDefinition : ... AssignmentExpression
- if (property.type() == ObjectProperty::Type::Spread) {
+ if (property->type() == ObjectProperty::Type::Spread) {
// 4. Perform ? CopyDataProperties(object, fromValue, excludedNames).
TRY(object->copy_data_properties(vm, key, {}));
@@ -3219,10 +3219,10 @@ Completion ObjectExpression::execute(Interpreter& interpreter) const
continue;
}
- auto value = TRY(property.value().execute(interpreter)).release_value();
+ auto value = TRY(property->value().execute(interpreter)).release_value();
// 8. If isProtoSetter is true, then
- if (property.type() == ObjectProperty::Type::ProtoSetter) {
+ if (property->type() == ObjectProperty::Type::ProtoSetter) {
// a. If Type(propValue) is either Object or Null, then
if (value.is_object() || value.is_null()) {
// i. Perform ! object.[[SetPrototypeOf]](propValue).
@@ -3234,21 +3234,21 @@ Completion ObjectExpression::execute(Interpreter& interpreter) const
auto property_key = TRY(PropertyKey::from_value(vm, key));
- if (property.is_method()) {
+ if (property->is_method()) {
VERIFY(value.is_function());
static_cast<ECMAScriptFunctionObject&>(value.as_function()).set_home_object(object);
auto name = MUST(get_function_property_name(property_key));
- if (property.type() == ObjectProperty::Type::Getter) {
+ if (property->type() == ObjectProperty::Type::Getter) {
name = DeprecatedString::formatted("get {}", name);
- } else if (property.type() == ObjectProperty::Type::Setter) {
+ } else if (property->type() == ObjectProperty::Type::Setter) {
name = DeprecatedString::formatted("set {}", name);
}
update_function_name(value, name);
}
- switch (property.type()) {
+ switch (property->type()) {
case ObjectProperty::Type::Getter:
VERIFY(value.is_function());
object->define_direct_accessor(property_key, &value.as_function(), nullptr, Attribute::Configurable | Attribute::Enumerable);
@@ -3741,7 +3741,7 @@ void TemplateLiteral::dump(int indent) const
{
ASTNode::dump(indent);
for (auto& expression : m_expressions)
- expression.dump(indent + 1);
+ expression->dump(indent + 1);
}
// 13.2.8.5 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-template-literals-runtime-semantics-evaluation
@@ -3757,7 +3757,7 @@ Completion TemplateLiteral::execute(Interpreter& interpreter) const
// 2. Let subRef be the result of evaluating Expression.
// 3. Let sub be ? GetValue(subRef).
- auto sub = TRY(expression.execute(interpreter)).release_value();
+ auto sub = TRY(expression->execute(interpreter)).release_value();
// 4. Let middle be ? ToString(sub).
auto string = TRY(sub.to_deprecated_string(vm));
@@ -3835,7 +3835,7 @@ Completion TaggedTemplateLiteral::execute(Interpreter& interpreter) const
// tag`foo${bar}baz${qux}` -> "foo", bar, "baz", qux, "" -> tag(["foo", "baz", ""], bar, qux)
// So we want all the odd expressions
for (size_t i = 1; i < expressions.size(); i += 2)
- arguments.append(TRY(expressions[i].execute(interpreter)).release_value());
+ arguments.append(TRY(expressions[i]->execute(interpreter)).release_value());
// 5. Return ? EvaluateCall(tagFunc, tagRef, TemplateLiteral, tailCall).
return call(vm, tag, tag_this_value, move(arguments));
@@ -3887,7 +3887,7 @@ ThrowCompletionOr<Value> TaggedTemplateLiteral::get_template_object(Interpreter&
auto cooked_string_index = i * 2;
// a. Let prop be ! ToString(𝔽(index)).
// b. Let cookedValue be cookedStrings[index].
- auto cooked_value = TRY(expressions[cooked_string_index].execute(interpreter)).release_value();
+ auto cooked_value = TRY(expressions[cooked_string_index]->execute(interpreter)).release_value();
// NOTE: If the string contains invalid escapes we get a null expression here,
// which we then convert to the expected `undefined` TV. See
@@ -3900,7 +3900,7 @@ ThrowCompletionOr<Value> TaggedTemplateLiteral::get_template_object(Interpreter&
// d. Let rawValue be the String value rawStrings[index].
// e. Perform ! DefinePropertyOrThrow(rawObj, prop, PropertyDescriptor { [[Value]]: rawValue, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false }).
- raw_obj->indexed_properties().append(TRY(raw_strings[i].execute(interpreter)).release_value());
+ raw_obj->indexed_properties().append(TRY(raw_strings[i]->execute(interpreter)).release_value());
// f. Set index to index + 1.
}
@@ -4108,11 +4108,11 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter) const
// 14.12.3 CaseClauseIsSelected ( C, input ), https://tc39.es/ecma262/#sec-runtime-semantics-caseclauseisselected
auto case_clause_is_selected = [&](auto const& case_clause, auto input) -> ThrowCompletionOr<bool> {
// 1. Assert: C is an instance of the production CaseClause : case Expression : StatementList[opt] .
- VERIFY(case_clause.test());
+ VERIFY(case_clause->test());
// 2. Let exprRef be the result of evaluating the Expression of C.
// 3. Let clauseSelector be ? GetValue(exprRef).
- auto clause_selector = TRY(case_clause.test()->execute(interpreter)).release_value();
+ auto clause_selector = TRY(case_clause->test()->execute(interpreter)).release_value();
// 4. Return IsStrictlyEqual(input, clauseSelector).
return is_strictly_equal(input, clause_selector);
@@ -4126,11 +4126,11 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter) const
return js_undefined();
}
- NonnullRefPtrVector<SwitchCase const> case_clauses_1;
- NonnullRefPtrVector<SwitchCase const> case_clauses_2;
+ Vector<NonnullRefPtr<SwitchCase const>> case_clauses_1;
+ Vector<NonnullRefPtr<SwitchCase const>> case_clauses_2;
RefPtr<SwitchCase const> default_clause;
for (auto const& switch_case : m_cases) {
- if (!switch_case.test())
+ if (!switch_case->test())
default_clause = switch_case;
else if (!default_clause)
case_clauses_1.append(switch_case);
@@ -4163,7 +4163,7 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter) const
// b. If found is true, then
if (found) {
// i. Let R be the result of evaluating C.
- auto result = case_clause.evaluate_statements(interpreter);
+ auto result = case_clause->evaluate_statements(interpreter);
// ii. If R.[[Value]] is not empty, set V to R.[[Value]].
if (result.value().has_value())
@@ -4203,7 +4203,7 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter) const
// b. If found is true, then
if (found) {
// i. Let R be the result of evaluating C.
- auto result = case_clause.evaluate_statements(interpreter);
+ auto result = case_clause->evaluate_statements(interpreter);
// ii. If R.[[Value]] is not empty, set V to R.[[Value]].
if (result.value().has_value())
@@ -4237,7 +4237,7 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter) const
// ii. If foundInB is true, then
if (found_in_b) {
// 1. Let R be the result of evaluating CaseClause C.
- auto result = case_clause.evaluate_statements(interpreter);
+ auto result = case_clause->evaluate_statements(interpreter);
// 2. If R.[[Value]] is not empty, set V to R.[[Value]].
if (result.value().has_value())
@@ -4269,7 +4269,7 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter) const
// 15. For each CaseClause C of B, do
for (auto const& case_clause : case_clauses_2) {
// a. Let R be the result of evaluating CaseClause C.
- result = case_clause.evaluate_statements(interpreter);
+ result = case_clause->evaluate_statements(interpreter);
// b. If R.[[Value]] is not empty, set V to R.[[Value]].
if (result.value().has_value())
@@ -4375,7 +4375,7 @@ void SwitchStatement::dump(int indent) const
ASTNode::dump(indent);
m_discriminant->dump(indent + 1);
for (auto& switch_case : m_cases) {
- switch_case.dump(indent + 1);
+ switch_case->dump(indent + 1);
}
}
@@ -4434,7 +4434,7 @@ void SequenceExpression::dump(int indent) const
{
ASTNode::dump(indent);
for (auto& expression : m_expressions)
- expression.dump(indent + 1);
+ expression->dump(indent + 1);
}
// 13.16.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-comma-operator-runtime-semantics-evaluation
@@ -4449,7 +4449,7 @@ Completion SequenceExpression::execute(Interpreter& interpreter) const
// 4. Return ? GetValue(rref).
Value last_value;
for (auto const& expression : m_expressions)
- last_value = TRY(expression.execute(interpreter)).release_value();
+ last_value = TRY(expression->execute(interpreter)).release_value();
return { move(last_value) };
}
@@ -4484,7 +4484,7 @@ ThrowCompletionOr<void> ScopeNode::for_each_lexically_scoped_declaration(ThrowCo
ThrowCompletionOr<void> ScopeNode::for_each_lexically_declared_name(ThrowCompletionOrVoidCallback<DeprecatedFlyString const&>&& callback) const
{
for (auto const& declaration : m_lexical_declarations) {
- TRY(declaration.for_each_bound_name([&](auto const& name) {
+ TRY(declaration->for_each_bound_name([&](auto const& name) {
return callback(name);
}));
}
@@ -4494,7 +4494,7 @@ ThrowCompletionOr<void> ScopeNode::for_each_lexically_declared_name(ThrowComplet
ThrowCompletionOr<void> ScopeNode::for_each_var_declared_name(ThrowCompletionOrVoidCallback<DeprecatedFlyString const&>&& callback) const
{
for (auto& declaration : m_var_declarations) {
- TRY(declaration.for_each_bound_name([&](auto const& name) {
+ TRY(declaration->for_each_bound_name([&](auto const& name) {
return callback(name);
}));
}
@@ -4506,7 +4506,7 @@ ThrowCompletionOr<void> ScopeNode::for_each_var_function_declaration_in_reverse_
for (ssize_t i = m_var_declarations.size() - 1; i >= 0; i--) {
auto& declaration = m_var_declarations[i];
if (is<FunctionDeclaration>(declaration))
- TRY(callback(static_cast<FunctionDeclaration const&>(declaration)));
+ TRY(callback(static_cast<FunctionDeclaration const&>(*declaration)));
}
return {};
}
@@ -4516,7 +4516,7 @@ ThrowCompletionOr<void> ScopeNode::for_each_var_scoped_variable_declaration(Thro
for (auto& declaration : m_var_declarations) {
if (!is<FunctionDeclaration>(declaration)) {
VERIFY(is<VariableDeclaration>(declaration));
- TRY(callback(static_cast<VariableDeclaration const&>(declaration)));
+ TRY(callback(static_cast<VariableDeclaration const&>(*declaration)));
}
}
return {};
@@ -4526,7 +4526,7 @@ ThrowCompletionOr<void> ScopeNode::for_each_function_hoistable_with_annexB_exten
{
for (auto& function : m_functions_hoistable_with_annexB_extension) {
// We need const_cast here since it might have to set a property on function declaration.
- TRY(callback(const_cast<FunctionDeclaration&>(function)));
+ TRY(callback(const_cast<FunctionDeclaration&>(*function)));
}
return {};
}