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...) 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 // Test sort doesn't depend on Object.prototype.hasOwnProperty. Otherwise a | |
arv (Not doing code reviews)
2014/09/15 15:32:47
You can remove this comment. The name and the code
| |
409 // TypeError Exception will be thrown when running sort(). | |
410 function TestSortDoesntDependOnObjectPrototypeHasOwnProperty() | |
411 { | |
arv (Not doing code reviews)
2014/09/15 15:32:47
no newline before {
| |
412 Array.prototype.sort.call({__proto__: { hasOwnProperty: null, 0: 1 }, length: 5}); | |
arv (Not doing code reviews)
2014/09/15 15:32:47
long line
| |
413 | |
414 var arr = new Array(2); | |
415 Object.defineProperty(arr, "0", { get: function() {}, set: function() {}, | |
arv (Not doing code reviews)
2014/09/15 15:32:47
Why the strange 0 property? It does not seem relev
| |
416 configurable: true}); | |
417 arr.hasOwnProperty = null; | |
418 arr.sort(); | |
419 } | |
420 | |
421 TestSortDoesntDependOnObjectPrototypeHasOwnProperty(); | |
422 | |
423 // Test sort doesn't depend on Array.prototype.push. Otherwise a TypeError | |
424 // Exception will be thrown when running sort(). | |
425 function TestSortDoesntDepenOnArrayPrototypePush() | |
426 { | |
427 // InsertionSort is used for arrays which length <= 22 | |
428 var arr = []; | |
429 for (var i = 0; i < 22; i++) arr[i] = {}; | |
430 delete Array.prototype.push; | |
arv (Not doing code reviews)
2014/09/15 15:32:47
or
Array.prototype.push = function() {
fail('Sh
| |
431 arr.sort(); | |
432 | |
433 // Quicksort is used for arrays which length > 22 | |
434 // Arrays which length > 1000 guarantee GetThirdIndex is executed | |
435 arr = []; | |
436 for (var i = 0; i < 2000; ++i) arr[i] = {}; | |
437 arr.sort(); | |
438 } | |
439 | |
440 TestSortDoesntDepenOnArrayPrototypePush(); | |
441 | |
442 // Test sort doesn't depend on Array.prototype.sort. Otherwise a TypeError | |
443 // Exception will be thrown when running sort(). | |
444 function TestSortDoesntDepenOnArrayPrototypeSort() | |
445 { | |
446 var arr = []; | |
447 for (var i = 0; i < 2000; i++) arr[i] = {}; | |
448 var sortfn = Array.prototype.sort; | |
449 delete Array.prototype.sort; | |
450 sortfn.call(arr); | |
451 } | |
452 | |
453 TestSortDoesntDepenOnArrayPrototypeSort(); | |
OLD | NEW |