summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Destructuring/array-iterator-close.js
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-24 12:23:14 +0100
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-24 12:23:14 +0100
commit2bb0252ab48a97a72c33cef9cbe54e86563f15c9 (patch)
tree1b792a95a2ddaed8f3a16e7367b72fff73a51a51 /js/src/tests/ecma_6/Destructuring/array-iterator-close.js
parent4b487efb58bfba4c3f67d898e86b9f6daaab59b2 (diff)
downloadUXP-2bb0252ab48a97a72c33cef9cbe54e86563f15c9.tar
UXP-2bb0252ab48a97a72c33cef9cbe54e86563f15c9.tar.gz
UXP-2bb0252ab48a97a72c33cef9cbe54e86563f15c9.tar.lz
UXP-2bb0252ab48a97a72c33cef9cbe54e86563f15c9.tar.xz
UXP-2bb0252ab48a97a72c33cef9cbe54e86563f15c9.zip
Bug 1147371: Implement IteratorClose for array destructuring
Issue #74
Diffstat (limited to 'js/src/tests/ecma_6/Destructuring/array-iterator-close.js')
-rw-r--r--js/src/tests/ecma_6/Destructuring/array-iterator-close.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Destructuring/array-iterator-close.js b/js/src/tests/ecma_6/Destructuring/array-iterator-close.js
new file mode 100644
index 000000000..f7805540d
--- /dev/null
+++ b/js/src/tests/ecma_6/Destructuring/array-iterator-close.js
@@ -0,0 +1,77 @@
+// Tests that IteratorClose is called in array destructuring patterns.
+
+function test() {
+ var returnCalled = 0;
+ var returnCalledExpected = 0;
+ var iterable = {};
+
+ // empty [] calls IteratorClose regardless of "done" on the result.
+ iterable[Symbol.iterator] = makeIterator({
+ next: function() {
+ return { done: true };
+ },
+ ret: function() {
+ returnCalled++;
+ return {};
+ }
+ });
+ var [] = iterable;
+ assertEq(returnCalled, ++returnCalledExpected);
+
+ iterable[Symbol.iterator] = makeIterator({
+ ret: function() {
+ returnCalled++;
+ return {};
+ }
+ });
+ var [] = iterable;
+ assertEq(returnCalled, ++returnCalledExpected);
+
+ // Non-empty destructuring calls IteratorClose if iterator is not done by
+ // the end of destructuring.
+ var [a,b] = iterable;
+ assertEq(returnCalled, ++returnCalledExpected);
+ var [c,] = iterable;
+ assertEq(returnCalled, ++returnCalledExpected);
+
+ // throw in lhs ref calls IteratorClose
+ function throwlhs() {
+ throw "in lhs";
+ }
+ assertThrowsValue(function() {
+ 0, [...{}[throwlhs()]] = iterable;
+ }, "in lhs");
+ assertEq(returnCalled, ++returnCalledExpected);
+
+ // throw in iter.next doesn't call IteratorClose
+ iterable[Symbol.iterator] = makeIterator({
+ next: function() {
+ throw "in next";
+ },
+ ret: function() {
+ returnCalled++;
+ return {};
+ }
+ });
+ assertThrowsValue(function() {
+ var [d] = iterable;
+ }, "in next");
+ assertEq(returnCalled, returnCalledExpected);
+
+ // "return" must return an Object.
+ iterable[Symbol.iterator] = makeIterator({
+ ret: function() {
+ returnCalled++;
+ return 42;
+ }
+ });
+ assertThrowsInstanceOf(function() {
+ var [] = iterable;
+ }, TypeError);
+ assertEq(returnCalled, ++returnCalledExpected);
+}
+
+test();
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0);