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

Unified Diff: test/mjsunit/harmony/generators.js

Issue 1606273002: Implement [Generator].prototype.return. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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/js/generator.js ('K') | « test/mjsunit/es6/generators-runtime.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/generators.js
diff --git a/test/mjsunit/harmony/generators.js b/test/mjsunit/harmony/generators.js
new file mode 100644
index 0000000000000000000000000000000000000000..baef2506c6516427eda770ac4329b7c82fddaf82
--- /dev/null
+++ b/test/mjsunit/harmony/generators.js
@@ -0,0 +1,142 @@
+// 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.
+
+
+{ // yield in try-catch
+
+ let g = function*() {
+ try {yield 1} catch (error) {assertEquals("caught", error)}
+ };
+
+ assertThrowsEquals(() => g().throw("not caught"), "not caught");
+
+ {
+ let x = g();
+ assertEquals({value: 1, done: false}, x.next());
+ assertEquals({value: undefined, done: true}, x.throw("caught"));
+ }
+
+ {
+ let x = g();
+ assertEquals({value: 1, done: false}, x.next());
+ assertEquals({value: undefined, done: true}, x.next());
+ assertThrowsEquals(() => x.throw("not caught"), "not caught");
+ }
+}
+
+
+{ // yield in try-finally, finally clause performs return
+
+ let g = function*() { try {yield 42} finally {return 13} };
+
+ { // "return" closes at suspendedStart
+ let x = g();
+ assertEquals({value: 666, done: true}, x.return(666));
+ assertEquals({value: undefined, done: true}, x.next(42));
+ assertThrowsEquals(() => x.throw(43), 43);
+ assertEquals({value: 42, done: true}, x.return(42));
+ }
+
+ { // "throw" closes at suspendedStart
+ let x = g();
+ assertThrowsEquals(() => x.throw(666), 666);
+ assertEquals({value: undefined, done: true}, x.next(42));
+ assertEquals({value: 43, done: true}, x.return(43));
+ assertThrowsEquals(() => x.throw(44), 44);
+ }
+
+ { // "next" closes at suspendedYield
+ let x = g();
+ assertEquals({value: 42, done: false}, x.next());
+ assertEquals({value: 13, done: true}, x.next(666));
+ assertEquals({value: undefined, done: true}, x.next(666));
+ assertThrowsEquals(() => x.throw(666), 666);
+ }
+
+ { // "return" closes at suspendedYield
+ let x = g();
+ assertEquals({value: 42, done: false}, x.next());
+ assertEquals({value: 13, done: true}, x.return(666));
+ assertEquals({value: undefined, done: true}, x.next(666));
+ assertEquals({value: 666, done: true}, x.return(666));
+ }
+
+ { // "throw" closes at suspendedYield
+ let x = g();
+ assertEquals({value: 42, done: false}, x.next());
+ assertEquals({value: 13, done: true}, x.throw(666));
+ assertThrowsEquals(() => x.throw(666), 666);
+ assertEquals({value: undefined, done: true}, x.next(666));
+ }
+}
+
+
+{ // yield in try-finally, finally clause doesn't perform return
+
+ let g = function*() { try {yield 42} finally {13} };
+
+ { // "return" closes at suspendedStart
+ let x = g();
+ assertEquals({value: 666, done: true}, x.return(666));
+ assertEquals({value: undefined, done: true}, x.next(42));
+ assertThrowsEquals(() => x.throw(43), 43);
+ assertEquals({value: 42, done: true}, x.return(42));
+ }
+
+ { // "throw" closes at suspendedStart
+ let x = g();
+ assertThrowsEquals(() => x.throw(666), 666);
+ assertEquals({value: undefined, done: true}, x.next(42));
+ assertEquals({value: 43, done: true}, x.return(43));
+ assertThrowsEquals(() => x.throw(44), 44);
+ }
+
+ { // "next" closes at suspendedYield
+ let x = g();
+ assertEquals({value: 42, done: false}, x.next());
+ assertEquals({value: undefined, done: true}, x.next(666));
+ assertEquals({value: undefined, done: true}, x.next(666));
+ assertThrowsEquals(() => x.throw(666), 666);
+ assertEquals({value: 42, done: true}, x.return(42));
+ }
+
+ { // "return" closes at suspendedYield
+ let x = g();
+ assertEquals({value: 42, done: false}, x.next());
+ assertEquals({value: 666, done: true}, x.return(666));
+ assertEquals({value: undefined, done: true}, x.next(666));
+ assertThrowsEquals(() => x.throw(44), 44);
+ assertEquals({value: 42, done: true}, x.return(42));
+ }
+
+ { // "throw" closes at suspendedYield
+ let x = g();
+ assertEquals({value: 42, done: false}, x.next());
+ assertThrowsEquals(() => x.throw(666), 666);
+ assertEquals({value: undefined, done: true}, x.next(666));
+ assertThrowsEquals(() => x.throw(666), 666);
+ assertEquals({value: 42, done: true}, x.return(42));
+ }
+}
+
+
+{ // yield in try-finally, finally yields and performs return
+
+ let g = function*() { try {yield 42} finally {yield 43; return 13} };
+
+ {
+ let x = g();
+ assertEquals({value: 42, done: false}, x.next());
+ assertEquals({value: 43, done: false}, x.return(666));
+ assertEquals({value: 13, done: true}, x.next());
+ assertEquals({value: 666, done: true}, x.return(666));
+ }
+
+ {
+ let x = g();
+ assertEquals({value: 666, done: true}, x.return(666));
+ assertEquals({value: undefined, done: true}, x.next());
+ assertEquals({value: 666, done: true}, x.return(666));
+ }
+}
« src/js/generator.js ('K') | « test/mjsunit/es6/generators-runtime.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698