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