michael@0: // This file was written by Andy Wingo and originally michael@0: // contributed to V8 as generators-objects.js, available here: michael@0: // michael@0: // http://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/harmony/generators-objects.js michael@0: michael@0: // Test that yield* re-yields received results without re-boxing. michael@0: michael@0: function results(results) { michael@0: var i = 0; michael@0: function next() { michael@0: return results[i++]; michael@0: } michael@0: var iter = { next: next } michael@0: var ret = {}; michael@0: ret[std_iterator] = function () { return iter; } michael@0: return ret; michael@0: } michael@0: michael@0: function* yield_results(expected) { michael@0: return yield* results(expected); michael@0: } michael@0: michael@0: function collect_results(iterable) { michael@0: var ret = []; michael@0: var result; michael@0: var iter = iterable[std_iterator](); michael@0: do { michael@0: result = iter.next(); michael@0: ret.push(result); michael@0: } while (!result.done); michael@0: return ret; michael@0: } michael@0: michael@0: // We have to put a full result for the end, because the return will re-box. michael@0: var expected = [{value: 1}, 13, "foo", {value: 34, done: true}]; michael@0: michael@0: // Sanity check. michael@0: assertDeepEq(expected, collect_results(results(expected))); michael@0: assertDeepEq(expected, collect_results(yield_results(expected))); michael@0: michael@0: if (typeof reportCompare == "function") michael@0: reportCompare(true, true);