From a99fcc7f303ecc8e19e97d17156c283e9ee45a8b Mon Sep 17 00:00:00 2001 From: lichenshuai Date: Fri, 30 Jun 2023 10:02:48 +0800 Subject: [PATCH] =?UTF-8?q?[Bug]:=20AsyncGeneratorResolve=E9=81=87?= =?UTF-8?q?=E5=88=B0=E7=A9=BA=E9=98=9F=E5=88=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在debug模式下,挂在AsyncGeneratorResolve字节码遇到空队列, 按照ECMA规范分析,执行两次next()后,状态应该为completed且队列应该为空。此时,不需要进入对应逻辑。 Issue: #I7HA9B Signed-off-by: lichenshuai Change-Id: I6559bd8d60f78341ee6783d636b6d6fa7fe55391 --- ecmascript/stubs/runtime_stubs-inl.h | 4 ++++ test/moduletest/asyncgenerator/asyncgeneratornext.js | 9 +++++++++ test/moduletest/asyncgenerator/expect_output.txt | 1 + 3 files changed, 14 insertions(+) diff --git a/ecmascript/stubs/runtime_stubs-inl.h b/ecmascript/stubs/runtime_stubs-inl.h index b4e2402e71..0952892f1c 100644 --- a/ecmascript/stubs/runtime_stubs-inl.h +++ b/ecmascript/stubs/runtime_stubs-inl.h @@ -359,6 +359,10 @@ JSTaggedValue RuntimeStubs::RuntimeAsyncGeneratorResolve(JSThread *thread, JSHan ASSERT(flag.IsBoolean()); bool done = flag.IsTrue(); + if (asyncGeneratorObjHandle->GetAsyncGeneratorState() == JSAsyncGeneratorState::COMPLETED && + TaggedQueue::Cast(asyncGeneratorObjHandle->GetAsyncGeneratorQueue().GetTaggedObject())->Empty()) { + return JSTaggedValue::Undefined(); + } return JSAsyncGeneratorObject::AsyncGeneratorResolve(thread, asyncGeneratorObjHandle, valueHandle, done); } diff --git a/test/moduletest/asyncgenerator/asyncgeneratornext.js b/test/moduletest/asyncgenerator/asyncgeneratornext.js index 433f38a9ed..df03f3d52b 100644 --- a/test/moduletest/asyncgenerator/asyncgeneratornext.js +++ b/test/moduletest/asyncgenerator/asyncgeneratornext.js @@ -26,8 +26,17 @@ async function *a() { print(c); } +async function *f() { + return 0; +} + let b = a(); print("asyncgenerator next start"); b.next(); b.next(3); + +const g = f(); +g.next(); +g.next(); +print("asyncgenerator double next"); print("asyncgenerator next end"); \ No newline at end of file diff --git a/test/moduletest/asyncgenerator/expect_output.txt b/test/moduletest/asyncgenerator/expect_output.txt index 7582685b9c..db6d77b20f 100644 --- a/test/moduletest/asyncgenerator/expect_output.txt +++ b/test/moduletest/asyncgenerator/expect_output.txt @@ -14,6 +14,7 @@ async generator start asyncgenerator next start 1 +asyncgenerator double next asyncgenerator next end 3 asyncgenerator return start