| OLD | NEW |
| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 function GlobalIsFinite(number) { | 85 function GlobalIsFinite(number) { |
| 86 if (!IS_NUMBER(number)) number = NonNumberToNumber(number); | 86 if (!IS_NUMBER(number)) number = NonNumberToNumber(number); |
| 87 | 87 |
| 88 // NaN - NaN == NaN, Infinity - Infinity == NaN, -Infinity - -Infinity == NaN. | 88 // NaN - NaN == NaN, Infinity - Infinity == NaN, -Infinity - -Infinity == NaN. |
| 89 return %_IsSmi(number) || number - number == 0; | 89 return %_IsSmi(number) || number - number == 0; |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 // ECMA-262 - 15.1.2.2 | 93 // ECMA-262 - 15.1.2.2 |
| 94 function GlobalParseInt(string, radix) { | 94 function GlobalParseInt(string, radix) { |
| 95 if (IS_UNDEFINED(radix)) { | 95 if (IS_UNDEFINED(radix) || radix === 10 || radix === 0) { |
| 96 // Some people use parseInt instead of Math.floor. This | 96 // Some people use parseInt instead of Math.floor. This |
| 97 // optimization makes parseInt on a Smi 12 times faster (60ns | 97 // optimization makes parseInt on a Smi 12 times faster (60ns |
| 98 // vs 800ns). The following optimization makes parseInt on a | 98 // vs 800ns). The following optimization makes parseInt on a |
| 99 // non-Smi number 9 times faster (230ns vs 2070ns). Together | 99 // non-Smi number 9 times faster (230ns vs 2070ns). Together |
| 100 // they make parseInt on a string 1.4% slower (274ns vs 270ns). | 100 // they make parseInt on a string 1.4% slower (274ns vs 270ns). |
| 101 if (%_IsSmi(string)) return string; | 101 if (%_IsSmi(string)) return string; |
| 102 if (IS_NUMBER(string) && | 102 if (IS_NUMBER(string) && |
| 103 ((0.01 < string && string < 1e9) || | 103 ((0.01 < string && string < 1e9) || |
| 104 (-1e9 < string && string < -0.01))) { | 104 (-1e9 < string && string < -0.01))) { |
| 105 // Truncate number. | 105 // Truncate number. |
| 106 return string | 0; | 106 return string | 0; |
| 107 } | 107 } |
| 108 radix = 0; | 108 if (IS_UNDEFINED(radix)) radix = 0; |
| 109 } else { | 109 } else { |
| 110 radix = TO_INT32(radix); | 110 radix = TO_INT32(radix); |
| 111 if (!(radix == 0 || (2 <= radix && radix <= 36))) | 111 if (!(radix == 0 || (2 <= radix && radix <= 36))) |
| 112 return $NaN; | 112 return $NaN; |
| 113 } | 113 } |
| 114 string = TO_STRING_INLINE(string); | 114 string = TO_STRING_INLINE(string); |
| 115 if (%_HasCachedArrayIndex(string) && | 115 if (%_HasCachedArrayIndex(string) && |
| 116 (radix == 0 || radix == 10)) { | 116 (radix == 0 || radix == 10)) { |
| 117 return %_GetCachedArrayIndex(string); | 117 return %_GetCachedArrayIndex(string); |
| 118 } | 118 } |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 (!desc.hasGetter() || | 579 (!desc.hasGetter() || |
| 580 SameValue(desc.getGet(), current.getGet())) && | 580 SameValue(desc.getGet(), current.getGet())) && |
| 581 (!desc.hasSetter() || | 581 (!desc.hasSetter() || |
| 582 SameValue(desc.getSet(), current.getSet()))) { | 582 SameValue(desc.getSet(), current.getSet()))) { |
| 583 return true; | 583 return true; |
| 584 } | 584 } |
| 585 if (!current.isConfigurable()) { | 585 if (!current.isConfigurable()) { |
| 586 // Step 7 | 586 // Step 7 |
| 587 if (desc.isConfigurable() || | 587 if (desc.isConfigurable() || |
| 588 (desc.hasEnumerable() && | 588 (desc.hasEnumerable() && |
| 589 desc.isEnumerable() != current.isEnumerable())) | 589 desc.isEnumerable() != current.isEnumerable())) { |
| 590 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 590 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 591 } |
| 591 // Step 8 | 592 // Step 8 |
| 592 if (!IsGenericDescriptor(desc)) { | 593 if (!IsGenericDescriptor(desc)) { |
| 593 // Step 9a | 594 // Step 9a |
| 594 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) | 595 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) { |
| 595 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 596 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 597 } |
| 596 // Step 10a | 598 // Step 10a |
| 597 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { | 599 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { |
| 598 if (!current.isWritable() && desc.isWritable()) | 600 if (!current.isWritable() && desc.isWritable()) { |
| 599 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 601 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 602 } |
| 600 if (!current.isWritable() && desc.hasValue() && | 603 if (!current.isWritable() && desc.hasValue() && |
| 601 !SameValue(desc.getValue(), current.getValue())) { | 604 !SameValue(desc.getValue(), current.getValue())) { |
| 602 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 605 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 603 } | 606 } |
| 604 } | 607 } |
| 605 // Step 11 | 608 // Step 11 |
| 606 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { | 609 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { |
| 607 if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())){ | 610 if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())) { |
| 608 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 611 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 609 } | 612 } |
| 610 if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) | 613 if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) { |
| 611 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 614 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 615 } |
| 612 } | 616 } |
| 613 } | 617 } |
| 614 } | 618 } |
| 615 } | 619 } |
| 616 | 620 |
| 617 // Send flags - enumerable and configurable are common - writable is | 621 // Send flags - enumerable and configurable are common - writable is |
| 618 // only send to the data descriptor. | 622 // only send to the data descriptor. |
| 619 // Take special care if enumerable and configurable is not defined on | 623 // Take special care if enumerable and configurable is not defined on |
| 620 // desc (we need to preserve the existing values from current). | 624 // desc (we need to preserve the existing values from current). |
| 621 var flag = NONE; | 625 var flag = NONE; |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 // ---------------------------------------------------------------------------- | 1243 // ---------------------------------------------------------------------------- |
| 1240 | 1244 |
| 1241 function SetupFunction() { | 1245 function SetupFunction() { |
| 1242 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1246 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1243 "bind", FunctionBind, | 1247 "bind", FunctionBind, |
| 1244 "toString", FunctionToString | 1248 "toString", FunctionToString |
| 1245 )); | 1249 )); |
| 1246 } | 1250 } |
| 1247 | 1251 |
| 1248 SetupFunction(); | 1252 SetupFunction(); |
| OLD | NEW |