OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 function ArrayPush() { | 510 function ArrayPush() { |
511 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push"); | 511 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push"); |
512 | 512 |
513 if (%IsObserved(this)) | 513 if (%IsObserved(this)) |
514 return ObservedArrayPush.apply(this, arguments); | 514 return ObservedArrayPush.apply(this, arguments); |
515 | 515 |
516 var array = TO_OBJECT(this); | 516 var array = TO_OBJECT(this); |
517 var n = TO_LENGTH_OR_UINT32(array.length); | 517 var n = TO_LENGTH_OR_UINT32(array.length); |
518 var m = %_ArgumentsLength(); | 518 var m = %_ArgumentsLength(); |
519 | 519 |
520 // It appears that there is no enforced, absolute limit on the number of | |
521 // arguments, but it would be very slow for users to use 2**32 or more. | |
522 // To avoid integer overflow, do the comparison to the max safe integer | |
523 // after subtracting 2**32 from both sides. To stay on the safe side, also | |
524 // prohibit this function from being called with more than 2**32 arguments. | |
525 if (m > 1 << 32 || (n - (1 << 32)) + m > kMaxSafeInteger - (1 << 32)) { | |
adamk
2015/10/26 23:14:28
"1 << 32" isn't doing what you want. It returns 1.
Dan Ehrenberg
2015/10/27 00:47:36
Right. I finally settled on something that works,
| |
526 throw MakeTypeError(kPushPastSafeLength, m, n); | |
527 } | |
528 | |
520 for (var i = 0; i < m; i++) { | 529 for (var i = 0; i < m; i++) { |
521 array[i+n] = %_Arguments(i); | 530 array[i+n] = %_Arguments(i); |
522 } | 531 } |
523 | 532 |
524 var new_length = n + m; | 533 var new_length = n + m; |
525 array.length = new_length; | 534 array.length = new_length; |
526 return new_length; | 535 return new_length; |
527 } | 536 } |
528 | 537 |
529 | 538 |
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1672 %InstallToContext([ | 1681 %InstallToContext([ |
1673 "array_pop", ArrayPop, | 1682 "array_pop", ArrayPop, |
1674 "array_push", ArrayPush, | 1683 "array_push", ArrayPush, |
1675 "array_shift", ArrayShift, | 1684 "array_shift", ArrayShift, |
1676 "array_splice", ArraySplice, | 1685 "array_splice", ArraySplice, |
1677 "array_slice", ArraySlice, | 1686 "array_slice", ArraySlice, |
1678 "array_unshift", ArrayUnshift, | 1687 "array_unshift", ArrayUnshift, |
1679 ]); | 1688 ]); |
1680 | 1689 |
1681 }); | 1690 }); |
OLD | NEW |