Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Unified Diff: test/mjsunit/harmony/iterator-close.js

Issue 1695583003: [WIP] for-of iterator finalization (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/parsing/parser.cc ('K') | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« src/parsing/parser.cc ('K') | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698