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

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

Issue 455763002: Unship unscopables and disable array.values iterators (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Adjust BUILD.gn Created 6 years, 4 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/cctest/test-unscopables-hidden-prototype.cc ('k') | test/mjsunit/es6/symbols.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); 48 // TODO(arv): Reenable once @@unscopables are shipping.
49 // assertHasOwnProperty(Array.prototype, 'values', DONT_ENUM);
49 assertHasOwnProperty(Array.prototype, 'keys', DONT_ENUM); 50 assertHasOwnProperty(Array.prototype, 'keys', DONT_ENUM);
50 assertHasOwnProperty(Array.prototype, Symbol.iterator, DONT_ENUM); 51 assertHasOwnProperty(Array.prototype, Symbol.iterator, DONT_ENUM);
51 52
52 assertEquals(Array.prototype.values, Array.prototype[Symbol.iterator]); 53 // TODO(arv): Reenable once @@unscopables are shipping.
54 // assertEquals(Array.prototype.values, Array.prototype[Symbol.iterator]);
53 } 55 }
54 TestArrayPrototype(); 56 TestArrayPrototype();
55 57
56 58
57 function assertIteratorResult(value, done, result) { 59 function assertIteratorResult(value, done, result) {
58 assertEquals({value: value, done: done}, result); 60 assertEquals({value: value, done: done}, result);
59 } 61 }
60 62
61 63
62 function TestValues() { 64 function TestValues() {
63 var array = ['a', 'b', 'c']; 65 var array = ['a', 'b', 'c'];
64 var iterator = array.values(); 66 var iterator = array.values();
65 assertIteratorResult('a', false, iterator.next()); 67 assertIteratorResult('a', false, iterator.next());
66 assertIteratorResult('b', false, iterator.next()); 68 assertIteratorResult('b', false, iterator.next());
67 assertIteratorResult('c', false, iterator.next()); 69 assertIteratorResult('c', false, iterator.next());
68 assertIteratorResult(void 0, true, iterator.next()); 70 assertIteratorResult(void 0, true, iterator.next());
69 71
70 array.push('d'); 72 array.push('d');
71 assertIteratorResult(void 0, true, iterator.next()); 73 assertIteratorResult(void 0, true, iterator.next());
72 } 74 }
73 TestValues(); 75 // TODO(arv): Reenable once @@unscopables are shipping.
76 // TestValues();
74 77
75 78
76 function TestValuesMutate() { 79 function TestValuesMutate() {
77 var array = ['a', 'b', 'c']; 80 var array = ['a', 'b', 'c'];
78 var iterator = array.values(); 81 var iterator = array.values();
79 assertIteratorResult('a', false, iterator.next()); 82 assertIteratorResult('a', false, iterator.next());
80 assertIteratorResult('b', false, iterator.next()); 83 assertIteratorResult('b', false, iterator.next());
81 assertIteratorResult('c', false, iterator.next()); 84 assertIteratorResult('c', false, iterator.next());
82 array.push('d'); 85 array.push('d');
83 assertIteratorResult('d', false, iterator.next()); 86 assertIteratorResult('d', false, iterator.next());
84 assertIteratorResult(void 0, true, iterator.next()); 87 assertIteratorResult(void 0, true, iterator.next());
85 } 88 }
86 TestValuesMutate(); 89 // TODO(arv): Reenable once @@unscopables are shipping.
90 // TestValuesMutate();
87 91
88 92
89 function TestKeys() { 93 function TestKeys() {
90 var array = ['a', 'b', 'c']; 94 var array = ['a', 'b', 'c'];
91 var iterator = array.keys(); 95 var iterator = array.keys();
92 assertIteratorResult(0, false, iterator.next()); 96 assertIteratorResult(0, false, iterator.next());
93 assertIteratorResult(1, false, iterator.next()); 97 assertIteratorResult(1, false, iterator.next());
94 assertIteratorResult(2, false, iterator.next()); 98 assertIteratorResult(2, false, iterator.next());
95 assertIteratorResult(void 0, true, iterator.next()); 99 assertIteratorResult(void 0, true, iterator.next());
96 100
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 assertIteratorResult([2, 'c'], false, iterator.next()); 139 assertIteratorResult([2, 'c'], false, iterator.next());
136 array.push('d'); 140 array.push('d');
137 assertIteratorResult([3, 'd'], false, iterator.next()); 141 assertIteratorResult([3, 'd'], false, iterator.next());
138 assertIteratorResult(void 0, true, iterator.next()); 142 assertIteratorResult(void 0, true, iterator.next());
139 } 143 }
140 TestEntriesMutate(); 144 TestEntriesMutate();
141 145
142 146
143 function TestArrayIteratorPrototype() { 147 function TestArrayIteratorPrototype() {
144 var array = []; 148 var array = [];
145 var iterator = array.values(); 149 var iterator = array.entries();
146 150
147 var ArrayIteratorPrototype = iterator.__proto__; 151 var ArrayIteratorPrototype = iterator.__proto__;
148 152
149 assertEquals(ArrayIteratorPrototype, array.values().__proto__); 153 // TODO(arv): Reenable once @@unscopables are shipping.
154 // assertEquals(ArrayIteratorPrototype, array.values().__proto__);
150 assertEquals(ArrayIteratorPrototype, array.keys().__proto__); 155 assertEquals(ArrayIteratorPrototype, array.keys().__proto__);
151 assertEquals(ArrayIteratorPrototype, array.entries().__proto__); 156 assertEquals(ArrayIteratorPrototype, array.entries().__proto__);
152 157
153 assertEquals(Object.prototype, ArrayIteratorPrototype.__proto__); 158 assertEquals(Object.prototype, ArrayIteratorPrototype.__proto__);
154 159
155 assertEquals('Array Iterator', %_ClassOf(array.values())); 160 // TODO(arv): Reenable once @@unscopables are shipping.
161 // assertEquals('Array Iterator', %_ClassOf(array.values()));
156 assertEquals('Array Iterator', %_ClassOf(array.keys())); 162 assertEquals('Array Iterator', %_ClassOf(array.keys()));
157 assertEquals('Array Iterator', %_ClassOf(array.entries())); 163 assertEquals('Array Iterator', %_ClassOf(array.entries()));
158 164
159 assertFalse(ArrayIteratorPrototype.hasOwnProperty('constructor')); 165 assertFalse(ArrayIteratorPrototype.hasOwnProperty('constructor'));
160 assertArrayEquals(['next'], 166 assertArrayEquals(['next'],
161 Object.getOwnPropertyNames(ArrayIteratorPrototype)); 167 Object.getOwnPropertyNames(ArrayIteratorPrototype));
162 assertHasOwnProperty(ArrayIteratorPrototype, 'next', DONT_ENUM); 168 assertHasOwnProperty(ArrayIteratorPrototype, 'next', DONT_ENUM);
163 assertHasOwnProperty(ArrayIteratorPrototype, Symbol.iterator, DONT_ENUM); 169 assertHasOwnProperty(ArrayIteratorPrototype, Symbol.iterator, DONT_ENUM);
164 } 170 }
165 TestArrayIteratorPrototype(); 171 TestArrayIteratorPrototype();
166 172
167 173
168 function TestForArrayValues() { 174 function TestForArrayValues() {
169 var buffer = []; 175 var buffer = [];
170 var array = [0, 'a', true, false, null, /* hole */, undefined, NaN]; 176 var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];
171 var i = 0; 177 var i = 0;
172 for (var value of array.values()) { 178 for (var value of array.values()) {
173 buffer[i++] = value; 179 buffer[i++] = value;
174 } 180 }
175 181
176 assertEquals(8, buffer.length); 182 assertEquals(8, buffer.length);
177 183
178 for (var i = 0; i < buffer.length - 1; i++) { 184 for (var i = 0; i < buffer.length - 1; i++) {
179 assertSame(array[i], buffer[i]); 185 assertSame(array[i], buffer[i]);
180 } 186 }
181 assertTrue(isNaN(buffer[buffer.length - 1])); 187 assertTrue(isNaN(buffer[buffer.length - 1]));
182 } 188 }
183 TestForArrayValues(); 189 // TODO(arv): Reenable once @@unscopables are shipping.
190 // TestForArrayValues();
184 191
185 192
186 function TestForArrayKeys() { 193 function TestForArrayKeys() {
187 var buffer = []; 194 var buffer = [];
188 var array = [0, 'a', true, false, null, /* hole */, undefined, NaN]; 195 var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];
189 var i = 0; 196 var i = 0;
190 for (var key of array.keys()) { 197 for (var key of array.keys()) {
191 buffer[i++] = key; 198 buffer[i++] = key;
192 } 199 }
193 200
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 buffer[i++] = value; 237 buffer[i++] = value;
231 } 238 }
232 239
233 assertEquals(8, buffer.length); 240 assertEquals(8, buffer.length);
234 241
235 for (var i = 0; i < buffer.length - 1; i++) { 242 for (var i = 0; i < buffer.length - 1; i++) {
236 assertSame(array[i], buffer[i]); 243 assertSame(array[i], buffer[i]);
237 } 244 }
238 assertTrue(isNaN(buffer[buffer.length - 1])); 245 assertTrue(isNaN(buffer[buffer.length - 1]));
239 } 246 }
240 TestForArrayValues(); 247 TestForArray();
241 248
242 249
243 function TestNonOwnSlots() { 250 function TestNonOwnSlots() {
244 var array = [0]; 251 var array = [0];
245 var iterator = array.values(); 252 var iterator = array.entries();
246 var object = {__proto__: iterator}; 253 var object = {__proto__: iterator};
247 254
248 assertThrows(function() { 255 assertThrows(function() {
249 object.next(); 256 object.next();
250 }, TypeError); 257 }, TypeError);
251 } 258 }
252 TestNonOwnSlots(); 259 TestNonOwnSlots();
OLDNEW
« no previous file with comments | « test/cctest/test-unscopables-hidden-prototype.cc ('k') | test/mjsunit/es6/symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698