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 TestSortDoesNotDependOnObjectPrototypeHasOwnProperty() { | |
409 Array.prototype.sort.call({ | |
410 __proto__: { hasOwnProperty: null, 0: 1 }, | |
411 length: 5 | |
412 }); | |
413 | |
414 var arr = new Array(2); | |
415 Object.defineProperty(arr, 0, { get: function() {}, set: function() {} }); | |
416 arr.hasOwnProperty = null; | |
417 arr.sort(); | |
418 } | |
419 | |
wingo
2014/09/16 12:11:53
I think the style is to join the invocation with t
Diego Pino
2014/09/16 13:23:20
OK, this is actually two tests that both have to d
arv (Not doing code reviews)
2014/09/16 13:41:09
It is fine to keep them in one function.
I believ
| |
420 TestSortDoesNotDependOnObjectPrototypeHasOwnProperty(); | |
421 | |
422 function TestSortDoesNotDependOnArrayPrototypePush() { | |
423 // InsertionSort is used for arrays which length <= 22 | |
424 var arr = []; | |
425 for (var i = 0; i < 22; i++) arr[i] = {}; | |
426 Array.prototype.push = function() { | |
427 fail('Should not call push'); | |
428 }; | |
429 arr.sort(); | |
430 | |
431 // Quicksort is used for arrays which length > 22 | |
432 // Arrays which length > 1000 guarantee GetThirdIndex is executed | |
433 arr = []; | |
434 for (var i = 0; i < 2000; ++i) arr[i] = {}; | |
435 arr.sort(); | |
436 } | |
437 | |
438 TestSortDoesNotDependOnArrayPrototypePush(); | |
439 | |
440 function TestSortDoesNotDependOnArrayPrototypeSort() { | |
441 var arr = []; | |
442 for (var i = 0; i < 2000; i++) arr[i] = {}; | |
443 var sortfn = Array.prototype.sort; | |
444 Array.prototype.sort = function() { | |
445 fail('Should not call sort'); | |
446 }; | |
447 sortfn.call(arr); | |
448 } | |
449 | |
450 TestSortDoesNotDependOnArrayPrototypeSort(); | |
OLD | NEW |