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

Side by Side Diff: test/mjsunit/es6/array-iterator.js

Issue 647703003: Don't expose Array.prototype.values as it breaks webcompat (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix tests Created 6 years, 2 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 | « test/mjsunit/es6/arguments-iterator.js ('k') | test/mjsunit/es6/typed-array-iterator.js » ('j') | 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
(...skipping 27 matching lines...) Expand all
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
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; i++) { 175 for (var i = 0; i < buffer.length; i++) {
179 assertSame(array[i], buffer[i]); 176 assertSame(array[i], buffer[i]);
180 } 177 }
181 } 178 }
182 TestForArrayValues(); 179 TestForArrayValues();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 229
233 for (var i = 0; i < buffer.length; i++) { 230 for (var i = 0; i < buffer.length; i++) {
234 assertSame(array[i], buffer[i]); 231 assertSame(array[i], buffer[i]);
235 } 232 }
236 } 233 }
237 TestForArrayValues(); 234 TestForArrayValues();
238 235
239 236
240 function TestNonOwnSlots() { 237 function TestNonOwnSlots() {
241 var array = [0]; 238 var array = [0];
242 var iterator = array.values(); 239 var iterator = array[Symbol.iterator]();
243 var object = {__proto__: iterator}; 240 var object = {__proto__: iterator};
244 241
245 assertThrows(function() { 242 assertThrows(function() {
246 object.next(); 243 object.next();
247 }, TypeError); 244 }, TypeError);
248 } 245 }
249 TestNonOwnSlots(); 246 TestNonOwnSlots();
OLDNEW
« no previous file with comments | « test/mjsunit/es6/arguments-iterator.js ('k') | test/mjsunit/es6/typed-array-iterator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698