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

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

Issue 139653003: Throw a TypeError when calling "next" method of a newly created generator with a value (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Revised Created 6 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
« no previous file with comments | « src/x64/full-codegen-x64.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/generators-iteration.js
diff --git a/test/mjsunit/harmony/generators-iteration.js b/test/mjsunit/harmony/generators-iteration.js
index d86a20f9e7da2cd52a59dd3cb15eb4bcfea76ec8..e6c05e3445996f96ac0d638ff8a96d46cc63d54e 100644
--- a/test/mjsunit/harmony/generators-iteration.js
+++ b/test/mjsunit/harmony/generators-iteration.js
@@ -74,7 +74,12 @@ function TestGenerator(g, expected_values_for_next,
}
function testSend(thunk) {
var iter = thunk();
- for (var i = 0; i < expected_values_for_send.length; i++) {
+ // Throw error when sending a value to a newly created generator.
+ if (expected_values_for_send.length > 0) {
+ assertThrows(function () { iter.next(send_val); }, TypeError);
+ assertIteratorResult(expected_values_for_send[0], 0 == expected_values_for_send.length - 1, iter.next());
+ }
+ for (var i = 1; i < expected_values_for_send.length; i++) {
assertIteratorResult(expected_values_for_send[i],
i == expected_values_for_send.length - 1,
iter.next(send_val));
@@ -648,3 +653,37 @@ function TestRecursion() {
assertThrows(TestThrowRecursion, Error);
}
TestRecursion();
+
+function TestNewlyCreated(instantiate) {
+ function * g() { return yield 1; }
+
+ function Test1(iter) {
+ assertThrows(function () { iter.next(1); }, TypeError);
+ // Iterator is still "suspendedStart" state.
+ assertThrows(function () { iter.next(1); }, TypeError);
+ assertIteratorResult(1, false, iter.next());
+ assertIteratorResult(2, true, iter.next(2));
+ assertIteratorIsClosed(iter);
+ }
+ Test1(instantiate(g));
+
+ function Test1(iter) {
+ // If a provided value is undefined, iter with "suspendedStart" status
+ // doesn't throw an error.
+ assertIteratorResult(1, false, iter.next(undefined));
+ assertIteratorResult(2, true, iter.next(2));
+ assertIteratorIsClosed(iter);
+ }
+ Test1(instantiate(g));
+
+ function Test2(iter) {
+ function Sentinel() { }
+ assertThrows(function () { iter.throw(new Sentinel); }, Sentinel);
+ // When calling throw method to an newly created iterator, it becomes
+ // "completed" state.
+ assertThrownIteratorIsClosed(iter);
+ }
+ Test2(instantiate(g));
+}
+TestNewlyCreated(function (g) { return g(); });
+TestNewlyCreated(function* (g) { return yield* g(); });
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698