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

Side by Side Diff: test/mjsunit/array-functions-prototype-misc.js

Issue 1260283002: Array Builtin Refactoring: Creating API methods on ElementsAccessor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: removing unused method Created 5 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
« no previous file with comments | « src/elements.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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // Test http://b/issue?id=1202711 305 // Test http://b/issue?id=1202711
306 arr = [0]; 306 arr = [0];
307 arr.length = 2; 307 arr.length = 2;
308 Array.prototype[1] = 1; 308 Array.prototype[1] = 1;
309 assertEquals(1, arr.pop()); 309 assertEquals(1, arr.pop());
310 assertEquals(0, arr.pop()); 310 assertEquals(0, arr.pop());
311 Array.prototype[1] = undefined; 311 Array.prototype[1] = undefined;
312 312
313 // Test http://code.google.com/p/chromium/issues/detail?id=21860 313 // Test http://code.google.com/p/chromium/issues/detail?id=21860
314 Array.prototype.push.apply([], [1].splice(0, -(-1 % 5))); 314 Array.prototype.push.apply([], [1].splice(0, -(-1 % 5)));
315
316
317 // Check that the Array functions work also properly on non-Arrays
318 var receiver;
319
320 receiver = 'a string';
321 assertThrows(function(){
322 Array.prototype.push.call(receiver);
323 });
324
325 receiver = 0;
326 assertEquals(undefined, receiver.length);
327 assertEquals(0, Array.prototype.push.call(receiver));
328 assertEquals(1, Array.prototype.push.call(receiver, 'first'));
329 assertEquals(undefined, receiver.length);
330
331 receiver = {};
332 assertEquals(undefined, receiver.length);
333 assertEquals(0, Array.prototype.push.call(receiver));
334 assertEquals(0, Array.prototype.push.call(receiver));
335 assertEquals(0, receiver.length);
336 assertEquals(1, Array.prototype.push.call(receiver, 'first'));
337 assertEquals(1, receiver.length);
338 assertEquals('first', receiver[0]);
339 assertEquals(2, Array.prototype.push.call(receiver, 'second'));
340 assertEquals(2, receiver.length);
341 assertEquals('first', receiver[0]);
342 assertEquals('second', receiver[1]);
343
344 receiver = {'length': 10};
345 assertEquals(10, Array.prototype.push.call(receiver));
346 assertEquals(10, receiver.length);
347 assertEquals(11, Array.prototype.push.call(receiver, 'first'));
348 assertEquals(11, receiver.length);
349 assertEquals('first', receiver[10]);
350 assertEquals(13, Array.prototype.push.call(receiver, 'second', 'third'));
351 assertEquals(13, receiver.length);
352 assertEquals('first', receiver[10]);
353 assertEquals('second', receiver[11]);
354 assertEquals('third', receiver[12]);
355
356 receiver = {
357 get length() { return 10; },
358 set length(l) {}
359 };
360 assertEquals(10, Array.prototype.push.call(receiver));
361 assertEquals(10, receiver.length);
362 assertEquals(11, Array.prototype.push.call(receiver, 'first'));
363 assertEquals(10, receiver.length);
364 assertEquals('first', receiver[10]);
365 assertEquals(12, Array.prototype.push.call(receiver, 'second', 'third'));
366 assertEquals(10, receiver.length);
367 assertEquals('second', receiver[10]);
368 assertEquals('third', receiver[11]);
369
370 // readonly length
371 receiver = {
372 get length() { return 10; },
373 };
374 assertThrows(function(){
375 Array.prototype.push.call(receiver);
376 });
377
378 receiver = {
379 set length(l) {}
380 };
381 assertEquals(0, Array.prototype.push.call(receiver));
382 assertEquals(undefined, receiver.length);
383 assertEquals(1, Array.prototype.push.call(receiver, 'first'));
384 assertEquals(undefined, receiver.length);
385 assertEquals(2, Array.prototype.push.call(receiver, 'third', 'second'));
386 assertEquals(undefined, receiver.length);
OLDNEW
« no previous file with comments | « src/elements.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698