| 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 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 | 902 |
| 903 function BooleanValueOf() { | 903 function BooleanValueOf() { |
| 904 // NOTE: Both Boolean objects and values can enter here as | 904 // NOTE: Both Boolean objects and values can enter here as |
| 905 // 'this'. This is not as dictated by ECMA-262. | 905 // 'this'. This is not as dictated by ECMA-262. |
| 906 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) | 906 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) |
| 907 throw new $TypeError('Boolean.prototype.valueOf is not generic'); | 907 throw new $TypeError('Boolean.prototype.valueOf is not generic'); |
| 908 return %_ValueOf(this); | 908 return %_ValueOf(this); |
| 909 } | 909 } |
| 910 | 910 |
| 911 | 911 |
| 912 function BooleanToJSON(key) { | |
| 913 return CheckJSONPrimitive(this.valueOf()); | |
| 914 } | |
| 915 | |
| 916 | |
| 917 // ---------------------------------------------------------------------------- | 912 // ---------------------------------------------------------------------------- |
| 918 | 913 |
| 919 | 914 |
| 920 function SetupBoolean() { | 915 function SetupBoolean() { |
| 921 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( | 916 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( |
| 922 "toString", BooleanToString, | 917 "toString", BooleanToString, |
| 923 "valueOf", BooleanValueOf, | 918 "valueOf", BooleanValueOf |
| 924 "toJSON", BooleanToJSON | |
| 925 )); | 919 )); |
| 926 } | 920 } |
| 927 | 921 |
| 928 SetupBoolean(); | 922 SetupBoolean(); |
| 929 | 923 |
| 930 // ---------------------------------------------------------------------------- | 924 // ---------------------------------------------------------------------------- |
| 931 // Number | 925 // Number |
| 932 | 926 |
| 933 // Set the Number function and constructor. | 927 // Set the Number function and constructor. |
| 934 %SetCode($Number, function(x) { | 928 %SetCode($Number, function(x) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); | 1008 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); |
| 1015 var p = TO_INTEGER(precision); | 1009 var p = TO_INTEGER(precision); |
| 1016 if (p < 1 || p > 21) { | 1010 if (p < 1 || p > 21) { |
| 1017 throw new $RangeError("toPrecision() argument must be between 1 and 21"); | 1011 throw new $RangeError("toPrecision() argument must be between 1 and 21"); |
| 1018 } | 1012 } |
| 1019 var x = ToNumber(this); | 1013 var x = ToNumber(this); |
| 1020 return %NumberToPrecision(x, p); | 1014 return %NumberToPrecision(x, p); |
| 1021 } | 1015 } |
| 1022 | 1016 |
| 1023 | 1017 |
| 1024 function CheckJSONPrimitive(val) { | |
| 1025 if (!IsPrimitive(val)) | |
| 1026 throw MakeTypeError('result_not_primitive', ['toJSON', val]); | |
| 1027 return val; | |
| 1028 } | |
| 1029 | |
| 1030 | |
| 1031 function NumberToJSON(key) { | |
| 1032 return CheckJSONPrimitive(this.valueOf()); | |
| 1033 } | |
| 1034 | |
| 1035 | |
| 1036 // ---------------------------------------------------------------------------- | 1018 // ---------------------------------------------------------------------------- |
| 1037 | 1019 |
| 1038 function SetupNumber() { | 1020 function SetupNumber() { |
| 1039 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); | 1021 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); |
| 1040 // Setup the constructor property on the Number prototype object. | 1022 // Setup the constructor property on the Number prototype object. |
| 1041 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); | 1023 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); |
| 1042 | 1024 |
| 1043 %OptimizeObjectForAddingMultipleProperties($Number, 5); | 1025 %OptimizeObjectForAddingMultipleProperties($Number, 5); |
| 1044 // ECMA-262 section 15.7.3.1. | 1026 // ECMA-262 section 15.7.3.1. |
| 1045 %SetProperty($Number, | 1027 %SetProperty($Number, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1066 DONT_ENUM | DONT_DELETE | READ_ONLY); | 1048 DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1067 %ToFastProperties($Number); | 1049 %ToFastProperties($Number); |
| 1068 | 1050 |
| 1069 // Setup non-enumerable functions on the Number prototype object. | 1051 // Setup non-enumerable functions on the Number prototype object. |
| 1070 InstallFunctions($Number.prototype, DONT_ENUM, $Array( | 1052 InstallFunctions($Number.prototype, DONT_ENUM, $Array( |
| 1071 "toString", NumberToString, | 1053 "toString", NumberToString, |
| 1072 "toLocaleString", NumberToLocaleString, | 1054 "toLocaleString", NumberToLocaleString, |
| 1073 "valueOf", NumberValueOf, | 1055 "valueOf", NumberValueOf, |
| 1074 "toFixed", NumberToFixed, | 1056 "toFixed", NumberToFixed, |
| 1075 "toExponential", NumberToExponential, | 1057 "toExponential", NumberToExponential, |
| 1076 "toPrecision", NumberToPrecision, | 1058 "toPrecision", NumberToPrecision |
| 1077 "toJSON", NumberToJSON | |
| 1078 )); | 1059 )); |
| 1079 } | 1060 } |
| 1080 | 1061 |
| 1081 SetupNumber(); | 1062 SetupNumber(); |
| 1082 | 1063 |
| 1083 | 1064 |
| 1084 | |
| 1085 // ---------------------------------------------------------------------------- | 1065 // ---------------------------------------------------------------------------- |
| 1086 // Function | 1066 // Function |
| 1087 | 1067 |
| 1088 $Function.prototype.constructor = $Function; | 1068 $Function.prototype.constructor = $Function; |
| 1089 | 1069 |
| 1090 function FunctionSourceString(func) { | 1070 function FunctionSourceString(func) { |
| 1091 if (!IS_FUNCTION(func)) { | 1071 if (!IS_FUNCTION(func)) { |
| 1092 throw new $TypeError('Function.prototype.toString is not generic'); | 1072 throw new $TypeError('Function.prototype.toString is not generic'); |
| 1093 } | 1073 } |
| 1094 | 1074 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 // ---------------------------------------------------------------------------- | 1173 // ---------------------------------------------------------------------------- |
| 1194 | 1174 |
| 1195 function SetupFunction() { | 1175 function SetupFunction() { |
| 1196 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1176 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1197 "bind", FunctionBind, | 1177 "bind", FunctionBind, |
| 1198 "toString", FunctionToString | 1178 "toString", FunctionToString |
| 1199 )); | 1179 )); |
| 1200 } | 1180 } |
| 1201 | 1181 |
| 1202 SetupFunction(); | 1182 SetupFunction(); |
| OLD | NEW |