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

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

Issue 22715004: Version 3.20.15 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Add TypedArray API and correctness patches r16033 and r16084 Created 7 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/mjsunit/harmony/array-findindex.js ('k') | test/mjsunit/harmony/object-observe.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 21 matching lines...) Expand all
32 assertTrue(Array.prototype.hasOwnProperty('values')); 32 assertTrue(Array.prototype.hasOwnProperty('values'));
33 assertTrue(Array.prototype.hasOwnProperty('keys')); 33 assertTrue(Array.prototype.hasOwnProperty('keys'));
34 34
35 assertFalse(Array.prototype.propertyIsEnumerable('entries')); 35 assertFalse(Array.prototype.propertyIsEnumerable('entries'));
36 assertFalse(Array.prototype.propertyIsEnumerable('values')); 36 assertFalse(Array.prototype.propertyIsEnumerable('values'));
37 assertFalse(Array.prototype.propertyIsEnumerable('keys')); 37 assertFalse(Array.prototype.propertyIsEnumerable('keys'));
38 } 38 }
39 TestArrayPrototype(); 39 TestArrayPrototype();
40 40
41 function assertIteratorResult(value, done, result) { 41 function assertIteratorResult(value, done, result) {
42 assertEquals({value: value, done: done}, result); 42 assertEquals({ value: value, done: done}, result);
43 } 43 }
44 44
45 function TestValues() { 45 function TestValues() {
46 var array = ['a', 'b', 'c']; 46 var array = ['a', 'b', 'c'];
47 var iterator = array.values(); 47 var iterator = array.values();
48 assertIteratorResult('a', false, iterator.next()); 48 assertIteratorResult('a', false, iterator.next());
49 assertIteratorResult('b', false, iterator.next()); 49 assertIteratorResult('b', false, iterator.next());
50 assertIteratorResult('c', false, iterator.next()); 50 assertIteratorResult('c', false, iterator.next());
51 assertIteratorResult(void 0, true, iterator.next()); 51 assertIteratorResult(void 0, true, iterator.next());
52 52
(...skipping 10 matching lines...) Expand all
63 assertIteratorResult('c', false, iterator.next()); 63 assertIteratorResult('c', false, iterator.next());
64 array.push('d'); 64 array.push('d');
65 assertIteratorResult('d', false, iterator.next()); 65 assertIteratorResult('d', false, iterator.next());
66 assertIteratorResult(void 0, true, iterator.next()); 66 assertIteratorResult(void 0, true, iterator.next());
67 } 67 }
68 TestValuesMutate(); 68 TestValuesMutate();
69 69
70 function TestKeys() { 70 function TestKeys() {
71 var array = ['a', 'b', 'c']; 71 var array = ['a', 'b', 'c'];
72 var iterator = array.keys(); 72 var iterator = array.keys();
73 assertIteratorResult(0, false, iterator.next()); 73 assertIteratorResult('0', false, iterator.next());
74 assertIteratorResult(1, false, iterator.next()); 74 assertIteratorResult('1', false, iterator.next());
75 assertIteratorResult(2, false, iterator.next()); 75 assertIteratorResult('2', false, iterator.next());
76 assertIteratorResult(void 0, true, iterator.next()); 76 assertIteratorResult(void 0, true, iterator.next());
77 77
78 array.push('d'); 78 array.push('d');
79 assertIteratorResult(void 0, true, iterator.next()); 79 assertIteratorResult(void 0, true, iterator.next());
80 } 80 }
81 TestKeys(); 81 TestKeys();
82 82
83 function TestKeysMutate() { 83 function TestKeysMutate() {
84 var array = ['a', 'b', 'c']; 84 var array = ['a', 'b', 'c'];
85 var iterator = array.keys(); 85 var iterator = array.keys();
86 assertIteratorResult(0, false, iterator.next()); 86 assertIteratorResult('0', false, iterator.next());
87 assertIteratorResult(1, false, iterator.next()); 87 assertIteratorResult('1', false, iterator.next());
88 assertIteratorResult(2, false, iterator.next()); 88 assertIteratorResult('2', false, iterator.next());
89 array.push('d'); 89 array.push('d');
90 assertIteratorResult(3, false, iterator.next()); 90 assertIteratorResult('3', false, iterator.next());
91 assertIteratorResult(void 0, true, iterator.next()); 91 assertIteratorResult(void 0, true, iterator.next());
92 } 92 }
93 TestKeysMutate(); 93 TestKeysMutate();
94 94
95 function TestEntries() { 95 function TestEntries() {
96 var array = ['a', 'b', 'c']; 96 var array = ['a', 'b', 'c'];
97 var iterator = array.entries(); 97 var iterator = array.entries();
98 assertIteratorResult([0, 'a'], false, iterator.next()); 98 assertIteratorResult(['0', 'a'], false, iterator.next());
99 assertIteratorResult([1, 'b'], false, iterator.next()); 99 assertIteratorResult(['1', 'b'], false, iterator.next());
100 assertIteratorResult([2, 'c'], false, iterator.next()); 100 assertIteratorResult(['2', 'c'], false, iterator.next());
101 assertIteratorResult(void 0, true, iterator.next()); 101 assertIteratorResult(void 0, true, iterator.next());
102 102
103 array.push('d'); 103 array.push('d');
104 assertIteratorResult(void 0, true, iterator.next()); 104 assertIteratorResult(void 0, true, iterator.next());
105 } 105 }
106 TestEntries(); 106 TestEntries();
107 107
108 function TestEntriesMutate() { 108 function TestEntriesMutate() {
109 var array = ['a', 'b', 'c']; 109 var array = ['a', 'b', 'c'];
110 var iterator = array.entries(); 110 var iterator = array.entries();
111 assertIteratorResult([0, 'a'], false, iterator.next()); 111 assertIteratorResult(['0', 'a'], false, iterator.next());
112 assertIteratorResult([1, 'b'], false, iterator.next()); 112 assertIteratorResult(['1', 'b'], false, iterator.next());
113 assertIteratorResult([2, 'c'], false, iterator.next()); 113 assertIteratorResult(['2', 'c'], false, iterator.next());
114 array.push('d'); 114 array.push('d');
115 assertIteratorResult([3, 'd'], false, iterator.next()); 115 assertIteratorResult(['3', 'd'], false, iterator.next());
116 assertIteratorResult(void 0, true, iterator.next()); 116 assertIteratorResult(void 0, true, iterator.next());
117 } 117 }
118 TestEntriesMutate(); 118 TestEntriesMutate();
119 119
120 function TestArrayIteratorPrototype() { 120 function TestArrayIteratorPrototype() {
121 var array = []; 121 var array = [];
122 var iterator = array.values(); 122 var iterator = array.values();
123 123
124 var ArrayIterator = iterator.constructor; 124 var ArrayIterator = iterator.constructor;
125 assertEquals(ArrayIterator.prototype, array.values().__proto__); 125 assertEquals(ArrayIterator.prototype, array.values().__proto__);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 var buffer = []; 161 var buffer = [];
162 var array = [0, 'a', true, false, null, /* hole */, undefined, NaN]; 162 var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];
163 var i = 0; 163 var i = 0;
164 for (var key of array.keys()) { 164 for (var key of array.keys()) {
165 buffer[i++] = key; 165 buffer[i++] = key;
166 } 166 }
167 167
168 assertEquals(8, buffer.length); 168 assertEquals(8, buffer.length);
169 169
170 for (var i = 0; i < buffer.length; i++) { 170 for (var i = 0; i < buffer.length; i++) {
171 assertEquals(i, buffer[i]); 171 assertEquals(String(i), buffer[i]);
172 } 172 }
173 } 173 }
174 TestForArrayKeys(); 174 TestForArrayKeys();
175 175
176 function TestForArrayEntries() { 176 function TestForArrayEntries() {
177 var buffer = []; 177 var buffer = [];
178 var array = [0, 'a', true, false, null, /* hole */, undefined, NaN]; 178 var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];
179 var i = 0; 179 var i = 0;
180 for (var entry of array.entries()) { 180 for (var entry of array.entries()) {
181 buffer[i++] = entry; 181 buffer[i++] = entry;
182 } 182 }
183 183
184 assertEquals(8, buffer.length); 184 assertEquals(8, buffer.length);
185 185
186 for (var i = 0; i < buffer.length - 1; i++) { 186 for (var i = 0; i < buffer.length - 1; i++) {
187 assertEquals(array[i], buffer[i][1]); 187 assertEquals(array[i], buffer[i][1]);
188 } 188 }
189 assertTrue(isNaN(buffer[buffer.length - 1][1])); 189 assertTrue(isNaN(buffer[buffer.length - 1][1]));
190 190
191 for (var i = 0; i < buffer.length; i++) { 191 for (var i = 0; i < buffer.length; i++) {
192 assertEquals(i, buffer[i][0]); 192 assertEquals(String(i), buffer[i][0]);
193 } 193 }
194 } 194 }
195 TestForArrayEntries(); 195 TestForArrayEntries();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/array-findindex.js ('k') | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698