3 throw new Error("Bad assertion");
6 function test(f) { f(); }
8 function shallowEq(a, b) {
9 if (a.length !== b.length)
11 for (let i = 0; i < a.length; ++i) {
18 function makeArrayIterator(arr, f) {
25 return {value: arr[i++], done: false};
32 arr.__proto__ = {[Symbol.iterator]: Array.prototype[Symbol.iterator]};
38 for (let i = 0; i < 10000; i++) {
39 assert(shallowEq(bar(arr), arr));
51 [Symbol.iterator]: function() {
52 return makeArrayIterator(this, callback);
61 for (let i = 0; i < 10000; i++) {
65 assert(shallowEq(t, arr));
76 arr[Symbol.iterator] = function() {
77 return makeArrayIterator(this, callback);
85 for (let i = 0; i < 10000; i++) {
89 assert(shallowEq(t, arr));
95 arr[Symbol.iterator] = Array.prototype[Symbol.iterator];
101 for (let i = 0; i < 10000; i++) {
102 assert(shallowEq(bar(arr), arr));
109 Object.defineProperty(arr, 0, {get() { ++callCount; return 10; }});
115 for (let i = 0; i < 10000; i++) {
117 assert(callCount === 1);
118 assert(shallowEq(t, arr));
119 assert(callCount === 2);
124 // We run this test last since it fires watchpoints for the protocol.
126 let iter = [][Symbol.iterator]();
127 let iterProto = Object.getPrototypeOf(iter);
128 let oldNext = iterProto.next;
130 function hackedNext() {
131 let val = oldNext.call(this);
132 if ("value" in val) {
143 for (let i = 0; i < 10000; ++i) {
146 Object.defineProperty(arr, 1, { get: function() { ++callCount; iterProto.next = hackedNext; return 2; } });
148 assert(callCount === 1);
149 assert(t.length === 3);
153 iterProto.next = oldNext;