| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 201 |
| 202 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); | 202 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); |
| 203 | 203 |
| 204 // ---------------------------------------------------------------------------- | 204 // ---------------------------------------------------------------------------- |
| 205 // Object | 205 // Object |
| 206 | 206 |
| 207 $Object.prototype.constructor = $Object; | 207 $Object.prototype.constructor = $Object; |
| 208 | 208 |
| 209 // ECMA-262 - 15.2.4.2 | 209 // ECMA-262 - 15.2.4.2 |
| 210 function ObjectToString() { | 210 function ObjectToString() { |
| 211 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 212 return '[object Undefined]'; |
| 213 } |
| 214 if (IS_NULL(this)) return '[object Null]'; |
| 211 return "[object " + %_ClassOf(ToObject(this)) + "]"; | 215 return "[object " + %_ClassOf(ToObject(this)) + "]"; |
| 212 } | 216 } |
| 213 | 217 |
| 214 | 218 |
| 215 // ECMA-262 - 15.2.4.3 | 219 // ECMA-262 - 15.2.4.3 |
| 216 function ObjectToLocaleString() { | 220 function ObjectToLocaleString() { |
| 221 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 222 throw MakeTypeError("called_on_null_or_undefined", |
| 223 ["Object.prototype.toLocaleString"]); |
| 224 } |
| 217 return this.toString(); | 225 return this.toString(); |
| 218 } | 226 } |
| 219 | 227 |
| 220 | 228 |
| 221 // ECMA-262 - 15.2.4.4 | 229 // ECMA-262 - 15.2.4.4 |
| 222 function ObjectValueOf() { | 230 function ObjectValueOf() { |
| 223 return ToObject(this); | 231 return ToObject(this); |
| 224 } | 232 } |
| 225 | 233 |
| 226 | 234 |
| 227 // ECMA-262 - 15.2.4.5 | 235 // ECMA-262 - 15.2.4.5 |
| 228 function ObjectHasOwnProperty(V) { | 236 function ObjectHasOwnProperty(V) { |
| 229 return %HasLocalProperty(ToObject(this), ToString(V)); | 237 return %HasLocalProperty(ToObject(this), ToString(V)); |
| 230 } | 238 } |
| 231 | 239 |
| 232 | 240 |
| 233 // ECMA-262 - 15.2.4.6 | 241 // ECMA-262 - 15.2.4.6 |
| 234 function ObjectIsPrototypeOf(V) { | 242 function ObjectIsPrototypeOf(V) { |
| 243 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 244 throw MakeTypeError("called_on_null_or_undefined", |
| 245 ["Object.prototype.isPrototypeOf"]); |
| 246 } |
| 235 if (!IS_SPEC_OBJECT(V)) return false; | 247 if (!IS_SPEC_OBJECT(V)) return false; |
| 236 return %IsInPrototypeChain(this, V); | 248 return %IsInPrototypeChain(this, V); |
| 237 } | 249 } |
| 238 | 250 |
| 239 | 251 |
| 240 // ECMA-262 - 15.2.4.6 | 252 // ECMA-262 - 15.2.4.6 |
| 241 function ObjectPropertyIsEnumerable(V) { | 253 function ObjectPropertyIsEnumerable(V) { |
| 242 return %IsPropertyEnumerable(ToObject(this), ToString(V)); | 254 return %IsPropertyEnumerable(ToObject(this), ToString(V)); |
| 243 } | 255 } |
| 244 | 256 |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 if (radix < 2 || radix > 36) { | 1067 if (radix < 2 || radix > 36) { |
| 1056 throw new $RangeError('toString() radix argument must be between 2 and 36'); | 1068 throw new $RangeError('toString() radix argument must be between 2 and 36'); |
| 1057 } | 1069 } |
| 1058 // Convert the number to a string in the given radix. | 1070 // Convert the number to a string in the given radix. |
| 1059 return %NumberToRadixString(number, radix); | 1071 return %NumberToRadixString(number, radix); |
| 1060 } | 1072 } |
| 1061 | 1073 |
| 1062 | 1074 |
| 1063 // ECMA-262 section 15.7.4.3 | 1075 // ECMA-262 section 15.7.4.3 |
| 1064 function NumberToLocaleString() { | 1076 function NumberToLocaleString() { |
| 1077 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1078 throw MakeTypeError("called_on_null_or_undefined", |
| 1079 ["Number.prototype.toLocaleString"]); |
| 1080 } |
| 1065 return this.toString(); | 1081 return this.toString(); |
| 1066 } | 1082 } |
| 1067 | 1083 |
| 1068 | 1084 |
| 1069 // ECMA-262 section 15.7.4.4 | 1085 // ECMA-262 section 15.7.4.4 |
| 1070 function NumberValueOf() { | 1086 function NumberValueOf() { |
| 1071 // NOTE: Both Number objects and values can enter here as | 1087 // NOTE: Both Number objects and values can enter here as |
| 1072 // 'this'. This is not as dictated by ECMA-262. | 1088 // 'this'. This is not as dictated by ECMA-262. |
| 1073 if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) | 1089 if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) |
| 1074 throw new $TypeError('Number.prototype.valueOf is not generic'); | 1090 throw new $TypeError('Number.prototype.valueOf is not generic'); |
| 1075 return %_ValueOf(this); | 1091 return %_ValueOf(this); |
| 1076 } | 1092 } |
| 1077 | 1093 |
| 1078 | 1094 |
| 1079 // ECMA-262 section 15.7.4.5 | 1095 // ECMA-262 section 15.7.4.5 |
| 1080 function NumberToFixed(fractionDigits) { | 1096 function NumberToFixed(fractionDigits) { |
| 1081 var f = TO_INTEGER(fractionDigits); | 1097 var f = TO_INTEGER(fractionDigits); |
| 1082 if (f < 0 || f > 20) { | 1098 if (f < 0 || f > 20) { |
| 1083 throw new $RangeError("toFixed() digits argument must be between 0 and 20"); | 1099 throw new $RangeError("toFixed() digits argument must be between 0 and 20"); |
| 1084 } | 1100 } |
| 1101 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1102 throw MakeTypeError("called_on_null_or_undefined", |
| 1103 ["Number.prototype.toFixed"]); |
| 1104 } |
| 1085 var x = ToNumber(this); | 1105 var x = ToNumber(this); |
| 1086 return %NumberToFixed(x, f); | 1106 return %NumberToFixed(x, f); |
| 1087 } | 1107 } |
| 1088 | 1108 |
| 1089 | 1109 |
| 1090 // ECMA-262 section 15.7.4.6 | 1110 // ECMA-262 section 15.7.4.6 |
| 1091 function NumberToExponential(fractionDigits) { | 1111 function NumberToExponential(fractionDigits) { |
| 1092 var f = -1; | 1112 var f = -1; |
| 1093 if (!IS_UNDEFINED(fractionDigits)) { | 1113 if (!IS_UNDEFINED(fractionDigits)) { |
| 1094 f = TO_INTEGER(fractionDigits); | 1114 f = TO_INTEGER(fractionDigits); |
| 1095 if (f < 0 || f > 20) { | 1115 if (f < 0 || f > 20) { |
| 1096 throw new $RangeError("toExponential() argument must be between 0 and 20")
; | 1116 throw new $RangeError("toExponential() argument must be between 0 and 20")
; |
| 1097 } | 1117 } |
| 1098 } | 1118 } |
| 1119 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1120 throw MakeTypeError("called_on_null_or_undefined", |
| 1121 ["Number.prototype.toExponential"]); |
| 1122 } |
| 1099 var x = ToNumber(this); | 1123 var x = ToNumber(this); |
| 1100 return %NumberToExponential(x, f); | 1124 return %NumberToExponential(x, f); |
| 1101 } | 1125 } |
| 1102 | 1126 |
| 1103 | 1127 |
| 1104 // ECMA-262 section 15.7.4.7 | 1128 // ECMA-262 section 15.7.4.7 |
| 1105 function NumberToPrecision(precision) { | 1129 function NumberToPrecision(precision) { |
| 1130 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1131 throw MakeTypeError("called_on_null_or_undefined", |
| 1132 ["Number.prototype.toPrecision"]); |
| 1133 } |
| 1106 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); | 1134 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); |
| 1107 var p = TO_INTEGER(precision); | 1135 var p = TO_INTEGER(precision); |
| 1108 if (p < 1 || p > 21) { | 1136 if (p < 1 || p > 21) { |
| 1109 throw new $RangeError("toPrecision() argument must be between 1 and 21"); | 1137 throw new $RangeError("toPrecision() argument must be between 1 and 21"); |
| 1110 } | 1138 } |
| 1111 var x = ToNumber(this); | 1139 var x = ToNumber(this); |
| 1112 return %NumberToPrecision(x, p); | 1140 return %NumberToPrecision(x, p); |
| 1113 } | 1141 } |
| 1114 | 1142 |
| 1115 | 1143 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 // ---------------------------------------------------------------------------- | 1312 // ---------------------------------------------------------------------------- |
| 1285 | 1313 |
| 1286 function SetupFunction() { | 1314 function SetupFunction() { |
| 1287 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1315 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1288 "bind", FunctionBind, | 1316 "bind", FunctionBind, |
| 1289 "toString", FunctionToString | 1317 "toString", FunctionToString |
| 1290 )); | 1318 )); |
| 1291 } | 1319 } |
| 1292 | 1320 |
| 1293 SetupFunction(); | 1321 SetupFunction(); |
| OLD | NEW |