summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Generators/yield-star-iterator-close.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/ecma_6/Generators/yield-star-iterator-close.js')
-rw-r--r--js/src/tests/ecma_6/Generators/yield-star-iterator-close.js38
1 files changed, 34 insertions, 4 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();