| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 // ECMA 262 - 15.1.4 | 77 // ECMA 262 - 15.1.4 |
| 78 function GlobalIsNaN(number) { | 78 function GlobalIsNaN(number) { |
| 79 var n = ToNumber(number); | 79 var n = ToNumber(number); |
| 80 return NUMBER_IS_NAN(n); | 80 return NUMBER_IS_NAN(n); |
| 81 } | 81 } |
| 82 | 82 |
| 83 | 83 |
| 84 // ECMA 262 - 15.1.5 | 84 // ECMA 262 - 15.1.5 |
| 85 function GlobalIsFinite(number) { | 85 function GlobalIsFinite(number) { |
| 86 if (!IS_NUMBER(number)) number = ToNumber(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)) { |
| 96 // Some people use parseInt instead of Math.floor. This | 96 // Some people use parseInt instead of Math.floor. This |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 | 889 |
| 890 SetupObject(); | 890 SetupObject(); |
| 891 | 891 |
| 892 | 892 |
| 893 // ---------------------------------------------------------------------------- | 893 // ---------------------------------------------------------------------------- |
| 894 // Boolean | 894 // Boolean |
| 895 | 895 |
| 896 function BooleanToString() { | 896 function BooleanToString() { |
| 897 // NOTE: Both Boolean objects and values can enter here as | 897 // NOTE: Both Boolean objects and values can enter here as |
| 898 // 'this'. This is not as dictated by ECMA-262. | 898 // 'this'. This is not as dictated by ECMA-262. |
| 899 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) | 899 var b = this; |
| 900 throw new $TypeError('Boolean.prototype.toString is not generic'); | 900 if (!IS_BOOLEAN(b)) { |
| 901 return ToString(%_ValueOf(this)); | 901 if (!IS_BOOLEAN_WRAPPER(b)) { |
| 902 throw new $TypeError('Boolean.prototype.toString is not generic'); |
| 903 } |
| 904 b = %_ValueOf(b); |
| 905 } |
| 906 return b ? 'true' : 'false'; |
| 902 } | 907 } |
| 903 | 908 |
| 904 | 909 |
| 905 function BooleanValueOf() { | 910 function BooleanValueOf() { |
| 906 // NOTE: Both Boolean objects and values can enter here as | 911 // NOTE: Both Boolean objects and values can enter here as |
| 907 // 'this'. This is not as dictated by ECMA-262. | 912 // 'this'. This is not as dictated by ECMA-262. |
| 908 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) | 913 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) |
| 909 throw new $TypeError('Boolean.prototype.valueOf is not generic'); | 914 throw new $TypeError('Boolean.prototype.valueOf is not generic'); |
| 910 return %_ValueOf(this); | 915 return %_ValueOf(this); |
| 911 } | 916 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 // 'this'. This is not as dictated by ECMA-262. | 949 // 'this'. This is not as dictated by ECMA-262. |
| 945 var number = this; | 950 var number = this; |
| 946 if (!IS_NUMBER(this)) { | 951 if (!IS_NUMBER(this)) { |
| 947 if (!IS_NUMBER_WRAPPER(this)) | 952 if (!IS_NUMBER_WRAPPER(this)) |
| 948 throw new $TypeError('Number.prototype.toString is not generic'); | 953 throw new $TypeError('Number.prototype.toString is not generic'); |
| 949 // Get the value of this number in case it's an object. | 954 // Get the value of this number in case it's an object. |
| 950 number = %_ValueOf(this); | 955 number = %_ValueOf(this); |
| 951 } | 956 } |
| 952 // Fast case: Convert number in radix 10. | 957 // Fast case: Convert number in radix 10. |
| 953 if (IS_UNDEFINED(radix) || radix === 10) { | 958 if (IS_UNDEFINED(radix) || radix === 10) { |
| 954 return ToString(number); | 959 return %_NumberToString(number); |
| 955 } | 960 } |
| 956 | 961 |
| 957 // Convert the radix to an integer and check the range. | 962 // Convert the radix to an integer and check the range. |
| 958 radix = TO_INTEGER(radix); | 963 radix = TO_INTEGER(radix); |
| 959 if (radix < 2 || radix > 36) { | 964 if (radix < 2 || radix > 36) { |
| 960 throw new $RangeError('toString() radix argument must be between 2 and 36'); | 965 throw new $RangeError('toString() radix argument must be between 2 and 36'); |
| 961 } | 966 } |
| 962 // Convert the number to a string in the given radix. | 967 // Convert the number to a string in the given radix. |
| 963 return %NumberToRadixString(number, radix); | 968 return %NumberToRadixString(number, radix); |
| 964 } | 969 } |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 | 1148 |
| 1144 return result; | 1149 return result; |
| 1145 } | 1150 } |
| 1146 | 1151 |
| 1147 | 1152 |
| 1148 function NewFunction(arg1) { // length == 1 | 1153 function NewFunction(arg1) { // length == 1 |
| 1149 var n = %_ArgumentsLength(); | 1154 var n = %_ArgumentsLength(); |
| 1150 var p = ''; | 1155 var p = ''; |
| 1151 if (n > 1) { | 1156 if (n > 1) { |
| 1152 p = new $Array(n - 1); | 1157 p = new $Array(n - 1); |
| 1153 // Explicitly convert all parameters to strings. | 1158 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); |
| 1154 // Array.prototype.join replaces null with empty strings which is | 1159 p = Join(p, n - 1, ',', NonStringToString); |
| 1155 // not appropriate. | |
| 1156 for (var i = 0; i < n - 1; i++) p[i] = ToString(%_Arguments(i)); | |
| 1157 p = p.join(','); | |
| 1158 // If the formal parameters string include ) - an illegal | 1160 // If the formal parameters string include ) - an illegal |
| 1159 // character - it may make the combined function expression | 1161 // character - it may make the combined function expression |
| 1160 // compile. We avoid this problem by checking for this early on. | 1162 // compile. We avoid this problem by checking for this early on. |
| 1161 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); | 1163 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); |
| 1162 } | 1164 } |
| 1163 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 1165 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
| 1164 var source = '(function(' + p + ') {\n' + body + '\n})'; | 1166 var source = '(function(' + p + ') {\n' + body + '\n})'; |
| 1165 | 1167 |
| 1166 // The call to SetNewFunctionAttributes will ensure the prototype | 1168 // The call to SetNewFunctionAttributes will ensure the prototype |
| 1167 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 1169 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). |
| 1168 var f = %CompileString(source)(); | 1170 var f = %CompileString(source)(); |
| 1169 %FunctionSetName(f, "anonymous"); | 1171 %FunctionSetName(f, "anonymous"); |
| 1170 return %SetNewFunctionAttributes(f); | 1172 return %SetNewFunctionAttributes(f); |
| 1171 } | 1173 } |
| 1172 | 1174 |
| 1173 %SetCode($Function, NewFunction); | 1175 %SetCode($Function, NewFunction); |
| 1174 | 1176 |
| 1175 // ---------------------------------------------------------------------------- | 1177 // ---------------------------------------------------------------------------- |
| 1176 | 1178 |
| 1177 function SetupFunction() { | 1179 function SetupFunction() { |
| 1178 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1180 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1179 "bind", FunctionBind, | 1181 "bind", FunctionBind, |
| 1180 "toString", FunctionToString | 1182 "toString", FunctionToString |
| 1181 )); | 1183 )); |
| 1182 } | 1184 } |
| 1183 | 1185 |
| 1184 SetupFunction(); | 1186 SetupFunction(); |
| OLD | NEW |