OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 Loading... |
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 string = TO_STRING_INLINE(string); |
109 radix = radix | 0; | 110 radix = radix | 0; |
110 } else { | 111 } else { |
| 112 // The spec says ToString should be evaluated before ToInt32. |
| 113 string = TO_STRING_INLINE(string); |
111 radix = TO_INT32(radix); | 114 radix = TO_INT32(radix); |
112 if (!(radix == 0 || (2 <= radix && radix <= 36))) | 115 if (!(radix == 0 || (2 <= radix && radix <= 36))) |
113 return $NaN; | 116 return $NaN; |
114 } | 117 } |
115 string = TO_STRING_INLINE(string); | 118 |
116 if (%_HasCachedArrayIndex(string) && | 119 if (%_HasCachedArrayIndex(string) && |
117 (radix == 0 || radix == 10)) { | 120 (radix == 0 || radix == 10)) { |
118 return %_GetCachedArrayIndex(string); | 121 return %_GetCachedArrayIndex(string); |
119 } | 122 } |
120 return %StringParseInt(string, radix); | 123 return %StringParseInt(string, radix); |
121 } | 124 } |
122 | 125 |
123 | 126 |
124 // ECMA-262 - 15.1.2.3 | 127 // ECMA-262 - 15.1.2.3 |
125 function GlobalParseFloat(string) { | 128 function GlobalParseFloat(string) { |
(...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 // ---------------------------------------------------------------------------- | 1526 // ---------------------------------------------------------------------------- |
1524 | 1527 |
1525 function SetupFunction() { | 1528 function SetupFunction() { |
1526 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1529 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1527 "bind", FunctionBind, | 1530 "bind", FunctionBind, |
1528 "toString", FunctionToString | 1531 "toString", FunctionToString |
1529 )); | 1532 )); |
1530 } | 1533 } |
1531 | 1534 |
1532 SetupFunction(); | 1535 SetupFunction(); |
OLD | NEW |