Chromium Code Reviews| Index: test/mjsunit/harmony/iterator-close.js |
| diff --git a/test/mjsunit/harmony/iterator-close.js b/test/mjsunit/harmony/iterator-close.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e82b8fe511fb200186e42cd1835db3a435220b7f |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/iterator-close.js |
| @@ -0,0 +1,210 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| + |
| +function* g() { yield 42; return 88 }; |
| + |
| + |
| +// Return method is "undefined". |
| +{ |
| + g.prototype.return = null; |
| + |
| + assertEquals(undefined, (() => { |
| + for (let x of g()) { break; } |
| + })()); |
| + |
| + assertEquals(undefined, (() => { |
| + for (x of g()) { break; } |
| + })()); |
| + |
| + assertThrowsEquals(() => { |
| + for (let x of g()) { throw 42; } |
| + }, 42); |
| + |
| + //assertThrowsEquals(() => { |
| + // for (x of g()) { throw 42; } |
| + //}, 42); |
|
neis
2016/02/12 12:30:13
This and the other two commented out tests fail wi
|
| + |
| + assertEquals(42, (() => { |
| + for (let x of g()) { return 42; } |
| + })()); |
| + |
| + assertEquals(42, (() => { |
| + for (x of g()) { return 42; } |
| + })()); |
| + |
| + assertEquals(42, eval('for (let x of g()) { x; }')); |
| + |
| + assertEquals(42, eval('for (let x of g()) { x; }')); |
| +} |
| + |
| + |
| +// Return method is not callable. |
| +{ |
| + g.prototype.return = 666; |
| + |
| + assertThrows(() => { |
| + for (let x of g()) { break; } |
| + }, TypeError); |
| + |
| + assertThrows(() => { |
| + for (x of g()) { break; } |
| + }, TypeError); |
| + |
| + assertThrows(() => { |
| + for (let x of g()) { throw 666; } |
| + }, TypeError); |
| + |
| + assertThrows(() => { |
| + for (x of g()) { throw 666; } |
| + }, TypeError); |
| + |
| + assertThrows(() => { |
| + for (let x of g()) { return 666; } |
| + }, TypeError); |
| + |
| + assertThrows(() => { |
| + for (x of g()) { return 666; } |
| + }, TypeError); |
| + |
| + assertEquals(42, eval('for (let x of g()) { x; }')); |
| + |
| + assertEquals(42, eval('for (let x of g()) { x; }')); |
| +} |
| + |
| + |
| +// Return method does not return an object. |
| +{ |
| + g.prototype.return = () => 666; |
| + |
| + assertThrows(() => { |
| + for (let x of g()) { break; } |
| + }, TypeError); |
| + |
| + assertThrows(() => { |
| + for (x of g()) { break; } |
| + }, TypeError); |
| + |
| + assertThrows(() => { |
| + for (let x of g()) { throw 666; } |
| + }, TypeError); |
| + |
| + assertThrows(() => { |
| + for (x of g()) { throw 666; } |
| + }, TypeError); |
| + |
| + assertThrows(() => { |
| + for (let x of g()) { return 666; } |
| + }, TypeError); |
| + |
| + assertThrows(() => { |
| + for (x of g()) { return 666; } |
| + }, TypeError); |
| + |
| + assertEquals(42, eval('for (let x of g()) { x; }')); |
| + |
| + assertEquals(42, eval('for (x of g()) { x; }')); |
| +} |
| + |
| + |
| +// Return method returns an object. |
| +{ |
| + let log = []; |
| + g.prototype.return = (...args) => { log.push(args); return {} }; |
| + |
| + log.length = 0; |
| + for (let x of g()) { break; } |
| + assertEquals([[]], log); |
| + |
| + log.length = 0; |
| + for (x of g()) { break; } |
| + assertEquals([[]], log); |
| + |
| + log.length = 0; |
| + assertThrowsEquals(() => { |
| + for (let x of g()) { throw 42; } |
| + }, 42); |
| + assertEquals([[]], log); |
| + |
| + //log.length = 0; |
| + //assertThrowsEquals(() => { |
| + // for (x of g()) { throw 42; } |
| + //}, 42); |
| + //assertEquals([[]], log); |
| + |
| + log.length = 0; |
| + assertEquals(42, (() => { |
| + for (let x of g()) { return 42; } |
| + })()); |
| + assertEquals([[]], log); |
| + |
| + log.length = 0; |
| + assertEquals(42, (() => { |
| + for (x of g()) { return 42; } |
| + })()); |
| + assertEquals([[]], log); |
| + |
| + log.length = 0; |
| + assertEquals(42, eval('for (let x of g()) { x; }')); |
| + assertEquals([], log); |
| + |
| + log.length = 0; |
| + assertEquals(42, eval('for (x of g()) { x; }')); |
| + assertEquals([], log); |
| +} |
| + |
| + |
| +// Return method throws. |
| +{ |
| + let log = []; |
| + g.prototype.return = (...args) => { log.push(args); throw 23 }; |
| + |
| + log.length = 0; |
| + assertThrowsEquals(() => { |
| + for (let x of g()) { break; } |
| + }, 23); |
| + assertEquals([[]], log); |
| + |
| + log.length = 0; |
| + assertThrowsEquals(() => { |
| + for (x of g()) { break; } |
| + }, 23); |
| + assertEquals([[]], log); |
| + |
| + log.length = 0; |
| + assertThrowsEquals(() => { |
| + for (let x of g()) { throw 42; } |
| + }, 42); |
| + assertEquals([[]], log); |
| + |
| + //log.length = 0; |
| + //assertThrowsEquals(() => { |
| + // for (x of g()) { throw 42; } |
| + //}, 42); |
| + //assertEquals([[]], log); |
| + |
| + log.length = 0; |
| + assertThrowsEquals(() => { |
| + for (let x of g()) { return 42; } |
| + }, 23); |
| + assertEquals([[]], log); |
| + |
| + log.length = 0; |
| + assertThrowsEquals(() => { |
| + for (x of g()) { return 42; } |
| + }, 23); |
| + assertEquals([[]], log); |
| + |
| + log.length = 0; |
| + assertEquals(42, eval('for (let x of g()) { x; }')); |
| + assertEquals([], log); |
| + |
| + log.length = 0; |
| + assertEquals(42, eval('for (x of g()) { x; }')); |
| + assertEquals([], log); |
| +} |
| + |
| + |
| +// TODO(neis): |
| +// - tests with throw in next() etc |