diff options
author | Linus Groh <mail@linusgroh.de> | 2022-05-02 20:54:39 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-05-03 01:09:29 +0200 |
commit | 9f3f3b0864009b20a9cd02d303aa04b18bdca113 (patch) | |
tree | a9550c3806fac82e345e4a78f520b163b4561ee9 /Userland/Libraries/LibJS/AST.cpp | |
parent | 15f32379bb399e0a8b2928a8de07cd070fb73ee5 (diff) | |
download | serenity-9f3f3b0864009b20a9cd02d303aa04b18bdca113.zip |
LibJS: Remove implicit wrapping/unwrapping of completion records
This is an editorial change in the ECMA-262 spec, with similar changes
in some proposals.
See:
- https://github.com/tc39/ecma262/commit/7575f74
- https://github.com/tc39/proposal-array-grouping/commit/df899eb
- https://github.com/tc39/proposal-shadowrealm/commit/9eb5a12
- https://github.com/tc39/proposal-shadowrealm/commit/c81f527
Diffstat (limited to 'Userland/Libraries/LibJS/AST.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/AST.cpp | 219 |
1 files changed, 109 insertions, 110 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index afe61b6a2a..5bcc92e623 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -105,7 +105,7 @@ Completion ScopeNode::evaluate_statements(Interpreter& interpreter, GlobalObject // BreakableStatement : IterationStatement static Completion labelled_evaluation(Interpreter& interpreter, GlobalObject& global_object, IterationStatement const& statement, Vector<FlyString> const& label_set) { - // 1. Let stmtResult be LoopEvaluation of IterationStatement with argument labelSet. + // 1. Let stmtResult be Completion(LoopEvaluation of IterationStatement with argument labelSet). auto result = statement.loop_evaluation(interpreter, global_object, label_set); // 2. If stmtResult.[[Type]] is break, then @@ -118,7 +118,7 @@ static Completion labelled_evaluation(Interpreter& interpreter, GlobalObject& gl } } - // 3. Return Completion(stmtResult). + // 3. Return ? stmtResult. return result; } @@ -139,7 +139,7 @@ static Completion labelled_evaluation(Interpreter& interpreter, GlobalObject& gl } } - // 3. Return Completion(stmtResult). + // 3. Return ? stmtResult. return result; } @@ -160,7 +160,7 @@ static Completion labelled_evaluation(Interpreter& interpreter, GlobalObject& gl new_label_set->append(label); } - // 3. Let stmtResult be LabelledEvaluation of LabelledItem with argument newLabelSet. + // 3. Let stmtResult be Completion(LabelledEvaluation of LabelledItem with argument newLabelSet). Completion result; if (is<IterationStatement>(labelled_item)) result = labelled_evaluation(interpreter, global_object, static_cast<IterationStatement const&>(labelled_item), *new_label_set); @@ -177,7 +177,7 @@ static Completion labelled_evaluation(Interpreter& interpreter, GlobalObject& gl result = normal_completion(result.value()); } - // 5. Return Completion(stmtResult). + // 5. Return ? stmtResult. return result; } @@ -187,7 +187,7 @@ Completion LabelledStatement::execute(Interpreter& interpreter, GlobalObject& gl InterpreterNodeScope node_scope { interpreter, *this }; // 1. Let newLabelSet be a new empty List. - // 2. Return LabelledEvaluation of this LabelledStatement with argument newLabelSet. + // 2. Return ? LabelledEvaluation of this LabelledStatement with argument newLabelSet. return labelled_evaluation(interpreter, global_object, *this, {}); } @@ -267,12 +267,12 @@ Completion FunctionDeclaration::execute(Interpreter& interpreter, GlobalObject& // iv. Perform ? genv.SetMutableBinding(F, fobj, false). TRY(variable_environment->set_mutable_binding(global_object, name(), function_object, false)); - // v. Return NormalCompletion(empty). - return normal_completion({}); + // v. Return unused. + return Optional<Value> {}; } - // 1. Return NormalCompletion(empty). - return normal_completion({}); + // 1. Return unused. + return Optional<Value> {}; } // 15.2.6 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-function-definitions-runtime-semantics-evaluation @@ -315,8 +315,8 @@ Value FunctionExpression::instantiate_ordinary_function_expression(Interpreter& // 14.4.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-empty-statement-runtime-semantics-evaluation Completion EmptyStatement::execute(Interpreter&, GlobalObject&) const { - // 1. Return NormalCompletion(empty). - return normal_completion({}); + // 1. Return empty. + return Optional<Value> {}; } // 14.5.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-expression-statement-runtime-semantics-evaluation @@ -452,7 +452,7 @@ Completion SuperCall::execute(Interpreter& interpreter, GlobalObject& global_obj // 2. Assert: Type(newTarget) is Object. VERIFY(new_target.is_function()); - // 3. Let func be ! GetSuperConstructor(). + // 3. Let func be GetSuperConstructor(). auto* func = get_super_constructor(interpreter.vm()); // 4. Let argList be ? ArgumentListEvaluation of Arguments. @@ -521,7 +521,7 @@ Completion ReturnStatement::execute(Interpreter& interpreter, GlobalObject& glob auto value = TRY(m_argument->execute(interpreter, global_object)); // NOTE: Generators are not supported in the AST interpreter - // 3. If ! GetGeneratorKind() is async, set exprValue to ? Await(exprValue). + // 3. If GetGeneratorKind() is async, set exprValue to ? Await(exprValue). // 4. Return Completion Record { [[Type]]: return, [[Value]]: exprValue, [[Target]]: empty }. return { Completion::Type::Return, value, {} }; @@ -534,27 +534,27 @@ Completion IfStatement::execute(Interpreter& interpreter, GlobalObject& global_o // IfStatement : if ( Expression ) Statement else Statement // 1. Let exprRef be the result of evaluating Expression. - // 2. Let exprValue be ! ToBoolean(? GetValue(exprRef)). + // 2. Let exprValue be ToBoolean(? GetValue(exprRef)). auto predicate_result = TRY(m_predicate->execute(interpreter, global_object)).release_value(); // 3. If exprValue is true, then if (predicate_result.to_boolean()) { // a. Let stmtCompletion be the result of evaluating the first Statement. - // 5. Return Completion(UpdateEmpty(stmtCompletion, undefined)). + // 5. Return ? UpdateEmpty(stmtCompletion, undefined). return m_consequent->execute(interpreter, global_object).update_empty(js_undefined()); } // 4. Else, if (m_alternate) { // a. Let stmtCompletion be the result of evaluating the second Statement. - // 5. Return Completion(UpdateEmpty(stmtCompletion, undefined)). + // 5. Return ? UpdateEmpty(stmtCompletion, undefined). return m_alternate->execute(interpreter, global_object).update_empty(js_undefined()); } // IfStatement : if ( Expression ) Statement // 3. If exprValue is false, then - // a. Return NormalCompletion(undefined). - return normal_completion(js_undefined()); + // a. Return undefined. + return js_undefined(); } // 14.11.2 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-with-statement-runtime-semantics-evaluation @@ -584,7 +584,7 @@ Completion WithStatement::execute(Interpreter& interpreter, GlobalObject& global // 7. Set the running execution context's LexicalEnvironment to oldEnv. interpreter.vm().running_execution_context().lexical_environment = old_environment; - // 8. Return Completion(UpdateEmpty(C, undefined)). + // 8. Return ? UpdateEmpty(C, undefined). return result.update_empty(js_undefined()); } @@ -616,7 +616,7 @@ static bool loop_continues(Completion const& completion, Vector<FlyString> const Completion WhileStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const { // 1. Let newLabelSet be a new empty List. - // 2. Return the result of performing LabelledEvaluation of this BreakableStatement with argument newLabelSet. + // 2. Return ? LabelledEvaluation of this BreakableStatement with argument newLabelSet. return labelled_evaluation(interpreter, global_object, *this, {}); } @@ -634,14 +634,14 @@ Completion WhileStatement::loop_evaluation(Interpreter& interpreter, GlobalObjec // b. Let exprValue be ? GetValue(exprRef). auto test_result = TRY(m_test->execute(interpreter, global_object)).release_value(); - // c. If ! ToBoolean(exprValue) is false, return NormalCompletion(V). + // c. If ToBoolean(exprValue) is false, return V. if (!test_result.to_boolean()) - return normal_completion(last_value); + return last_value; // d. Let stmtResult be the result of evaluating Statement. auto body_result = m_body->execute(interpreter, global_object); - // e. If LoopContinues(stmtResult, labelSet) is false, return Completion(UpdateEmpty(stmtResult, V)). + // e. If LoopContinues(stmtResult, labelSet) is false, return ? UpdateEmpty(stmtResult, V). if (!loop_continues(body_result, label_set)) return body_result.update_empty(last_value); @@ -658,7 +658,7 @@ Completion WhileStatement::loop_evaluation(Interpreter& interpreter, GlobalObjec Completion DoWhileStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const { // 1. Let newLabelSet be a new empty List. - // 2. Return the result of performing LabelledEvaluation of this BreakableStatement with argument newLabelSet. + // 2. Return ? LabelledEvaluation of this BreakableStatement with argument newLabelSet. return labelled_evaluation(interpreter, global_object, *this, {}); } @@ -675,7 +675,7 @@ Completion DoWhileStatement::loop_evaluation(Interpreter& interpreter, GlobalObj // a. Let stmtResult be the result of evaluating Statement. auto body_result = m_body->execute(interpreter, global_object); - // b. If LoopContinues(stmtResult, labelSet) is false, return Completion(UpdateEmpty(stmtResult, V)). + // b. If LoopContinues(stmtResult, labelSet) is false, return ? UpdateEmpty(stmtResult, V). if (!loop_continues(body_result, label_set)) return body_result.update_empty(last_value); @@ -687,9 +687,9 @@ Completion DoWhileStatement::loop_evaluation(Interpreter& interpreter, GlobalObj // e. Let exprValue be ? GetValue(exprRef). auto test_result = TRY(m_test->execute(interpreter, global_object)).release_value(); - // f. If ! ToBoolean(exprValue) is false, return NormalCompletion(V). + // f. If ToBoolean(exprValue) is false, return V. if (!test_result.to_boolean()) - return normal_completion(last_value); + return last_value; } VERIFY_NOT_REACHED(); @@ -700,7 +700,7 @@ Completion DoWhileStatement::loop_evaluation(Interpreter& interpreter, GlobalObj Completion ForStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const { // 1. Let newLabelSet be a new empty List. - // 2. Return the result of performing LabelledEvaluation of this BreakableStatement with argument newLabelSet. + // 2. Return ? LabelledEvaluation of this BreakableStatement with argument newLabelSet. return labelled_evaluation(interpreter, global_object, *this, {}); } @@ -767,7 +767,7 @@ Completion ForStatement::loop_evaluation(Interpreter& interpreter, GlobalObject& // f. Set the running execution context's LexicalEnvironment to thisIterationEnv. interpreter.vm().running_execution_context().lexical_environment = this_iteration_env; - // 2. Return undefined. + // 2. Return unused. }; // 14.7.4.3 ForBodyEvaluation ( test, increment, stmt, perIterationBindings, labelSet ), https://tc39.es/ecma262/#sec-forbodyevaluation @@ -786,15 +786,15 @@ Completion ForStatement::loop_evaluation(Interpreter& interpreter, GlobalObject& // ii. Let testValue be ? GetValue(testRef). auto test_value = TRY(m_test->execute(interpreter, global_object)).release_value(); - // iii. If ! ToBoolean(testValue) is false, return NormalCompletion(V). + // iii. If ToBoolean(testValue) is false, return V. if (!test_value.to_boolean()) - return normal_completion(last_value); + return last_value; } // b. Let result be the result of evaluating stmt. auto result = m_body->execute(interpreter, global_object); - // c. If LoopContinues(result, labelSet) is false, return Completion(UpdateEmpty(result, V)). + // c. If LoopContinues(result, labelSet) is false, return ? UpdateEmpty(result, V). if (!loop_continues(result, label_set)) return result.update_empty(last_value); @@ -987,7 +987,7 @@ static ThrowCompletionOr<ForInOfHeadState> for_in_of_head_execute(Interpreter& i Completion ForInStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const { // 1. Let newLabelSet be a new empty List. - // 2. Return the result of performing LabelledEvaluation of this BreakableStatement with argument newLabelSet. + // 2. Return ? LabelledEvaluation of this BreakableStatement with argument newLabelSet. return labelled_evaluation(interpreter, global_object, *this, {}); } @@ -1033,7 +1033,7 @@ Completion ForInStatement::loop_evaluation(Interpreter& interpreter, GlobalObjec // n. If LoopContinues(result, labelSet) is false, then if (!loop_continues(result, label_set)) { - // 1. Return Completion(UpdateEmpty(result, V)). + // 1. Return UpdateEmpty(result, V). return result.update_empty(last_value); } @@ -1052,7 +1052,7 @@ Completion ForInStatement::loop_evaluation(Interpreter& interpreter, GlobalObjec Completion ForOfStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const { // 1. Let newLabelSet be a new empty List. - // 2. Return the result of performing LabelledEvaluation of this BreakableStatement with argument newLabelSet. + // 2. Return ? LabelledEvaluation of this BreakableStatement with argument newLabelSet. return labelled_evaluation(interpreter, global_object, *this, {}); } @@ -1106,8 +1106,8 @@ Completion ForOfStatement::loop_evaluation(Interpreter& interpreter, GlobalObjec })); // Return `status` set during step n.2. in the callback, or... - // e. If done is true, return NormalCompletion(V). - return status.value_or(normal_completion(last_value)); + // e. If done is true, return V. + return status.value_or(last_value); } // 14.1.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-statement-semantics-runtime-semantics-evaluation @@ -1115,7 +1115,7 @@ Completion ForOfStatement::loop_evaluation(Interpreter& interpreter, GlobalObjec Completion ForAwaitOfStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const { // 1. Let newLabelSet be a new empty List. - // 2. Return the result of performing LabelledEvaluation of this BreakableStatement with argument newLabelSet. + // 2. Return ? LabelledEvaluation of this BreakableStatement with argument newLabelSet. return labelled_evaluation(interpreter, global_object, *this, {}); } @@ -1164,7 +1164,7 @@ Completion ForAwaitOfStatement::loop_evaluation(Interpreter& interpreter, Global // d. Let done be ? IteratorComplete(nextResult). auto done = TRY(iterator_complete(global_object, next_result.as_object())); - // e. If done is true, return NormalCompletion(V). + // e. If done is true, return V. if (done) return last_value; @@ -1289,7 +1289,7 @@ Completion LogicalExpression::execute(Interpreter& interpreter, GlobalObject& gl switch (m_op) { // LogicalANDExpression : LogicalANDExpression && BitwiseORExpression case LogicalOp::And: - // 3. Let lbool be ! ToBoolean(lval). + // 3. Let lbool be ToBoolean(lval). // 4. If lbool is false, return lval. if (!lhs_result.to_boolean()) return lhs_result; @@ -1300,7 +1300,7 @@ Completion LogicalExpression::execute(Interpreter& interpreter, GlobalObject& gl // LogicalORExpression : LogicalORExpression || LogicalANDExpression case LogicalOp::Or: - // 3. Let lbool be ! ToBoolean(lval). + // 3. Let lbool be ToBoolean(lval). // 4. If lbool is true, return lval. if (lhs_result.to_boolean()) return lhs_result; @@ -1594,7 +1594,7 @@ public: VERIFY(!m_class_field_identifier_name.is_empty()); // 3. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then - // a. Let value be NamedEvaluation of Initializer with argument functionObject.[[ClassFieldInitializerName]]. + // a. Let value be ? NamedEvaluation of Initializer with argument functionObject.[[ClassFieldInitializerName]]. // 4. Else, // a. Let rhs be the result of evaluating AssignmentExpression. // b. Let value be ? GetValue(rhs). @@ -1746,8 +1746,8 @@ Completion ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& glo // 1. Perform ? BindingClassDeclarationEvaluation of this ClassDeclaration. (void)TRY(binding_class_declaration_evaluation(interpreter, global_object, m_class_expression)); - // 2. Return NormalCompletion(empty). - return normal_completion({}); + // 2. Return empty. + return Optional<Value> {}; } // 15.7.14 Runtime Semantics: ClassDefinitionEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-classdefinitionevaluation @@ -2550,7 +2550,7 @@ Completion AssignmentExpression::execute(Interpreter& interpreter, GlobalObject& // c. If IsAnonymousFunctionDefinition(AssignmentExpression) and IsIdentifierRef of LeftHandSideExpression are both true, then if (lhs->is_identifier()) { - // i. Let rval be NamedEvaluation of AssignmentExpression with argument lref.[[ReferencedName]]. + // i. Let rval be ? NamedEvaluation of AssignmentExpression with argument lref.[[ReferencedName]]. auto& identifier_name = static_cast<Identifier const&>(*lhs).string(); rhs_result = TRY(interpreter.vm().named_evaluation_if_anonymous_function(global_object, m_rhs, identifier_name)); } @@ -2594,7 +2594,7 @@ Completion AssignmentExpression::execute(Interpreter& interpreter, GlobalObject& switch (m_op) { // AssignmentExpression : LeftHandSideExpression &&= AssignmentExpression case AssignmentOp::AndAssignment: - // 3. Let lbool be ! ToBoolean(lval). + // 3. Let lbool be ToBoolean(lval). // 4. If lbool is false, return lval. if (!lhs_result.to_boolean()) return lhs_result; @@ -2602,7 +2602,7 @@ Completion AssignmentExpression::execute(Interpreter& interpreter, GlobalObject& // AssignmentExpression : LeftHandSideExpression ||= AssignmentExpression case AssignmentOp::OrAssignment: - // 3. Let lbool be ! ToBoolean(lval). + // 3. Let lbool be ToBoolean(lval). // 4. If lbool is true, return lval. if (lhs_result.to_boolean()) return lhs_result; @@ -2623,7 +2623,7 @@ Completion AssignmentExpression::execute(Interpreter& interpreter, GlobalObject& // 5. If IsAnonymousFunctionDefinition(AssignmentExpression) is true and IsIdentifierRef of LeftHandSideExpression is true, then if (lhs_expression.is_identifier()) { - // a. Let rval be NamedEvaluation of AssignmentExpression with argument lref.[[ReferencedName]]. + // a. Let rval be ? NamedEvaluation of AssignmentExpression with argument lref.[[ReferencedName]]. auto& identifier_name = static_cast<Identifier const&>(lhs_expression).string(); rhs_result = TRY(interpreter.vm().named_evaluation_if_anonymous_function(global_object, m_rhs, identifier_name)); } @@ -2649,7 +2649,7 @@ Completion AssignmentExpression::execute(Interpreter& interpreter, GlobalObject& // 5. Let assignmentOpText be the source text matched by AssignmentOperator. // 6. Let opText be the sequence of Unicode code points associated with assignmentOpText in the following table: - // 7. Let r be ApplyStringOrNumericBinaryOperator(lval, opText, rval). + // 7. Let r be ? ApplyStringOrNumericBinaryOperator(lval, opText, rval). switch (m_op) { case AssignmentOp::AdditionAssignment: rhs_result = TRY(add(global_object, lhs_result, rhs_result)); @@ -2721,26 +2721,26 @@ Completion UpdateExpression::execute(Interpreter& interpreter, GlobalObject& glo case UpdateOp::Increment: // 3. If Type(oldValue) is Number, then if (old_value.is_number()) { - // a. Let newValue be ! Number::add(oldValue, 1𝔽). + // a. Let newValue be Number::add(oldValue, 1𝔽). new_value = Value(old_value.as_double() + 1); } // 4. Else, else { // a. Assert: Type(oldValue) is BigInt. - // b. Let newValue be ! BigInt::add(oldValue, 1ℤ). + // b. Let newValue be BigInt::add(oldValue, 1ℤ). new_value = js_bigint(interpreter.heap(), old_value.as_bigint().big_integer().plus(Crypto::SignedBigInteger { 1 })); } break; case UpdateOp::Decrement: // 3. If Type(oldValue) is Number, then if (old_value.is_number()) { - // a. Let newValue be ! Number::subtract(oldValue, 1𝔽). + // a. Let newValue be Number::subtract(oldValue, 1𝔽). new_value = Value(old_value.as_double() - 1); } // 4. Else, else { // a. Assert: Type(oldValue) is BigInt. - // b. Let newValue be ! BigInt::subtract(oldValue, 1ℤ). + // b. Let newValue be BigInt::subtract(oldValue, 1ℤ). new_value = js_bigint(interpreter.heap(), old_value.as_bigint().big_integer().minus(Crypto::SignedBigInteger { 1 })); } break; @@ -2974,7 +2974,7 @@ Completion ObjectExpression::execute(Interpreter& interpreter, GlobalObject& glo { InterpreterNodeScope node_scope { interpreter, *this }; - // 1. Let obj be ! OrdinaryObjectCreate(%Object.prototype%). + // 1. Let obj be OrdinaryObjectCreate(%Object.prototype%). auto* object = Object::create(global_object, global_object.object_prototype()); // 2. Perform ? PropertyDefinitionEvaluation of PropertyDefinitionList with argument obj. @@ -2983,8 +2983,10 @@ Completion ObjectExpression::execute(Interpreter& interpreter, GlobalObject& glo // PropertyDefinition : ... AssignmentExpression if (property.type() == ObjectProperty::Type::Spread) { - // 4. Return ? CopyDataProperties(object, fromValue, excludedNames). + // 4. Perform ? CopyDataProperties(object, fromValue, excludedNames). TRY(object->copy_data_properties(key, {}, global_object)); + + // 5. Return unused. continue; } @@ -3191,7 +3193,7 @@ Completion MetaProperty::execute(Interpreter& interpreter, GlobalObject& global_ // ImportMeta : import . meta if (m_type == MetaProperty::Type::ImportMeta) { - // 1. Let module be ! GetActiveScriptOrModule(). + // 1. Let module be GetActiveScriptOrModule(). auto script_or_module = interpreter.vm().get_active_script_or_module(); // 2. Assert: module is a Source Text Module Record. @@ -3205,10 +3207,10 @@ Completion MetaProperty::execute(Interpreter& interpreter, GlobalObject& global_ // 4. If importMeta is empty, then if (import_meta == nullptr) { - // a. Set importMeta to ! OrdinaryObjectCreate(null). + // a. Set importMeta to OrdinaryObjectCreate(null). import_meta = Object::create(global_object, nullptr); - // b. Let importMetaValues be ! HostGetImportMetaProperties(module). + // b. Let importMetaValues be HostGetImportMetaProperties(module). auto import_meta_values = interpreter.vm().host_get_import_meta_properties(module); // c. For each Record { [[Key]], [[Value]] } p of importMetaValues, do @@ -3217,7 +3219,7 @@ Completion MetaProperty::execute(Interpreter& interpreter, GlobalObject& global_ MUST(import_meta->create_data_property_or_throw(entry.key, entry.value)); } - // d. Perform ! HostFinalizeImportMeta(importMeta, module). + // d. Perform HostFinalizeImportMeta(importMeta, module). interpreter.vm().host_finalize_import_meta(import_meta, module); // e. Set module.[[ImportMeta]] to importMeta. @@ -3258,7 +3260,7 @@ Completion ImportCall::execute(Interpreter& interpreter, GlobalObject& global_ob InterpreterNodeScope node_scope { interpreter, *this }; // 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ), https://tc39.es/proposal-import-assertions/#sec-evaluate-import-call - // 1. Let referencingScriptOrModule be ! GetActiveScriptOrModule(). + // 1. Let referencingScriptOrModule be GetActiveScriptOrModule(). auto referencing_script_or_module = interpreter.vm().get_active_script_or_module(); // 2. Let specifierRef be the result of evaluating specifierExpression. @@ -3279,7 +3281,7 @@ Completion ImportCall::execute(Interpreter& interpreter, GlobalObject& global_ob // 6. Let promiseCapability be ! NewPromiseCapability(%Promise%). auto promise_capability = MUST(new_promise_capability(global_object, global_object.promise_constructor())); - // 7. Let specifierString be ToString(specifier). + // 7. Let specifierString be Completion(ToString(specifier)). // 8. IfAbruptRejectPromise(specifierString, promiseCapability). auto specifier_string = TRY_OR_REJECT_WITH_VALUE(global_object, promise_capability, specifier->to_string(global_object)); @@ -3353,7 +3355,7 @@ Completion ImportCall::execute(Interpreter& interpreter, GlobalObject& global_ob // 11. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Assertions]]: assertions }. ModuleRequest request { specifier_string, assertions }; - // 12. Perform ! HostImportModuleDynamically(referencingScriptOrModule, moduleRequest, promiseCapability). + // 12. Perform HostImportModuleDynamically(referencingScriptOrModule, moduleRequest, promiseCapability). interpreter.vm().host_import_module_dynamically(referencing_script_or_module, move(request), promise_capability); // 13. Return promiseCapability.[[Promise]]. @@ -3427,13 +3429,13 @@ Completion RegExpLiteral::execute(Interpreter& interpreter, GlobalObject& global { InterpreterNodeScope node_scope { interpreter, *this }; - // 1. Let pattern be ! CodePointsToString(BodyText of RegularExpressionLiteral). + // 1. Let pattern be CodePointsToString(BodyText of RegularExpressionLiteral). auto pattern = this->pattern(); - // 2. Let flags be ! CodePointsToString(FlagText of RegularExpressionLiteral). + // 2. Let flags be CodePointsToString(FlagText of RegularExpressionLiteral). auto flags = this->flags(); - // 3. Return RegExpCreate(pattern, flags). + // 3. Return ! RegExpCreate(pattern, flags). Regex<ECMA262> regex(parsed_regex(), parsed_pattern(), parsed_flags()); return Value { RegExpObject::create(global_object, move(regex), move(pattern), move(flags)) }; } @@ -3459,8 +3461,7 @@ Completion ArrayExpression::execute(Interpreter& interpreter, GlobalObject& glob // 1. Let array be ! ArrayCreate(0). auto* array = MUST(Array::create(global_object, 0)); - // 2. Let len be the result of performing ArrayAccumulation of ElementList with arguments array and 0. - // 3. ReturnIfAbrupt(len). + // 2. Perform ? ArrayAccumulation of ElementList with arguments array and 0. array->indexed_properties(); size_t index = 0; @@ -3480,7 +3481,7 @@ Completion ArrayExpression::execute(Interpreter& interpreter, GlobalObject& glob array->indexed_properties().put(index++, value, default_attributes); } - // 4. Return array. + // 3. Return array. return Value { array }; } @@ -3637,7 +3638,7 @@ Completion TryStatement::execute(Interpreter& interpreter, GlobalObject& global_ // 4. Set the running execution context's LexicalEnvironment to catchEnv. vm.running_execution_context().lexical_environment = catch_environment; - // 5. Let status be BindingInitialization of CatchParameter with arguments thrownValue and catchEnv. + // 5. Let status be Completion(BindingInitialization of CatchParameter with arguments thrownValue and catchEnv). auto status = m_handler->parameter().visit( [&](FlyString const& parameter) { return catch_environment->initialize_binding(global_object, parameter, thrown_value); @@ -3651,7 +3652,7 @@ Completion TryStatement::execute(Interpreter& interpreter, GlobalObject& global_ // a. Set the running execution context's LexicalEnvironment to oldEnv. vm.running_execution_context().lexical_environment = old_environment; - // b. Return Completion(status). + // b. Return ? status. return status.release_error(); } @@ -3661,7 +3662,7 @@ Completion TryStatement::execute(Interpreter& interpreter, GlobalObject& global_ // 8. Set the running execution context's LexicalEnvironment to oldEnv. vm.running_execution_context().lexical_environment = old_environment; - // 9. Return Completion(B). + // 9. Return ? B. return handler_result; }; @@ -3673,7 +3674,7 @@ Completion TryStatement::execute(Interpreter& interpreter, GlobalObject& global_ // TryStatement : try Block Catch // TryStatement : try Block Catch Finally if (m_handler) { - // 2. If B.[[Type]] is throw, let C be CatchClauseEvaluation of Catch with argument B.[[Value]]. + // 2. If B.[[Type]] is throw, let C be Completion(CatchClauseEvaluation of Catch with argument B.[[Value]]). if (block_result.type() == Completion::Type::Throw) result = catch_clause_evaluation(*block_result.value()); // 3. Else, let C be B. @@ -3695,11 +3696,11 @@ Completion TryStatement::execute(Interpreter& interpreter, GlobalObject& global_ if (finalizer_result.type() == Completion::Type::Normal) finalizer_result = move(result); - // 6. Return Completion(UpdateEmpty(F, undefined)). + // 6. Return ? UpdateEmpty(F, undefined). return finalizer_result.update_empty(js_undefined()); } - // 4. Return Completion(UpdateEmpty(C, undefined)). + // 4. Return ? UpdateEmpty(C, undefined). return result.update_empty(js_undefined()); } @@ -3730,7 +3731,7 @@ Completion ThrowStatement::execute(Interpreter& interpreter, GlobalObject& globa Completion SwitchStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const { // 1. Let newLabelSet be a new empty List. - // 2. Return the result of performing LabelledEvaluation of this BreakableStatement with argument newLabelSet. + // 2. Return ? LabelledEvaluation of this BreakableStatement with argument newLabelSet. return labelled_evaluation(interpreter, global_object, *this, {}); } @@ -3757,11 +3758,11 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter, GlobalObject& }; // 14.12.2 Runtime Semantics: CaseBlockEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-caseblockevaluation - auto case_block_evaluation = [&](auto input) { + auto case_block_evaluation = [&](auto input) -> Completion { // CaseBlock : { } if (m_cases.is_empty()) { - // 1. Return NormalCompletion(undefined). - return normal_completion(js_undefined()); + // 1. Return undefined. + return js_undefined(); } NonnullRefPtrVector<SwitchCase> case_clauses_1; @@ -3807,14 +3808,14 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter, GlobalObject& if (result.value().has_value()) last_value = *result.value(); - // iii. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + // iii. If R is an abrupt completion, return ? UpdateEmpty(R, V). if (result.is_abrupt()) return result.update_empty(last_value); } } - // 5. Return NormalCompletion(V). - return normal_completion(last_value); + // 5. Return V. + return last_value; } // CaseBlock : { CaseClauses[opt] DefaultClause CaseClauses[opt] } else { @@ -3847,7 +3848,7 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter, GlobalObject& if (result.value().has_value()) last_value = *result.value(); - // iii. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + // iii. If R is an abrupt completion, return ? UpdateEmpty(R, V). if (result.is_abrupt()) return result.update_empty(last_value); } @@ -3881,16 +3882,16 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter, GlobalObject& if (result.value().has_value()) last_value = *result.value(); - // 3. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + // 3. If R is an abrupt completion, return ? UpdateEmpty(R, V). if (result.is_abrupt()) return result.update_empty(last_value); } } } - // 10. If foundInB is true, return NormalCompletion(V). + // 10. If foundInB is true, return V. if (found_in_b) - return normal_completion(last_value); + return last_value; // 11. Let R be the result of evaluating DefaultClause. auto result = default_clause->evaluate_statements(interpreter, global_object); @@ -3899,7 +3900,7 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter, GlobalObject& if (result.value().has_value()) last_value = *result.value(); - // 13. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + // 13. If R is an abrupt completion, return ? UpdateEmpty(R, V). if (result.is_abrupt()) return result.update_empty(last_value); @@ -3913,13 +3914,13 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter, GlobalObject& if (result.value().has_value()) last_value = *result.value(); - // c. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + // c. If R is an abrupt completion, return ? UpdateEmpty(R, V). if (result.is_abrupt()) return result.update_empty(last_value); } - // 16. Return NormalCompletion(V). - return normal_completion(last_value); + // 16. Return V. + return last_value; } VERIFY_NOT_REACHED(); @@ -3945,7 +3946,7 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter, GlobalObject& vm.running_execution_context().lexical_environment = block_environment; } - // 7. Let R be CaseBlockEvaluation of CaseBlock with argument switchValue. + // 7. Let R be Completion(CaseBlockEvaluation of CaseBlock with argument switchValue). auto result = case_block_evaluation(switch_value); // 8. Set the running execution context's LexicalEnvironment to oldEnv. @@ -4027,7 +4028,7 @@ Completion ConditionalExpression::execute(Interpreter& interpreter, GlobalObject InterpreterNodeScope node_scope { interpreter, *this }; // 1. Let lref be the result of evaluating ShortCircuitExpression. - // 2. Let lval be ! ToBoolean(? GetValue(lref)). + // 2. Let lval be ToBoolean(? GetValue(lref)). auto test_result = TRY(m_test->execute(interpreter, global_object)).release_value(); // 3. If lval is true, then @@ -4091,17 +4092,15 @@ Completion DebuggerStatement::execute(Interpreter& interpreter, GlobalObject&) c // 1. If an implementation-defined debugging facility is available and enabled, then if (false) { // a. Perform an implementation-defined debugging action. - // b. Let result be an implementation-defined Completion value. + // b. Return a new implementation-defined Completion Record. } // 2. Else, else { - // a. Let result be NormalCompletion(empty). - result = normal_completion({}); + // a. Return empty. + return Optional<Value> {}; } - - // 3. Return result. - return result; } + ThrowCompletionOr<void> ScopeNode::for_each_lexically_scoped_declaration(ThrowCompletionOrVoidCallback<Declaration const&>&& callback) const { for (auto& declaration : m_lexical_declarations) @@ -4180,8 +4179,8 @@ Completion ImportStatement::execute(Interpreter& interpreter, GlobalObject&) con { InterpreterNodeScope node_scope { interpreter, *this }; - // 1. Return NormalCompletion(empty). - return normal_completion({}); + // 1. Return empty. + return Optional<Value> {}; } FlyString ExportStatement::local_name_for_default = "*default*"; @@ -4197,8 +4196,8 @@ Completion ExportStatement::execute(Interpreter& interpreter, GlobalObject& glob return m_statement->execute(interpreter, global_object); } - // 1. Return NormalCompletion(empty). - return normal_completion({}); + // 1. Return empty. + return Optional<Value> {}; } VERIFY(m_statement); @@ -4222,8 +4221,8 @@ Completion ExportStatement::execute(Interpreter& interpreter, GlobalObject& glob // Note: We never go into step 3. since a ClassDeclaration always has a name and "*default*" is not a class name. (void)value; - // 4. Return NormalCompletion(empty). - return normal_completion({}); + // 4. Return empty. + return Optional<Value> {}; } // ExportDeclaration : export default ClassDeclaration @@ -4246,8 +4245,8 @@ Completion ExportStatement::execute(Interpreter& interpreter, GlobalObject& glob TRY(initialize_bound_name(global_object, ExportStatement::local_name_for_default, value, env)); } - // 4. Return NormalCompletion(empty). - return normal_completion({}); + // 4. Return empty. + return Optional<Value> {}; } // ExportDeclaration : export default AssignmentExpression ; @@ -4265,8 +4264,8 @@ Completion ExportStatement::execute(Interpreter& interpreter, GlobalObject& glob // 4. Perform ? InitializeBoundName("*default*", value, env). TRY(initialize_bound_name(global_object, ExportStatement::local_name_for_default, value, env)); - // 5. Return NormalCompletion(empty). - return normal_completion({}); + // 5. Return empty. + return Optional<Value> {}; } static void dump_assert_clauses(ModuleRequest const& request) @@ -4516,7 +4515,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& i // ii. Let benv be the running execution context's LexicalEnvironment. // iii. Let fobj be ! benv.GetBindingValue(F, false). // iv. Perform ? genv.SetMutableBinding(F, fobj, false). - // v. Return NormalCompletion(empty). + // v. Return unused. function_declaration.set_should_do_additional_annexB_steps(); return {}; @@ -4566,7 +4565,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& i TRY(global_environment.create_global_var_binding(var_name, false)); } - // 18. Return NormalCompletion(empty). + // 18. Return unused. return {}; } |