13af6ab5fSopenharmony_ci/* 23af6ab5fSopenharmony_ci * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_ci#include "functionBuilder.h" 173af6ab5fSopenharmony_ci 183af6ab5fSopenharmony_ci#include "varbinder/varbinder.h" 193af6ab5fSopenharmony_ci#include "util/helpers.h" 203af6ab5fSopenharmony_ci#include "ir/statement.h" 213af6ab5fSopenharmony_ci#include "ir/base/scriptFunction.h" 223af6ab5fSopenharmony_ci#include "compiler/base/iterators.h" 233af6ab5fSopenharmony_ci#include "compiler/core/pandagen.h" 243af6ab5fSopenharmony_ci 253af6ab5fSopenharmony_cinamespace ark::es2panda::compiler { 263af6ab5fSopenharmony_ciFunctionBuilder::FunctionBuilder(PandaGen *pg, CatchTable *catchTable) 273af6ab5fSopenharmony_ci : pg_(pg), catchTable_(catchTable), funcObj_(catchTable != nullptr ? pg_->AllocReg() : VReg(VReg::REG_START)) 283af6ab5fSopenharmony_ci{ 293af6ab5fSopenharmony_ci} 303af6ab5fSopenharmony_ci 313af6ab5fSopenharmony_ciIteratorType FunctionBuilder::GeneratorKind() const 323af6ab5fSopenharmony_ci{ 333af6ab5fSopenharmony_ci return IteratorType::SYNC; 343af6ab5fSopenharmony_ci} 353af6ab5fSopenharmony_ci 363af6ab5fSopenharmony_civoid FunctionBuilder::DirectReturn(const ir::AstNode *node) const 373af6ab5fSopenharmony_ci{ 383af6ab5fSopenharmony_ci pg_->EmitReturn(node); 393af6ab5fSopenharmony_ci} 403af6ab5fSopenharmony_ci 413af6ab5fSopenharmony_civoid FunctionBuilder::ImplicitReturn(const ir::AstNode *node) const 423af6ab5fSopenharmony_ci{ 433af6ab5fSopenharmony_ci const auto *rootNode = pg_->RootNode(); 443af6ab5fSopenharmony_ci 453af6ab5fSopenharmony_ci if (!rootNode->IsScriptFunction() || !rootNode->AsScriptFunction()->IsConstructor()) { 463af6ab5fSopenharmony_ci pg_->EmitReturnUndefined(node); 473af6ab5fSopenharmony_ci return; 483af6ab5fSopenharmony_ci } 493af6ab5fSopenharmony_ci 503af6ab5fSopenharmony_ci pg_->GetThis(rootNode); 513af6ab5fSopenharmony_ci pg_->ThrowIfSuperNotCorrectCall(rootNode, 0); 523af6ab5fSopenharmony_ci pg_->EmitReturn(node); 533af6ab5fSopenharmony_ci} 543af6ab5fSopenharmony_ci 553af6ab5fSopenharmony_civoid FunctionBuilder::AsyncYield(const ir::AstNode *node, VReg completionType, VReg completionValue) const 563af6ab5fSopenharmony_ci{ 573af6ab5fSopenharmony_ci ASSERT(BuilderKind() == BuilderType::ASYNC_GENERATOR); 583af6ab5fSopenharmony_ci 593af6ab5fSopenharmony_ci pg_->GeneratorYield(node, funcObj_); 603af6ab5fSopenharmony_ci pg_->SuspendAsyncGenerator(node, funcObj_); 613af6ab5fSopenharmony_ci 623af6ab5fSopenharmony_ci ResumeGenerator(node, completionType, completionValue); 633af6ab5fSopenharmony_ci} 643af6ab5fSopenharmony_ci 653af6ab5fSopenharmony_civoid FunctionBuilder::SuspendResumeExecution(const ir::AstNode *node, VReg completionType, VReg completionValue) const 663af6ab5fSopenharmony_ci{ 673af6ab5fSopenharmony_ci ASSERT(BuilderKind() == BuilderType::ASYNC || BuilderKind() == BuilderType::ASYNC_GENERATOR || 683af6ab5fSopenharmony_ci BuilderKind() == BuilderType::GENERATOR); 693af6ab5fSopenharmony_ci 703af6ab5fSopenharmony_ci pg_->SuspendGenerator(node, funcObj_); 713af6ab5fSopenharmony_ci ResumeGenerator(node, completionType, completionValue); 723af6ab5fSopenharmony_ci} 733af6ab5fSopenharmony_ci 743af6ab5fSopenharmony_civoid FunctionBuilder::ResumeGenerator(const ir::AstNode *node, VReg completionType, VReg completionValue) const 753af6ab5fSopenharmony_ci{ 763af6ab5fSopenharmony_ci ASSERT(BuilderKind() == BuilderType::ASYNC || BuilderKind() == BuilderType::ASYNC_GENERATOR || 773af6ab5fSopenharmony_ci BuilderKind() == BuilderType::GENERATOR); 783af6ab5fSopenharmony_ci 793af6ab5fSopenharmony_ci pg_->ResumeGenerator(node, funcObj_); 803af6ab5fSopenharmony_ci pg_->StoreAccumulator(node, completionValue); 813af6ab5fSopenharmony_ci pg_->GetResumeMode(node, funcObj_); 823af6ab5fSopenharmony_ci pg_->StoreAccumulator(node, completionType); 833af6ab5fSopenharmony_ci} 843af6ab5fSopenharmony_ci 853af6ab5fSopenharmony_ciVReg FunctionBuilder::FunctionReg(const ir::ScriptFunction *node) const 863af6ab5fSopenharmony_ci{ 873af6ab5fSopenharmony_ci varbinder::FunctionScope *scope = node->Scope(); 883af6ab5fSopenharmony_ci auto res = scope->Find(varbinder::VarBinder::MANDATORY_PARAM_FUNC); 893af6ab5fSopenharmony_ci ASSERT(res.level == 0 && res.variable->IsLocalVariable()); 903af6ab5fSopenharmony_ci return res.variable->AsLocalVariable()->Vreg(); 913af6ab5fSopenharmony_ci} 923af6ab5fSopenharmony_ci 933af6ab5fSopenharmony_civoid FunctionBuilder::Await(const ir::AstNode *node) 943af6ab5fSopenharmony_ci{ 953af6ab5fSopenharmony_ci if (BuilderKind() == BuilderType::NORMAL) { 963af6ab5fSopenharmony_ci // NOTE: frobert. Implement top-level await 973af6ab5fSopenharmony_ci PandaGen::Unimplemented(); 983af6ab5fSopenharmony_ci } 993af6ab5fSopenharmony_ci 1003af6ab5fSopenharmony_ci ASSERT(BuilderKind() == BuilderType::ASYNC || BuilderKind() == BuilderType::ASYNC_GENERATOR); 1013af6ab5fSopenharmony_ci 1023af6ab5fSopenharmony_ci RegScope rs(pg_); 1033af6ab5fSopenharmony_ci VReg completionType = pg_->AllocReg(); 1043af6ab5fSopenharmony_ci VReg completionValue = pg_->AllocReg(); 1053af6ab5fSopenharmony_ci 1063af6ab5fSopenharmony_ci pg_->AsyncFunctionAwait(node, funcObj_); 1073af6ab5fSopenharmony_ci SuspendResumeExecution(node, completionType, completionValue); 1083af6ab5fSopenharmony_ci 1093af6ab5fSopenharmony_ci HandleCompletion(node, completionType, completionValue); 1103af6ab5fSopenharmony_ci} 1113af6ab5fSopenharmony_ci 1123af6ab5fSopenharmony_civoid FunctionBuilder::HandleCompletion(const ir::AstNode *node, VReg completionType, VReg completionValue) 1133af6ab5fSopenharmony_ci{ 1143af6ab5fSopenharmony_ci // .return(value) 1153af6ab5fSopenharmony_ci pg_->LoadAccumulatorInt(node, static_cast<int32_t>(ResumeMode::RETURN)); 1163af6ab5fSopenharmony_ci 1173af6ab5fSopenharmony_ci auto *notRetLabel = pg_->AllocLabel(); 1183af6ab5fSopenharmony_ci pg_->Condition(node, lexer::TokenType::PUNCTUATOR_EQUAL, completionType, notRetLabel); 1193af6ab5fSopenharmony_ci if (!handleReturn_) { 1203af6ab5fSopenharmony_ci handleReturn_ = true; 1213af6ab5fSopenharmony_ci pg_->ControlFlowChangeBreak(); 1223af6ab5fSopenharmony_ci handleReturn_ = false; 1233af6ab5fSopenharmony_ci } 1243af6ab5fSopenharmony_ci 1253af6ab5fSopenharmony_ci pg_->LoadAccumulator(node, completionValue); 1263af6ab5fSopenharmony_ci pg_->DirectReturn(node); 1273af6ab5fSopenharmony_ci 1283af6ab5fSopenharmony_ci // .throw(value) 1293af6ab5fSopenharmony_ci pg_->SetLabel(node, notRetLabel); 1303af6ab5fSopenharmony_ci pg_->LoadAccumulatorInt(node, static_cast<int32_t>(ResumeMode::THROW)); 1313af6ab5fSopenharmony_ci 1323af6ab5fSopenharmony_ci auto *notThrowLabel = pg_->AllocLabel(); 1333af6ab5fSopenharmony_ci pg_->Condition(node, lexer::TokenType::PUNCTUATOR_EQUAL, completionType, notThrowLabel); 1343af6ab5fSopenharmony_ci pg_->LoadAccumulator(node, completionValue); 1353af6ab5fSopenharmony_ci pg_->EmitThrow(node); 1363af6ab5fSopenharmony_ci 1373af6ab5fSopenharmony_ci // .next(value) 1383af6ab5fSopenharmony_ci pg_->SetLabel(node, notThrowLabel); 1393af6ab5fSopenharmony_ci pg_->LoadAccumulator(node, completionValue); 1403af6ab5fSopenharmony_ci} 1413af6ab5fSopenharmony_ci 1423af6ab5fSopenharmony_civoid FunctionBuilder::YieldStar(const ir::AstNode *node) 1433af6ab5fSopenharmony_ci{ 1443af6ab5fSopenharmony_ci ASSERT(BuilderKind() == BuilderType::GENERATOR || BuilderKind() == BuilderType::ASYNC_GENERATOR); 1453af6ab5fSopenharmony_ci 1463af6ab5fSopenharmony_ci RegScope rs(pg_); 1473af6ab5fSopenharmony_ci 1483af6ab5fSopenharmony_ci auto *loopStart = pg_->AllocLabel(); 1493af6ab5fSopenharmony_ci auto *returnCompletion = pg_->AllocLabel(); 1503af6ab5fSopenharmony_ci auto *throwCompletion = pg_->AllocLabel(); 1513af6ab5fSopenharmony_ci auto *callMethod = pg_->AllocLabel(); 1523af6ab5fSopenharmony_ci auto *normalOrThrowCompletion = pg_->AllocLabel(); 1533af6ab5fSopenharmony_ci auto *iteratorComplete = pg_->AllocLabel(); 1543af6ab5fSopenharmony_ci 1553af6ab5fSopenharmony_ci // 4. Let iteratorRecord be ? GetIterator(value, generatorKind). 1563af6ab5fSopenharmony_ci Iterator iterator(pg_, node, GeneratorKind()); 1573af6ab5fSopenharmony_ci 1583af6ab5fSopenharmony_ci // 6. Let received be NormalCompletion(undefined). 1593af6ab5fSopenharmony_ci VReg receivedValue = iterator.NextResult(); 1603af6ab5fSopenharmony_ci VReg receivedType = pg_->AllocReg(); 1613af6ab5fSopenharmony_ci VReg nextMethod = pg_->AllocReg(); 1623af6ab5fSopenharmony_ci VReg exitReturn = pg_->AllocReg(); 1633af6ab5fSopenharmony_ci 1643af6ab5fSopenharmony_ci pg_->StoreConst(node, receivedValue, Constant::JS_UNDEFINED); 1653af6ab5fSopenharmony_ci pg_->LoadAccumulatorInt(node, static_cast<int32_t>(ResumeMode::NEXT)); 1663af6ab5fSopenharmony_ci pg_->StoreAccumulator(node, receivedType); 1673af6ab5fSopenharmony_ci pg_->MoveVreg(node, nextMethod, iterator.Method()); 1683af6ab5fSopenharmony_ci 1693af6ab5fSopenharmony_ci // 7. Repeat 1703af6ab5fSopenharmony_ci pg_->SetLabel(node, loopStart); 1713af6ab5fSopenharmony_ci pg_->StoreConst(node, exitReturn, Constant::JS_FALSE); 1723af6ab5fSopenharmony_ci 1733af6ab5fSopenharmony_ci // a. If received.[[Type]] is normal, then 1743af6ab5fSopenharmony_ci pg_->LoadAccumulatorInt(node, static_cast<int32_t>(ResumeMode::NEXT)); 1753af6ab5fSopenharmony_ci pg_->Condition(node, lexer::TokenType::PUNCTUATOR_STRICT_EQUAL, receivedType, throwCompletion); 1763af6ab5fSopenharmony_ci pg_->MoveVreg(node, iterator.Method(), nextMethod); 1773af6ab5fSopenharmony_ci pg_->Branch(node, callMethod); 1783af6ab5fSopenharmony_ci 1793af6ab5fSopenharmony_ci // b. Else if received.[[Type]] is throw, then 1803af6ab5fSopenharmony_ci pg_->SetLabel(node, throwCompletion); 1813af6ab5fSopenharmony_ci pg_->LoadAccumulatorInt(node, static_cast<int32_t>(ResumeMode::THROW)); 1823af6ab5fSopenharmony_ci pg_->Condition(node, lexer::TokenType::PUNCTUATOR_STRICT_EQUAL, receivedType, returnCompletion); 1833af6ab5fSopenharmony_ci 1843af6ab5fSopenharmony_ci // i. Let throw be ? GetMethod(iterator, "throw"). 1853af6ab5fSopenharmony_ci iterator.GetMethod("throw"); 1863af6ab5fSopenharmony_ci 1873af6ab5fSopenharmony_ci // ii. If throw is not undefined, then 1883af6ab5fSopenharmony_ci pg_->BranchIfNotUndefined(node, callMethod); 1893af6ab5fSopenharmony_ci 1903af6ab5fSopenharmony_ci // iii. Else, 1913af6ab5fSopenharmony_ci // 1. NOTE: If iterator does not have a throw method, this throw is going to terminate the yield* loop. But first we 1923af6ab5fSopenharmony_ci // need to give iterator a chance to clean up. 1933af6ab5fSopenharmony_ci // 2. Let closeCompletion be Completion { [[Type]]: normal, [[Value]]: empty, [[Target]]: empty }. 1943af6ab5fSopenharmony_ci // 3. If generatorKind is async, perform ? AsyncIteratorClose(iteratorRecord, closeCompletion). 1953af6ab5fSopenharmony_ci // 4. Else, perform ? IteratorClose(iteratorRecord, closeCompletion). 1963af6ab5fSopenharmony_ci iterator.Close(false); 1973af6ab5fSopenharmony_ci // 5. NOTE: The next step throws a TypeError to indicate that there was a yield* protocol violation: iterator does 1983af6ab5fSopenharmony_ci // not have a throw method. 1993af6ab5fSopenharmony_ci // 6. Throw a TypeError exception. 2003af6ab5fSopenharmony_ci pg_->ThrowThrowNotExist(node); 2013af6ab5fSopenharmony_ci 2023af6ab5fSopenharmony_ci // c. Else, 2033af6ab5fSopenharmony_ci // i. Assert: received.[[Type]] is return. 2043af6ab5fSopenharmony_ci pg_->SetLabel(node, returnCompletion); 2053af6ab5fSopenharmony_ci pg_->StoreConst(node, exitReturn, Constant::JS_TRUE); 2063af6ab5fSopenharmony_ci // ii. Let return be ? GetMethod(iterator, "return"). 2073af6ab5fSopenharmony_ci iterator.GetMethod("return"); 2083af6ab5fSopenharmony_ci 2093af6ab5fSopenharmony_ci // iii. If return is undefined, then 2103af6ab5fSopenharmony_ci pg_->BranchIfNotUndefined(node, callMethod); 2113af6ab5fSopenharmony_ci 2123af6ab5fSopenharmony_ci // 1. If generatorKind is async, set received.[[Value]] to ? Await(received.[[Value]]). 2133af6ab5fSopenharmony_ci pg_->ControlFlowChangeBreak(); 2143af6ab5fSopenharmony_ci pg_->LoadAccumulator(node, receivedValue); 2153af6ab5fSopenharmony_ci 2163af6ab5fSopenharmony_ci if (GeneratorKind() == IteratorType::ASYNC) { 2173af6ab5fSopenharmony_ci Await(node); 2183af6ab5fSopenharmony_ci } 2193af6ab5fSopenharmony_ci 2203af6ab5fSopenharmony_ci // 2. Return Completion(received). 2213af6ab5fSopenharmony_ci pg_->DirectReturn(node); 2223af6ab5fSopenharmony_ci 2233af6ab5fSopenharmony_ci pg_->SetLabel(node, callMethod); 2243af6ab5fSopenharmony_ci // i. Let innerResult be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] »). 2253af6ab5fSopenharmony_ci // 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). 2263af6ab5fSopenharmony_ci // iv. Let innerReturnResult be ? Call(return, iterator, « received.[[Value]] »). 2273af6ab5fSopenharmony_ci iterator.CallMethodWithValue(); 2283af6ab5fSopenharmony_ci 2293af6ab5fSopenharmony_ci // ii. ii. If generatorKind is async, set innerResult to ? Await(innerResult). 2303af6ab5fSopenharmony_ci // 2. If generatorKind is async, set innerResult to ? Await(innerResult). 2313af6ab5fSopenharmony_ci // v. If generatorKind is async, set innerReturnResult to ? Await(innerReturnResult). 2323af6ab5fSopenharmony_ci if (GeneratorKind() == IteratorType::ASYNC) { 2333af6ab5fSopenharmony_ci Await(node); 2343af6ab5fSopenharmony_ci } 2353af6ab5fSopenharmony_ci 2363af6ab5fSopenharmony_ci pg_->StoreAccumulator(node, receivedValue); 2373af6ab5fSopenharmony_ci 2383af6ab5fSopenharmony_ci // ii. If Type(innerResult) is not Object, throw a TypeError exception. 2393af6ab5fSopenharmony_ci // 4. If Type(innerResult) is not Object, throw a TypeError exception. 2403af6ab5fSopenharmony_ci // vi. If Type(innerReturnResult) is not Object, throw a TypeError exception. 2413af6ab5fSopenharmony_ci pg_->ThrowIfNotObject(node); 2423af6ab5fSopenharmony_ci 2433af6ab5fSopenharmony_ci // iv. Let done be ? IteratorComplete(innerResult). 2443af6ab5fSopenharmony_ci // v. Let done be ? IteratorComplete(innerResult). 2453af6ab5fSopenharmony_ci // vii. Let done be ? IteratorComplete(innerReturnResult). 2463af6ab5fSopenharmony_ci iterator.Complete(); 2473af6ab5fSopenharmony_ci pg_->BranchIfTrue(node, iteratorComplete); 2483af6ab5fSopenharmony_ci 2493af6ab5fSopenharmony_ci // vi. If generatorKind is async, set received to AsyncGeneratorYield(? IteratorValue(innerResult)). 2503af6ab5fSopenharmony_ci // 7. If generatorKind is async, set received to AsyncGeneratorYield(? IteratorValue(innerResult)). 2513af6ab5fSopenharmony_ci // ix. If generatorKind is async, set received to AsyncGeneratorYield(? IteratorValue(innerReturnResult)). 2523af6ab5fSopenharmony_ci if (GeneratorKind() == IteratorType::ASYNC) { 2533af6ab5fSopenharmony_ci iterator.Value(); 2543af6ab5fSopenharmony_ci // 27.6.3.8 AsyncGeneratorYield 2553af6ab5fSopenharmony_ci // 5. Set value to ? Await(value). 2563af6ab5fSopenharmony_ci Await(node); 2573af6ab5fSopenharmony_ci // 6. Set generator.[[AsyncGeneratorState]] to suspendedYield. 2583af6ab5fSopenharmony_ci AsyncYield(node, receivedType, receivedValue); 2593af6ab5fSopenharmony_ci 2603af6ab5fSopenharmony_ci // a. If resumptionValue.[[Type]] is not return 2613af6ab5fSopenharmony_ci pg_->LoadAccumulatorInt(node, static_cast<int32_t>(ResumeMode::RETURN)); 2623af6ab5fSopenharmony_ci pg_->Condition(node, lexer::TokenType::PUNCTUATOR_EQUAL, receivedType, loopStart); 2633af6ab5fSopenharmony_ci 2643af6ab5fSopenharmony_ci // b. Let awaited be Await(resumptionValue.[[Value]]). 2653af6ab5fSopenharmony_ci pg_->LoadAccumulator(node, receivedValue); 2663af6ab5fSopenharmony_ci pg_->AsyncFunctionAwait(node, funcObj_); 2673af6ab5fSopenharmony_ci SuspendResumeExecution(node, receivedType, receivedValue); 2683af6ab5fSopenharmony_ci 2693af6ab5fSopenharmony_ci // c. If awaited.[[Type]] is throw, return Completion(awaited). 2703af6ab5fSopenharmony_ci pg_->LoadAccumulatorInt(node, static_cast<int32_t>(ResumeMode::THROW)); 2713af6ab5fSopenharmony_ci // d. Assert: awaited.[[Type]] is normal. 2723af6ab5fSopenharmony_ci // e. Return Completion { [[Type]]: return, [[Value]]: awaited.[[Value]], [[Target]]: empty }. 2733af6ab5fSopenharmony_ci pg_->Condition(node, lexer::TokenType::PUNCTUATOR_EQUAL, receivedType, returnCompletion); 2743af6ab5fSopenharmony_ci } else { 2753af6ab5fSopenharmony_ci // vii. Else, set received to GeneratorYield(innerResult). 2763af6ab5fSopenharmony_ci // 8. Else, set received to GeneratorYield(innerResult). 2773af6ab5fSopenharmony_ci // x. Else, set received to GeneratorYield(innerReturnResult). 2783af6ab5fSopenharmony_ci pg_->LoadAccumulator(node, receivedValue); 2793af6ab5fSopenharmony_ci pg_->GeneratorYield(node, funcObj_); 2803af6ab5fSopenharmony_ci SuspendResumeExecution(node, receivedType, receivedValue); 2813af6ab5fSopenharmony_ci } 2823af6ab5fSopenharmony_ci 2833af6ab5fSopenharmony_ci pg_->Branch(node, loopStart); 2843af6ab5fSopenharmony_ci 2853af6ab5fSopenharmony_ci // v. If done is true, then 2863af6ab5fSopenharmony_ci // 6. If done is true, then 2873af6ab5fSopenharmony_ci // viii. If done is true, then 2883af6ab5fSopenharmony_ci pg_->SetLabel(node, iteratorComplete); 2893af6ab5fSopenharmony_ci 2903af6ab5fSopenharmony_ci pg_->LoadAccumulator(node, exitReturn); 2913af6ab5fSopenharmony_ci pg_->BranchIfFalse(node, normalOrThrowCompletion); 2923af6ab5fSopenharmony_ci 2933af6ab5fSopenharmony_ci // 1. Let value be ? IteratorValue(innerReturnResult). 2943af6ab5fSopenharmony_ci iterator.Value(); 2953af6ab5fSopenharmony_ci 2963af6ab5fSopenharmony_ci if (pg_->CheckControlFlowChange()) { 2973af6ab5fSopenharmony_ci pg_->StoreAccumulator(node, receivedValue); 2983af6ab5fSopenharmony_ci pg_->ControlFlowChangeBreak(); 2993af6ab5fSopenharmony_ci pg_->LoadAccumulator(node, receivedValue); 3003af6ab5fSopenharmony_ci } 3013af6ab5fSopenharmony_ci 3023af6ab5fSopenharmony_ci // 2. Return Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty }. 3033af6ab5fSopenharmony_ci pg_->DirectReturn(node); 3043af6ab5fSopenharmony_ci 3053af6ab5fSopenharmony_ci pg_->SetLabel(node, normalOrThrowCompletion); 3063af6ab5fSopenharmony_ci // 1. Return ? IteratorValue(innerResult). 3073af6ab5fSopenharmony_ci // a. Return ? IteratorValue(innerResult). 3083af6ab5fSopenharmony_ci iterator.Value(); 3093af6ab5fSopenharmony_ci} 3103af6ab5fSopenharmony_ci} // namespace ark::es2panda::compiler 311