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

Side by Side Diff: src/v8natives.js

Issue 7206019: Fix "illegal access" when calling parseInt with a radix that is not a smi. (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // vs 800ns). The following optimization makes parseInt on a 99 // vs 800ns). The following optimization makes parseInt on a
100 // non-Smi number 9 times faster (230ns vs 2070ns). Together 100 // non-Smi number 9 times faster (230ns vs 2070ns). Together
101 // they make parseInt on a string 1.4% slower (274ns vs 270ns). 101 // they make parseInt on a string 1.4% slower (274ns vs 270ns).
102 if (%_IsSmi(string)) return string; 102 if (%_IsSmi(string)) return string;
103 if (IS_NUMBER(string) && 103 if (IS_NUMBER(string) &&
104 ((0.01 < string && string < 1e9) || 104 ((0.01 < string && string < 1e9) ||
105 (-1e9 < string && string < -0.01))) { 105 (-1e9 < string && string < -0.01))) {
106 // Truncate number. 106 // Truncate number.
107 return string | 0; 107 return string | 0;
108 } 108 }
109 if (IS_UNDEFINED(radix)) radix = 0; 109 radix = radix || 0;
Lasse Reichstein 2011/06/28 08:32:21 This seems silly to begin with. Just set radix =
Steven 2011/06/28 10:10:35 It seems so but it's not: 'radix = 0' will trigger
Lasse Reichstein 2011/06/28 10:28:17 Ack, my bad. In that case, use radix = TO_INT32(r
Lasse Reichstein 2011/06/28 10:31:48 and because radix = radix || 0 would not convert
110 } else { 110 } else {
111 radix = TO_INT32(radix); 111 radix = TO_INT32(radix);
112 if (!(radix == 0 || (2 <= radix && radix <= 36))) 112 if (!(radix == 0 || (2 <= radix && radix <= 36)))
113 return $NaN; 113 return $NaN;
Lasse Reichstein 2011/06/28 08:32:21 Could you please put braces around the then-branch
Steven 2011/06/28 10:10:35 Done.
114 } 114 }
115 string = TO_STRING_INLINE(string); 115 string = TO_STRING_INLINE(string);
116 if (%_HasCachedArrayIndex(string) && 116 if (%_HasCachedArrayIndex(string) &&
117 (radix == 0 || radix == 10)) { 117 (radix == 0 || radix == 10)) {
118 return %_GetCachedArrayIndex(string); 118 return %_GetCachedArrayIndex(string);
119 } 119 }
120 return %StringParseInt(string, radix); 120 return %StringParseInt(string, radix);
121 } 121 }
122 122
123 123
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 // ---------------------------------------------------------------------------- 1390 // ----------------------------------------------------------------------------
1391 1391
1392 function SetupFunction() { 1392 function SetupFunction() {
1393 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1393 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1394 "bind", FunctionBind, 1394 "bind", FunctionBind,
1395 "toString", FunctionToString 1395 "toString", FunctionToString
1396 )); 1396 ));
1397 } 1397 }
1398 1398
1399 SetupFunction(); 1399 SetupFunction();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-1246.js » ('j') | test/mjsunit/regress/regress-1246.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698