From c919c1d3c1fc6c5145a85ce6091f5363d490fd44 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Sat, 9 Dec 2023 16:14:41 +0000 Subject: [PATCH] Fix array binding pattern iteration Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8N2NQ Signed-off-by: ctw-ian Change-Id: I6f370c49560b0db5b168c983b15459d752575c04 --- es2panda/compiler/base/destructuring.cpp | 5 +++++ .../iterator-done-test-1-expected.txt | 1 + .../js/destructuring/iterator-done-test-1.js | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 es2panda/test/compiler/js/destructuring/iterator-done-test-1-expected.txt create mode 100644 es2panda/test/compiler/js/destructuring/iterator-done-test-1.js diff --git a/es2panda/compiler/base/destructuring.cpp b/es2panda/compiler/base/destructuring.cpp index 7831998020..0df86f24db 100644 --- a/es2panda/compiler/base/destructuring.cpp +++ b/es2panda/compiler/base/destructuring.cpp @@ -79,9 +79,12 @@ static void GenArray(PandaGen *pg, const ir::ArrayExpression *array) } DestructuringIteratorContext dstrCtx(pg, iterator); + auto *doneLabel = pg->AllocLabel(); for (const auto *element : array->Elements()) { RegScope ers(pg); + pg->LoadAccumulator(element, iterator.Done()); + pg->BranchIfTrue(element, doneLabel); if (element->IsRestElement()) { GenRestElement(pg, element->AsRestElement(), iterator, array->IsDeclaration()); @@ -121,6 +124,8 @@ static void GenArray(PandaGen *pg, const ir::ArrayExpression *array) lref.SetValue(); } + + pg->SetLabel(array, doneLabel); } static void GenObjectProperty(PandaGen *pg, const ir::ObjectExpression *object, diff --git a/es2panda/test/compiler/js/destructuring/iterator-done-test-1-expected.txt b/es2panda/test/compiler/js/destructuring/iterator-done-test-1-expected.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/es2panda/test/compiler/js/destructuring/iterator-done-test-1-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/js/destructuring/iterator-done-test-1.js b/es2panda/test/compiler/js/destructuring/iterator-done-test-1.js new file mode 100644 index 0000000000..8fa79e6861 --- /dev/null +++ b/es2panda/test/compiler/js/destructuring/iterator-done-test-1.js @@ -0,0 +1,16 @@ +let called = 0 +const it = { + [Symbol.iterator]() { + return this; + }, + next() { + called +=1; + return { + value: 42, + done: true + }; + } +} + +const [a, b, ...c] = it; +print(called); -- Gitee