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