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

Side by Side Diff: test/mjsunit/array-concat.js

Issue 6568007: Fix array concat to follow the specification in the presence of element getters. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge/build-ia32
Patch Set: git utd Created 9 years, 10 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 | « src/runtime.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 assertEquals("undefined", typeof(c.moe)); 94 assertEquals("undefined", typeof(c.moe));
95 95
96 // Negative indices don't get concated. 96 // Negative indices don't get concated.
97 a[-1] = 'minus1'; 97 a[-1] = 'minus1';
98 assertEquals("minus1", a[-1]); 98 assertEquals("minus1", a[-1]);
99 assertEquals("undefined", typeof(a[0xffffffff])); 99 assertEquals("undefined", typeof(a[0xffffffff]));
100 c = a.concat(b); 100 c = a.concat(b);
101 assertEquals("undefined", typeof(c[-1])); 101 assertEquals("undefined", typeof(c[-1]));
102 assertEquals("undefined", typeof(c[0xffffffff])); 102 assertEquals("undefined", typeof(c[0xffffffff]));
103 assertEquals(c.length, a.length + 1); 103 assertEquals(c.length, a.length + 1);
104
105 } 104 }
106 105
107 poses = [140, 4000000000]; 106 poses = [140, 4000000000];
108 while (pos = poses.shift()) { 107 while (pos = poses.shift()) {
109 var a = new Array(pos); 108 var a = new Array(pos);
110 assertEquals(pos, a.length); 109 assertEquals(pos, a.length);
111 a.push('foo'); 110 a.push('foo');
112 assertEquals(pos + 1, a.length); 111 assertEquals(pos + 1, a.length);
113 var b = ['bar']; 112 var b = ['bar'];
114 var c = a.concat(b); 113 var c = a.concat(b);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Check that concat preserves holes. 185 // Check that concat preserves holes.
187 var holey = [void 0,'a',,'c'].concat(['d',,'f',[0,,2],void 0]) 186 var holey = [void 0,'a',,'c'].concat(['d',,'f',[0,,2],void 0])
188 assertEquals(9, holey.length); // hole in embedded array is ignored 187 assertEquals(9, holey.length); // hole in embedded array is ignored
189 for (var i = 0; i < holey.length; i++) { 188 for (var i = 0; i < holey.length; i++) {
190 if (i == 2 || i == 5) { 189 if (i == 2 || i == 5) {
191 assertFalse(i in holey); 190 assertFalse(i in holey);
192 } else { 191 } else {
193 assertTrue(i in holey); 192 assertTrue(i in holey);
194 } 193 }
195 } 194 }
195
196 // Polluted prototype from prior tests.
197 delete Array.prototype[123];
198
199 // Check that concat reads getters in the correct order.
200 var arr1 = [,2];
201 var arr2 = [1,3];
202 var r1 = [].concat(arr1, arr2); // [,2,1,3]
203 assertEquals([,2,1,3], r1);
204
205 // Make first array change length of second array.
206 Object.defineProperty(arr1, 0, {get: function() {
207 arr2.push("X");
208 return undefined;
209 }, configurable: true})
210 var r2 = [].concat(arr1, arr2); // [undefined,2,1,3,"X"]
211 assertEquals([undefined,2,1,3,"X"], r2);
212
213 // Make first array change length of second array massively.
214 arr2.length = 2;
215 Object.defineProperty(arr1, 0, {get: function() {
216 arr2[500000] = "X";
217 return undefined;
218 }, configurable: true})
219 var r3 = [].concat(arr1, arr2); // [undefined,2,1,3,"X"]
220 var expected = [undefined,2,1,3];
221 expected[500000 + 2] = "X";
222
223 assertEquals(expected, r3);
224
225 var arr3 = [];
226 var trace = [];
227 var expectedTrace = []
228 function mkGetter(i) { return function() { trace.push(i); }; }
229 arr3.length = 10000;
230 for (var i = 0; i < 100; i++) {
231 Object.defineProperty(arr3, i * i, {get: mkGetter(i)});
232 expectedTrace[i] = i;
233 expectedTrace[100 + i] = i;
234 }
235 var r4 = [0].concat(arr3, arr3);
236 assertEquals(1 + arr3.length * 2, r4.length);
237 assertEquals(expectedTrace, trace);
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698