From 7530ab43c3abaff818b7131759de564af3373725 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Mon, 31 Jul 2023 15:59:24 +0800 Subject: [PATCH] fixed edf3fb4 from https://gitee.com/ctw-ian/ark_ts2abc/pulls/1154 Fix async generator with explicit return Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I7PBQY Signed-off-by: ctw-ian Change-Id: Iabef5d8caf7ed1f7c65e99d2959736c3dcac7c22 --- .../asyncGeneratorFunctionBuilder.cpp | 4 +--- ...ync-generator-explicit-return-expected.txt | 1 + .../async-generator-explicit-return.js | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 es2panda/test/compiler/js/async-generator/async-generator-explicit-return-expected.txt create mode 100644 es2panda/test/compiler/js/async-generator/async-generator-explicit-return.js diff --git a/es2panda/compiler/function/asyncGeneratorFunctionBuilder.cpp b/es2panda/compiler/function/asyncGeneratorFunctionBuilder.cpp index f6d5cd16e1..be27250557 100644 --- a/es2panda/compiler/function/asyncGeneratorFunctionBuilder.cpp +++ b/es2panda/compiler/function/asyncGeneratorFunctionBuilder.cpp @@ -80,11 +80,9 @@ void AsyncGeneratorFunctionBuilder::ExplicitReturn(const ir::AstNode *node) cons VReg resumeValue = pg_->AllocReg(); VReg canSuspend = pg_->AllocReg(); - pg_->StoreAccumulator(node, resumeValue); - pg_->GeneratorComplete(node, funcObj_); - pg_->LoadAccumulator(node, resumeValue); pg_->AsyncFunctionAwait(node, funcObj_); SuspendResumeExecution(node, resumeType, resumeValue); + pg_->GeneratorComplete(node, funcObj_); pg_->StoreConst(node, canSuspend, Constant::JS_TRUE); pg_->AsyncGeneratorResolve(node, funcObj_, resumeValue, canSuspend); pg_->EmitReturn(node); diff --git a/es2panda/test/compiler/js/async-generator/async-generator-explicit-return-expected.txt b/es2panda/test/compiler/js/async-generator/async-generator-explicit-return-expected.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/es2panda/test/compiler/js/async-generator/async-generator-explicit-return-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/js/async-generator/async-generator-explicit-return.js b/es2panda/test/compiler/js/async-generator/async-generator-explicit-return.js new file mode 100644 index 0000000000..065a555890 --- /dev/null +++ b/es2panda/test/compiler/js/async-generator/async-generator-explicit-return.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +async function *f() { + return 0; +} + +const g = f(); +g.next(); +g.next(); +print(1); -- Gitee