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

Side by Side Diff: test/mjsunit/harmony/generators-iteration.js

Issue 430693003: yield* calls @@iterator on iterable (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Removed extra flag from test Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --harmony-generators --expose-gc 28 // Flags: --harmony-generators --expose-gc --harmony-iteration
29 29
30 // Test generator iteration. 30 // Test generator iteration.
31 31
32 var GeneratorFunction = (function*(){yield 1;}).__proto__.constructor; 32 var GeneratorFunction = (function*(){yield 1;}).__proto__.constructor;
33 33
34 function assertIteratorResult(value, done, result) { 34 function assertIteratorResult(value, done, result) {
35 assertEquals({ value: value, done: done}, result); 35 assertEquals({ value: value, done: done}, result);
36 } 36 }
37 37
38 function assertIteratorIsClosed(iter) { 38 function assertIteratorIsClosed(iter) {
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 TestGenerator( 348 TestGenerator(
349 function* g27() { 349 function* g27() {
350 yield 350 yield
351 3 351 3
352 return 352 return
353 }, 353 },
354 [undefined, undefined], 354 [undefined, undefined],
355 "foo", 355 "foo",
356 [undefined, undefined]); 356 [undefined, undefined]);
357 357
358 // TODO(wingo): We should use TestGenerator for these, except that
359 // currently yield* will unconditionally propagate a throw() to the
360 // delegate iterator, which fails for these iterators that don't have
361 // throw(). See http://code.google.com/p/v8/issues/detail?id=3484.
362 (function() {
363 function* g28() {
364 yield* [1, 2, 3];
365 }
366 var iter = g28();
367 assertIteratorResult(1, false, iter.next());
368 assertIteratorResult(2, false, iter.next());
369 assertIteratorResult(3, false, iter.next());
370 assertIteratorResult(undefined, true, iter.next());
371 })();
372
373 (function() {
374 function* g29() {
375 yield* "abc";
376 }
377 var iter = g29();
378 assertIteratorResult("a", false, iter.next());
379 assertIteratorResult("b", false, iter.next());
380 assertIteratorResult("c", false, iter.next());
381 assertIteratorResult(undefined, true, iter.next());
382 })();
383
358 // Generator function instances. 384 // Generator function instances.
359 TestGenerator(GeneratorFunction(), 385 TestGenerator(GeneratorFunction(),
360 [undefined], 386 [undefined],
361 "foo", 387 "foo",
362 [undefined]); 388 [undefined]);
363 389
364 TestGenerator(new GeneratorFunction(), 390 TestGenerator(new GeneratorFunction(),
365 [undefined], 391 [undefined],
366 "foo", 392 "foo",
367 [undefined]); 393 [undefined]);
(...skipping 18 matching lines...) Expand all
386 "foo", 412 "foo",
387 [42, undefined]); 413 [42, undefined]);
388 414
389 // Test that yield* re-yields received results without re-boxing. 415 // Test that yield* re-yields received results without re-boxing.
390 function TestDelegatingYield() { 416 function TestDelegatingYield() {
391 function results(results) { 417 function results(results) {
392 var i = 0; 418 var i = 0;
393 function next() { 419 function next() {
394 return results[i++]; 420 return results[i++];
395 } 421 }
396 return { next: next } 422 var iter = { next: next };
423 var ret = {};
424 ret[Symbol.iterator] = function() { return iter; };
425 return ret;
397 } 426 }
398 function* yield_results(expected) { 427 function* yield_results(expected) {
399 return yield* results(expected); 428 return yield* results(expected);
400 } 429 }
401 function collect_results(iter) { 430 function collect_results(iterable) {
431 var iter = iterable[Symbol.iterator]();
402 var ret = []; 432 var ret = [];
403 var result; 433 var result;
404 do { 434 do {
405 result = iter.next(); 435 result = iter.next();
406 ret.push(result); 436 ret.push(result);
407 } while (!result.done); 437 } while (!result.done);
408 return ret; 438 return ret;
409 } 439 }
410 // We have to put a full result for the end, because the return will re-box. 440 // We have to put a full result for the end, because the return will re-box.
411 var expected = [{value: 1}, 13, "foo", {value: 34, done: true}]; 441 var expected = [{value: 1}, 13, "foo", {value: 34, done: true}];
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 function TestThrowRecursion() { 689 function TestThrowRecursion() {
660 function* g() { yield iter.throw(1); } 690 function* g() { yield iter.throw(1); }
661 var iter = g(); 691 var iter = g();
662 return iter.next(); 692 return iter.next();
663 } 693 }
664 assertThrows(TestNextRecursion, Error); 694 assertThrows(TestNextRecursion, Error);
665 assertThrows(TestSendRecursion, Error); 695 assertThrows(TestSendRecursion, Error);
666 assertThrows(TestThrowRecursion, Error); 696 assertThrows(TestThrowRecursion, Error);
667 } 697 }
668 TestRecursion(); 698 TestRecursion();
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698