summaryrefslogtreecommitdiffstats
path: root/js/src/tests
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-25 19:06:08 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-25 19:06:08 +0200
commit70c8cf8db71880c1ab1f8fee4787a19316960dac (patch)
tree618fc907d501d7154e9a86493d7cf86bf96ca682 /js/src/tests
parentaafdd314442c903815f6fdf6072b001c25ae85c5 (diff)
downloadUXP-70c8cf8db71880c1ab1f8fee4787a19316960dac.tar
UXP-70c8cf8db71880c1ab1f8fee4787a19316960dac.tar.gz
UXP-70c8cf8db71880c1ab1f8fee4787a19316960dac.tar.lz
UXP-70c8cf8db71880c1ab1f8fee4787a19316960dac.tar.xz
UXP-70c8cf8db71880c1ab1f8fee4787a19316960dac.zip
Bug 1360839 - Call IteratorClose due to abrupt completion from yield
Issue #74
Diffstat (limited to 'js/src/tests')
-rw-r--r--js/src/tests/ecma_6/Generators/yield-iterator-close.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Generators/yield-iterator-close.js b/js/src/tests/ecma_6/Generators/yield-iterator-close.js
new file mode 100644
index 000000000..970ad494d
--- /dev/null
+++ b/js/src/tests/ecma_6/Generators/yield-iterator-close.js
@@ -0,0 +1,58 @@
+// Test that IteratorClose is called when a Generator is abruptly completed by
+// Generator.return.
+
+var returnCalled = 0;
+function* wrapNoThrow() {
+ let iter = {
+ [Symbol.iterator]() {
+ return this;
+ },
+ next() {
+ return { value: 10, done: false };
+ },
+ return() {
+ returnCalled++;
+ return {};
+ }
+ };
+ for (const i of iter) {
+ yield i;
+ }
+}
+
+// Breaking calls Generator.return, which causes the yield above to resume with
+// an abrupt completion of kind "return", which then calls
+// iter.return.
+for (const i of wrapNoThrow()) {
+ break;
+}
+assertEq(returnCalled, 1);
+
+function* wrapThrow() {
+ let iter = {
+ [Symbol.iterator]() {
+ return this;
+ },
+ next() {
+ return { value: 10, done: false };
+ },
+ return() {
+ throw 42;
+ }
+ };
+ for (const i of iter) {
+ yield i;
+ }
+}
+
+// Breaking calls Generator.return, which, like above, calls iter.return. If
+// iter.return throws, since the yield is resuming with an abrupt completion of
+// kind "return", the newly thrown value takes precedence over returning.
+assertThrowsValue(() => {
+ for (const i of wrapThrow()) {
+ break;
+ }
+}, 42);
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0);