diff options
author | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-03-25 14:20:11 +0200 |
---|---|---|
committer | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-03-25 14:20:11 +0200 |
commit | 4ee42e38e0a490eb4880b4a260e3cbe07dd486d1 (patch) | |
tree | f923d15f26214678fe0bac821e9658503ce98157 /js/src/tests/ecma_6 | |
parent | c93787917dbf305aa622d2d288effff78fe81008 (diff) | |
download | UXP-4ee42e38e0a490eb4880b4a260e3cbe07dd486d1.tar UXP-4ee42e38e0a490eb4880b4a260e3cbe07dd486d1.tar.gz UXP-4ee42e38e0a490eb4880b4a260e3cbe07dd486d1.tar.lz UXP-4ee42e38e0a490eb4880b4a260e3cbe07dd486d1.tar.xz UXP-4ee42e38e0a490eb4880b4a260e3cbe07dd486d1.zip |
Bug 1338796 - Do not call iterator.return if iterator.throw is present in yield*
Issue #74
Diffstat (limited to 'js/src/tests/ecma_6')
-rw-r--r-- | js/src/tests/ecma_6/Generators/yield-star-iterator-close.js | 38 | ||||
-rw-r--r-- | js/src/tests/ecma_6/shell.js | 7 |
2 files changed, 38 insertions, 7 deletions
diff --git a/js/src/tests/ecma_6/Generators/yield-star-iterator-close.js b/js/src/tests/ecma_6/Generators/yield-star-iterator-close.js index ec62dd86d..91ad31cb6 100644 --- a/js/src/tests/ecma_6/Generators/yield-star-iterator-close.js +++ b/js/src/tests/ecma_6/Generators/yield-star-iterator-close.js @@ -6,6 +6,8 @@ function test() { var returnCalledExpected = 0; var nextCalled = 0; var nextCalledExpected = 0; + var throwCalled = 0; + var throwCalledExpected = 0; var iterable = {}; iterable[Symbol.iterator] = makeIterator({ next: function() { @@ -25,9 +27,9 @@ function test() { // G.p.throw on an iterator without "throw" calls IteratorClose. var g1 = y(); g1.next(); - assertThrowsValue(function() { + assertThrowsInstanceOf(function() { g1.throw("foo"); - }, "foo"); + }, TypeError); assertEq(returnCalled, ++returnCalledExpected); assertEq(nextCalled, ++nextCalledExpected); g1.next(); @@ -98,9 +100,18 @@ function test() { // IteratorClose expects iter.return to return an Object. var g6 = y(); g6.next(); - assertThrowsInstanceOf(function() { + var exc; + try { g6.throw("foo"); - }, TypeError); + } catch (e) { + exc = e; + } finally { + assertEq(exc instanceof TypeError, true); + // The message test is here because instanceof TypeError doesn't + // distinguish the non-Object return TypeError and the + // throw-method-is-not-defined iterator protocol error. + assertEq(exc.toString().indexOf("non-object") > 0, true); + } assertEq(returnCalled, ++returnCalledExpected); // G.p.return passes its argument to "return". @@ -115,6 +126,25 @@ function test() { g7.next(); g7.return("in test"); assertEq(returnCalled, ++returnCalledExpected); + + // If a throw method is present, do not call "return". + iterable[Symbol.iterator] = makeIterator({ + throw: function(e) { + throwCalled++; + throw e; + }, + ret: function(x) { + returnCalled++; + return { done: true }; + } + }); + var g8 = y(); + g8.next(); + assertThrowsValue(function() { + g8.throw("foo"); + }, "foo"); + assertEq(throwCalled, ++throwCalledExpected); + assertEq(returnCalled, returnCalledExpected); } test(); diff --git a/js/src/tests/ecma_6/shell.js b/js/src/tests/ecma_6/shell.js index 4da9221d6..756da9f36 100644 --- a/js/src/tests/ecma_6/shell.js +++ b/js/src/tests/ecma_6/shell.js @@ -21,10 +21,11 @@ /** Make an iterator with a return method. */ global.makeIterator = function makeIterator(overrides) { + var throwMethod; + if (overrides && overrides.throw) + throwMethod = overrides.throw; var iterator = { - throw: function(e) { - throw e; - }, + throw: throwMethod, next: function(x) { if (overrides && overrides.next) return overrides.next(x); |