OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 } | 397 } |
398 var arr = [o(1), o(2), o(4), o(8), o(16), o(32), o(64), o(128), o(256), o(-0)]; | 398 var arr = [o(1), o(2), o(4), o(8), o(16), o(32), o(64), o(128), o(256), o(-0)]; |
399 var global = this; | 399 var global = this; |
400 function cmpTest(a, b) { | 400 function cmpTest(a, b) { |
401 assertEquals(global, this); | 401 assertEquals(global, this); |
402 assertTrue(a instanceof o); | 402 assertTrue(a instanceof o); |
403 assertTrue(b instanceof o); | 403 assertTrue(b instanceof o); |
404 return a.val - b.val; | 404 return a.val - b.val; |
405 } | 405 } |
406 arr.sort(cmpTest); | 406 arr.sort(cmpTest); |
407 | |
408 function TestSortDoesntDependOnObjectPrototypeHasOwnProperty() { | |
409 Array.prototype.sort.call({__proto__: { hasOwnProperty: null, 0: 1 }, | |
arv (Not doing code reviews)
2014/09/15 18:05:28
Array.prototype.sort.call({
__proto__: { hasOwnP
| |
410 length: 5}); | |
411 | |
412 var arr = []; | |
413 Object.defineProperty(arr, "0", {}); | |
arv (Not doing code reviews)
2014/09/15 18:05:28
Now I'm confused again ;-)
Don't we treat the '0'
Diego Pino
2014/09/16 09:56:38
Yes, it's the same to use '0' or 0 in this case.
| |
414 arr.hasOwnProperty = null; | |
415 arr.sort(); | |
416 } | |
417 | |
418 TestSortDoesntDependOnObjectPrototypeHasOwnProperty(); | |
419 | |
420 function TestSortDoesntDepenOnArrayPrototypePush() { | |
wingo
2014/09/16 08:47:48
"Depend". Also better to write out DoesNot instea
| |
421 // InsertionSort is used for arrays which length <= 22 | |
422 var arr = []; | |
423 for (var i = 0; i < 22; i++) arr[i] = {}; | |
424 Array.prototype.push = function() { | |
425 fail('Should not call push'); | |
arv (Not doing code reviews)
2014/09/15 18:05:28
indent 2 spaces.
| |
426 } | |
arv (Not doing code reviews)
2014/09/15 18:05:28
;
| |
427 arr.sort(); | |
428 | |
429 // Quicksort is used for arrays which length > 22 | |
430 // Arrays which length > 1000 guarantee GetThirdIndex is executed | |
431 arr = []; | |
432 for (var i = 0; i < 2000; ++i) arr[i] = {}; | |
433 arr.sort(); | |
434 } | |
435 | |
436 TestSortDoesntDepenOnArrayPrototypePush(); | |
437 | |
438 function TestSortDoesntDepenOnArrayPrototypeSort() { | |
439 var arr = []; | |
440 for (var i = 0; i < 2000; i++) arr[i] = {}; | |
441 var sortfn = Array.prototype.sort; | |
442 Array.prototype.sort = function() { | |
443 fail('Should not call sort'); | |
444 } | |
arv (Not doing code reviews)
2014/09/15 18:05:28
;
| |
445 sortfn.call(arr); | |
446 } | |
447 | |
448 TestSortDoesntDepenOnArrayPrototypeSort(); | |
OLD | NEW |