diff --git a/es2panda/compiler/base/destructuring.cpp b/es2panda/compiler/base/destructuring.cpp index 7831998020f47034a2b2dea11590bcf4fd7da30a..0df86f24db676524869fd655b90763d57d220838 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 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /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 0000000000000000000000000000000000000000..8fa79e686183ea4457ae9d42455f59bd3c044044 --- /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);