| OLD | NEW |
| 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 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 assertTrue(object.hasOwnProperty(name)); | 38 assertTrue(object.hasOwnProperty(name)); |
| 39 var desc = Object.getOwnPropertyDescriptor(object, name); | 39 var desc = Object.getOwnPropertyDescriptor(object, name); |
| 40 assertEquals(desc.writable, !(attrs & READ_ONLY)); | 40 assertEquals(desc.writable, !(attrs & READ_ONLY)); |
| 41 assertEquals(desc.enumerable, !(attrs & DONT_ENUM)); | 41 assertEquals(desc.enumerable, !(attrs & DONT_ENUM)); |
| 42 assertEquals(desc.configurable, !(attrs & DONT_DELETE)); | 42 assertEquals(desc.configurable, !(attrs & DONT_DELETE)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 | 45 |
| 46 function TestArrayPrototype() { | 46 function TestArrayPrototype() { |
| 47 assertHasOwnProperty(Array.prototype, 'entries', DONT_ENUM); | 47 assertHasOwnProperty(Array.prototype, 'entries', DONT_ENUM); |
| 48 assertHasOwnProperty(Array.prototype, 'values', DONT_ENUM); | |
| 49 assertHasOwnProperty(Array.prototype, 'keys', DONT_ENUM); | 48 assertHasOwnProperty(Array.prototype, 'keys', DONT_ENUM); |
| 50 assertHasOwnProperty(Array.prototype, Symbol.iterator, DONT_ENUM); | 49 assertHasOwnProperty(Array.prototype, Symbol.iterator, DONT_ENUM); |
| 51 | |
| 52 assertEquals(Array.prototype.values, Array.prototype[Symbol.iterator]); | |
| 53 } | 50 } |
| 54 TestArrayPrototype(); | 51 TestArrayPrototype(); |
| 55 | 52 |
| 56 | 53 |
| 57 function assertIteratorResult(value, done, result) { | 54 function assertIteratorResult(value, done, result) { |
| 58 assertEquals({value: value, done: done}, result); | 55 assertEquals({value: value, done: done}, result); |
| 59 } | 56 } |
| 60 | 57 |
| 61 | 58 |
| 62 function TestValues() { | 59 function TestValues() { |
| 63 var array = ['a', 'b', 'c']; | 60 var array = ['a', 'b', 'c']; |
| 64 var iterator = array.values(); | 61 var iterator = array[Symbol.iterator](); |
| 65 assertIteratorResult('a', false, iterator.next()); | 62 assertIteratorResult('a', false, iterator.next()); |
| 66 assertIteratorResult('b', false, iterator.next()); | 63 assertIteratorResult('b', false, iterator.next()); |
| 67 assertIteratorResult('c', false, iterator.next()); | 64 assertIteratorResult('c', false, iterator.next()); |
| 68 assertIteratorResult(void 0, true, iterator.next()); | 65 assertIteratorResult(void 0, true, iterator.next()); |
| 69 | 66 |
| 70 array.push('d'); | 67 array.push('d'); |
| 71 assertIteratorResult(void 0, true, iterator.next()); | 68 assertIteratorResult(void 0, true, iterator.next()); |
| 72 } | 69 } |
| 73 TestValues(); | 70 TestValues(); |
| 74 | 71 |
| 75 | 72 |
| 76 function TestValuesMutate() { | 73 function TestValuesMutate() { |
| 77 var array = ['a', 'b', 'c']; | 74 var array = ['a', 'b', 'c']; |
| 78 var iterator = array.values(); | 75 var iterator = array[Symbol.iterator](); |
| 79 assertIteratorResult('a', false, iterator.next()); | 76 assertIteratorResult('a', false, iterator.next()); |
| 80 assertIteratorResult('b', false, iterator.next()); | 77 assertIteratorResult('b', false, iterator.next()); |
| 81 assertIteratorResult('c', false, iterator.next()); | 78 assertIteratorResult('c', false, iterator.next()); |
| 82 array.push('d'); | 79 array.push('d'); |
| 83 assertIteratorResult('d', false, iterator.next()); | 80 assertIteratorResult('d', false, iterator.next()); |
| 84 assertIteratorResult(void 0, true, iterator.next()); | 81 assertIteratorResult(void 0, true, iterator.next()); |
| 85 } | 82 } |
| 86 TestValuesMutate(); | 83 TestValuesMutate(); |
| 87 | 84 |
| 88 | 85 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 assertIteratorResult([2, 'c'], false, iterator.next()); | 132 assertIteratorResult([2, 'c'], false, iterator.next()); |
| 136 array.push('d'); | 133 array.push('d'); |
| 137 assertIteratorResult([3, 'd'], false, iterator.next()); | 134 assertIteratorResult([3, 'd'], false, iterator.next()); |
| 138 assertIteratorResult(void 0, true, iterator.next()); | 135 assertIteratorResult(void 0, true, iterator.next()); |
| 139 } | 136 } |
| 140 TestEntriesMutate(); | 137 TestEntriesMutate(); |
| 141 | 138 |
| 142 | 139 |
| 143 function TestArrayIteratorPrototype() { | 140 function TestArrayIteratorPrototype() { |
| 144 var array = []; | 141 var array = []; |
| 145 var iterator = array.values(); | 142 var iterator = array.keys(); |
| 146 | 143 |
| 147 var ArrayIteratorPrototype = iterator.__proto__; | 144 var ArrayIteratorPrototype = iterator.__proto__; |
| 148 | 145 |
| 149 assertEquals(ArrayIteratorPrototype, array.values().__proto__); | 146 assertEquals(ArrayIteratorPrototype, array[Symbol.iterator]().__proto__); |
| 150 assertEquals(ArrayIteratorPrototype, array.keys().__proto__); | 147 assertEquals(ArrayIteratorPrototype, array.keys().__proto__); |
| 151 assertEquals(ArrayIteratorPrototype, array.entries().__proto__); | 148 assertEquals(ArrayIteratorPrototype, array.entries().__proto__); |
| 152 | 149 |
| 153 assertEquals(Object.prototype, ArrayIteratorPrototype.__proto__); | 150 assertEquals(Object.prototype, ArrayIteratorPrototype.__proto__); |
| 154 | 151 |
| 155 assertEquals('Array Iterator', %_ClassOf(array.values())); | 152 assertEquals('Array Iterator', %_ClassOf(array[Symbol.iterator]())); |
| 156 assertEquals('Array Iterator', %_ClassOf(array.keys())); | 153 assertEquals('Array Iterator', %_ClassOf(array.keys())); |
| 157 assertEquals('Array Iterator', %_ClassOf(array.entries())); | 154 assertEquals('Array Iterator', %_ClassOf(array.entries())); |
| 158 | 155 |
| 159 assertFalse(ArrayIteratorPrototype.hasOwnProperty('constructor')); | 156 assertFalse(ArrayIteratorPrototype.hasOwnProperty('constructor')); |
| 160 assertArrayEquals(['next'], | 157 assertArrayEquals(['next'], |
| 161 Object.getOwnPropertyNames(ArrayIteratorPrototype)); | 158 Object.getOwnPropertyNames(ArrayIteratorPrototype)); |
| 162 assertHasOwnProperty(ArrayIteratorPrototype, 'next', DONT_ENUM); | 159 assertHasOwnProperty(ArrayIteratorPrototype, 'next', DONT_ENUM); |
| 163 assertHasOwnProperty(ArrayIteratorPrototype, Symbol.iterator, DONT_ENUM); | 160 assertHasOwnProperty(ArrayIteratorPrototype, Symbol.iterator, DONT_ENUM); |
| 164 } | 161 } |
| 165 TestArrayIteratorPrototype(); | 162 TestArrayIteratorPrototype(); |
| 166 | 163 |
| 167 | 164 |
| 168 function TestForArrayValues() { | 165 function TestForArrayValues() { |
| 169 var buffer = []; | 166 var buffer = []; |
| 170 var array = [0, 'a', true, false, null, /* hole */, undefined, NaN]; | 167 var array = [0, 'a', true, false, null, /* hole */, undefined, NaN]; |
| 171 var i = 0; | 168 var i = 0; |
| 172 for (var value of array.values()) { | 169 for (var value of array[Symbol.iterator]()) { |
| 173 buffer[i++] = value; | 170 buffer[i++] = value; |
| 174 } | 171 } |
| 175 | 172 |
| 176 assertEquals(8, buffer.length); | 173 assertEquals(8, buffer.length); |
| 177 | 174 |
| 178 for (var i = 0; i < buffer.length - 1; i++) { | 175 for (var i = 0; i < buffer.length - 1; i++) { |
| 179 assertSame(array[i], buffer[i]); | 176 assertSame(array[i], buffer[i]); |
| 180 } | 177 } |
| 181 assertTrue(isNaN(buffer[buffer.length - 1])); | 178 assertTrue(isNaN(buffer[buffer.length - 1])); |
| 182 } | 179 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 for (var i = 0; i < buffer.length - 1; i++) { | 232 for (var i = 0; i < buffer.length - 1; i++) { |
| 236 assertSame(array[i], buffer[i]); | 233 assertSame(array[i], buffer[i]); |
| 237 } | 234 } |
| 238 assertTrue(isNaN(buffer[buffer.length - 1])); | 235 assertTrue(isNaN(buffer[buffer.length - 1])); |
| 239 } | 236 } |
| 240 TestForArrayValues(); | 237 TestForArrayValues(); |
| 241 | 238 |
| 242 | 239 |
| 243 function TestNonOwnSlots() { | 240 function TestNonOwnSlots() { |
| 244 var array = [0]; | 241 var array = [0]; |
| 245 var iterator = array.values(); | 242 var iterator = array[Symbol.iterator](); |
| 246 var object = {__proto__: iterator}; | 243 var object = {__proto__: iterator}; |
| 247 | 244 |
| 248 assertThrows(function() { | 245 assertThrows(function() { |
| 249 object.next(); | 246 object.next(); |
| 250 }, TypeError); | 247 }, TypeError); |
| 251 } | 248 } |
| 252 TestNonOwnSlots(); | 249 TestNonOwnSlots(); |
| OLD | NEW |