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

Unified Diff: src/js/array.js

Issue 1925993005: Simplify length-range-check in Array.prototype.push (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/array.js
diff --git a/src/js/array.js b/src/js/array.js
index c368cf395cee0a6327350ff89971e84719a50b7a..d4deb913942ef3773ef615d6743bc12679675361 100644
--- a/src/js/array.js
+++ b/src/js/array.js
@@ -463,14 +463,10 @@ function ArrayPush() {
var n = TO_LENGTH(array.length);
var m = arguments.length;
- // It appears that there is no enforced, absolute limit on the number of
- // arguments, but it would surely blow the stack to use 2**30 or more.
- // To avoid integer overflow, do the comparison to the max safe integer
- // after subtracting 2**30 from both sides. (2**31 would seem like a
- // natural value, but it is negative in JS, and 2**32 is 1.)
- if (m > (1 << 30) || (n - (1 << 30)) + m > kMaxSafeInteger - (1 << 30)) {
- throw MakeTypeError(kPushPastSafeLength, m, n);
- }
+ // Subtract n from kMaxSafeInteger rather than testing m + n >
+ // kMaxSafeInteger. n may already be kMaxSafeInteger. In that case adding
+ // e.g., 1 would not be safe.
+ if (m > kMaxSafeInteger - n) throw MakeTypeError(kPushPastSafeLength, m, n);
for (var i = 0; i < m; i++) {
array[i+n] = arguments[i];
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698