Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 33 // const $Number = global.Number; | 33 // const $Number = global.Number; |
| 34 // const $Function = global.Function; | 34 // const $Function = global.Function; |
| 35 // const $Array = global.Array; | 35 // const $Array = global.Array; |
| 36 // const $NaN = 0/0; | 36 // const $NaN = 0/0; |
| 37 // | 37 // |
| 38 // in math.js: | 38 // in math.js: |
| 39 // const $floor = MathFloor | 39 // const $floor = MathFloor |
| 40 | 40 |
| 41 const $isNaN = GlobalIsNaN; | 41 const $isNaN = GlobalIsNaN; |
| 42 const $isFinite = GlobalIsFinite; | 42 const $isFinite = GlobalIsFinite; |
| 43 | 43 |
|
PhistucK
2011/09/02 20:24:34
I know this code was there already, but see http:/
Lasse Reichstein
2011/09/05 10:51:16
We shouldn't use "const" at all.
The primary reaso
| |
| 44 | |
| 45 // ---------------------------------------------------------------------------- | 44 // ---------------------------------------------------------------------------- |
| 46 | 45 |
| 47 | 46 |
| 48 // Helper function used to install functions on objects. | 47 // Helper function used to install functions on objects. |
| 49 function InstallFunctions(object, attributes, functions) { | 48 function InstallFunctions(object, attributes, functions) { |
| 50 if (functions.length >= 8) { | 49 if (functions.length >= 8) { |
| 51 %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); | 50 %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); |
| 52 } | 51 } |
| 53 for (var i = 0; i < functions.length; i += 2) { | 52 for (var i = 0; i < functions.length; i += 2) { |
| 54 var key = functions[i]; | 53 var key = functions[i]; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 79 %SetHiddenPrototype(object, hidden_prototype); | 78 %SetHiddenPrototype(object, hidden_prototype); |
| 80 InstallFunctions(hidden_prototype, attributes, functions); | 79 InstallFunctions(hidden_prototype, attributes, functions); |
| 81 } | 80 } |
| 82 | 81 |
| 83 | 82 |
| 84 // ---------------------------------------------------------------------------- | 83 // ---------------------------------------------------------------------------- |
| 85 | 84 |
| 86 | 85 |
| 87 // ECMA 262 - 15.1.4 | 86 // ECMA 262 - 15.1.4 |
| 88 function GlobalIsNaN(number) { | 87 function GlobalIsNaN(number) { |
| 89 var n = ToNumber(number); | 88 if (!IS_NUMBER(number)) number = NonNumberToNumber(number); |
| 90 return NUMBER_IS_NAN(n); | 89 return NUMBER_IS_NAN(number); |
| 91 } | 90 } |
| 92 | 91 |
| 93 | 92 |
| 94 // ECMA 262 - 15.1.5 | 93 // ECMA 262 - 15.1.5 |
| 95 function GlobalIsFinite(number) { | 94 function GlobalIsFinite(number) { |
| 96 if (!IS_NUMBER(number)) number = NonNumberToNumber(number); | 95 if (!IS_NUMBER(number)) number = NonNumberToNumber(number); |
| 97 | 96 return !NUMBER_IS_NAN(number) && number !== (1 / 0) && number !== (-1 / 0); |
|
Sven Panne
2011/09/02 16:00:14
!NUMBER_IS_NAN(number) is equivalent to %_IsSmi(%I
Lasse Reichstein
2011/09/05 10:51:16
That depends a lot on the test.
My, admittedly ver
| |
| 98 // NaN - NaN == NaN, Infinity - Infinity == NaN, -Infinity - -Infinity == NaN. | |
| 99 return %_IsSmi(number) || number - number == 0; | |
| 100 } | 97 } |
| 101 | 98 |
| 102 | 99 |
| 103 // ECMA-262 - 15.1.2.2 | 100 // ECMA-262 - 15.1.2.2 |
| 104 function GlobalParseInt(string, radix) { | 101 function GlobalParseInt(string, radix) { |
| 105 if (IS_UNDEFINED(radix) || radix === 10 || radix === 0) { | 102 if (IS_UNDEFINED(radix) || radix === 10 || radix === 0) { |
| 106 // Some people use parseInt instead of Math.floor. This | 103 // Some people use parseInt instead of Math.floor. This |
| 107 // optimization makes parseInt on a Smi 12 times faster (60ns | 104 // optimization makes parseInt on a Smi 12 times faster (60ns |
| 108 // vs 800ns). The following optimization makes parseInt on a | 105 // vs 800ns). The following optimization makes parseInt on a |
| 109 // non-Smi number 9 times faster (230ns vs 2070ns). Together | 106 // non-Smi number 9 times faster (230ns vs 2070ns). Together |
| (...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1532 // ---------------------------------------------------------------------------- | 1529 // ---------------------------------------------------------------------------- |
| 1533 | 1530 |
| 1534 function SetupFunction() { | 1531 function SetupFunction() { |
| 1535 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1532 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1536 "bind", FunctionBind, | 1533 "bind", FunctionBind, |
| 1537 "toString", FunctionToString | 1534 "toString", FunctionToString |
| 1538 )); | 1535 )); |
| 1539 } | 1536 } |
| 1540 | 1537 |
| 1541 SetupFunction(); | 1538 SetupFunction(); |
| OLD | NEW |