|
1 // This file was written by Andy Wingo <wingo@igalia.com> and originally |
|
2 // contributed to V8 as generators-objects.js, available here: |
|
3 // |
|
4 // http://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/harmony/generators-objects.js |
|
5 |
|
6 // Test that yield* re-yields received results without re-boxing. |
|
7 |
|
8 function results(results) { |
|
9 var i = 0; |
|
10 function next() { |
|
11 return results[i++]; |
|
12 } |
|
13 var iter = { next: next } |
|
14 var ret = {}; |
|
15 ret[std_iterator] = function () { return iter; } |
|
16 return ret; |
|
17 } |
|
18 |
|
19 function* yield_results(expected) { |
|
20 return yield* results(expected); |
|
21 } |
|
22 |
|
23 function collect_results(iterable) { |
|
24 var ret = []; |
|
25 var result; |
|
26 var iter = iterable[std_iterator](); |
|
27 do { |
|
28 result = iter.next(); |
|
29 ret.push(result); |
|
30 } while (!result.done); |
|
31 return ret; |
|
32 } |
|
33 |
|
34 // We have to put a full result for the end, because the return will re-box. |
|
35 var expected = [{value: 1}, 13, "foo", {value: 34, done: true}]; |
|
36 |
|
37 // Sanity check. |
|
38 assertDeepEq(expected, collect_results(results(expected))); |
|
39 assertDeepEq(expected, collect_results(yield_results(expected))); |
|
40 |
|
41 if (typeof reportCompare == "function") |
|
42 reportCompare(true, true); |