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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 185 |
186 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); | 186 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); |
187 | 187 |
188 // ---------------------------------------------------------------------------- | 188 // ---------------------------------------------------------------------------- |
189 // Object | 189 // Object |
190 | 190 |
191 $Object.prototype.constructor = $Object; | 191 $Object.prototype.constructor = $Object; |
192 | 192 |
193 // ECMA-262 - 15.2.4.2 | 193 // ECMA-262 - 15.2.4.2 |
194 function ObjectToString() { | 194 function ObjectToString() { |
195 var c = %ClassOf(this); | 195 var c = %_ClassOf(this); |
196 // Hide Arguments from the outside. | 196 // Hide Arguments from the outside. |
197 if (c === 'Arguments') c = 'Object'; | 197 if (c === 'Arguments') c = 'Object'; |
198 return "[object " + c + "]"; | 198 return "[object " + c + "]"; |
199 } | 199 } |
200 | 200 |
201 | 201 |
202 // ECMA-262 - 15.2.4.3 | 202 // ECMA-262 - 15.2.4.3 |
203 function ObjectToLocaleString() { | 203 function ObjectToLocaleString() { |
204 return this.toString(); | 204 return this.toString(); |
205 } | 205 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 SetupObject(); | 305 SetupObject(); |
306 | 306 |
307 | 307 |
308 // ---------------------------------------------------------------------------- | 308 // ---------------------------------------------------------------------------- |
309 // Boolean | 309 // Boolean |
310 | 310 |
311 function BooleanToString() { | 311 function BooleanToString() { |
312 // NOTE: Both Boolean objects and values can enter here as | 312 // NOTE: Both Boolean objects and values can enter here as |
313 // 'this'. This is not as dictated by ECMA-262. | 313 // 'this'. This is not as dictated by ECMA-262. |
314 if (!IS_BOOLEAN(this) && !%HasBooleanClass(this)) | 314 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) |
315 throw new $TypeError('Boolean.prototype.toString is not generic'); | 315 throw new $TypeError('Boolean.prototype.toString is not generic'); |
316 return ToString(%_ValueOf(this)); | 316 return ToString(%_ValueOf(this)); |
317 } | 317 } |
318 | 318 |
319 | 319 |
320 function BooleanValueOf() { | 320 function BooleanValueOf() { |
321 // NOTE: Both Boolean objects and values can enter here as | 321 // NOTE: Both Boolean objects and values can enter here as |
322 // 'this'. This is not as dictated by ECMA-262. | 322 // 'this'. This is not as dictated by ECMA-262. |
323 if (!IS_BOOLEAN(this) && !%HasBooleanClass(this)) | 323 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) |
324 throw new $TypeError('Boolean.prototype.valueOf is not generic'); | 324 throw new $TypeError('Boolean.prototype.valueOf is not generic'); |
325 return %_ValueOf(this); | 325 return %_ValueOf(this); |
326 } | 326 } |
327 | 327 |
328 | 328 |
329 function BooleanToJSON(key) { | 329 function BooleanToJSON(key) { |
330 return CheckJSONPrimitive(this.valueOf()); | 330 return CheckJSONPrimitive(this.valueOf()); |
331 } | 331 } |
332 | 332 |
333 | 333 |
(...skipping 24 matching lines...) Expand all Loading... |
358 }); | 358 }); |
359 | 359 |
360 %FunctionSetPrototype($Number, new $Number(0)); | 360 %FunctionSetPrototype($Number, new $Number(0)); |
361 | 361 |
362 // ECMA-262 section 15.7.4.2. | 362 // ECMA-262 section 15.7.4.2. |
363 function NumberToString(radix) { | 363 function NumberToString(radix) { |
364 // NOTE: Both Number objects and values can enter here as | 364 // NOTE: Both Number objects and values can enter here as |
365 // 'this'. This is not as dictated by ECMA-262. | 365 // 'this'. This is not as dictated by ECMA-262. |
366 var number = this; | 366 var number = this; |
367 if (!IS_NUMBER(this)) { | 367 if (!IS_NUMBER(this)) { |
368 if (!%HasNumberClass(this)) | 368 if (!IS_NUMBER_WRAPPER(this)) |
369 throw new $TypeError('Number.prototype.toString is not generic'); | 369 throw new $TypeError('Number.prototype.toString is not generic'); |
370 // Get the value of this number in case it's an object. | 370 // Get the value of this number in case it's an object. |
371 number = %_ValueOf(this); | 371 number = %_ValueOf(this); |
372 } | 372 } |
373 // Fast case: Convert number in radix 10. | 373 // Fast case: Convert number in radix 10. |
374 if (IS_UNDEFINED(radix) || radix === 10) { | 374 if (IS_UNDEFINED(radix) || radix === 10) { |
375 return ToString(number); | 375 return ToString(number); |
376 } | 376 } |
377 | 377 |
378 // Convert the radix to an integer and check the range. | 378 // Convert the radix to an integer and check the range. |
379 radix = TO_INTEGER(radix); | 379 radix = TO_INTEGER(radix); |
380 if (radix < 2 || radix > 36) { | 380 if (radix < 2 || radix > 36) { |
381 throw new $RangeError('toString() radix argument must be between 2 and 36'); | 381 throw new $RangeError('toString() radix argument must be between 2 and 36'); |
382 } | 382 } |
383 // Convert the number to a string in the given radix. | 383 // Convert the number to a string in the given radix. |
384 return %NumberToRadixString(number, radix); | 384 return %NumberToRadixString(number, radix); |
385 } | 385 } |
386 | 386 |
387 | 387 |
388 // ECMA-262 section 15.7.4.3 | 388 // ECMA-262 section 15.7.4.3 |
389 function NumberToLocaleString() { | 389 function NumberToLocaleString() { |
390 return this.toString(); | 390 return this.toString(); |
391 } | 391 } |
392 | 392 |
393 | 393 |
394 // ECMA-262 section 15.7.4.4 | 394 // ECMA-262 section 15.7.4.4 |
395 function NumberValueOf() { | 395 function NumberValueOf() { |
396 // NOTE: Both Number objects and values can enter here as | 396 // NOTE: Both Number objects and values can enter here as |
397 // 'this'. This is not as dictated by ECMA-262. | 397 // 'this'. This is not as dictated by ECMA-262. |
398 if (!IS_NUMBER(this) && !%HasNumberClass(this)) | 398 if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) |
399 throw new $TypeError('Number.prototype.valueOf is not generic'); | 399 throw new $TypeError('Number.prototype.valueOf is not generic'); |
400 return %_ValueOf(this); | 400 return %_ValueOf(this); |
401 } | 401 } |
402 | 402 |
403 | 403 |
404 // ECMA-262 section 15.7.4.5 | 404 // ECMA-262 section 15.7.4.5 |
405 function NumberToFixed(fractionDigits) { | 405 function NumberToFixed(fractionDigits) { |
406 var f = TO_INTEGER(fractionDigits); | 406 var f = TO_INTEGER(fractionDigits); |
407 if (f < 0 || f > 20) { | 407 if (f < 0 || f > 20) { |
408 throw new $RangeError("toFixed() digits argument must be between 0 and 20"); | 408 throw new $RangeError("toFixed() digits argument must be between 0 and 20"); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 SetupNumber(); | 495 SetupNumber(); |
496 | 496 |
497 | 497 |
498 | 498 |
499 // ---------------------------------------------------------------------------- | 499 // ---------------------------------------------------------------------------- |
500 // Function | 500 // Function |
501 | 501 |
502 $Function.prototype.constructor = $Function; | 502 $Function.prototype.constructor = $Function; |
503 | 503 |
504 function FunctionSourceString(func) { | 504 function FunctionSourceString(func) { |
505 // NOTE: Both Function objects and values can enter here as | 505 if (!IS_FUNCTION(func)) { |
506 // 'func'. This is not as dictated by ECMA-262. | |
507 if (!IS_FUNCTION(func) && !%HasFunctionClass(func)) | |
508 throw new $TypeError('Function.prototype.toString is not generic'); | 506 throw new $TypeError('Function.prototype.toString is not generic'); |
| 507 } |
509 | 508 |
510 var source = %FunctionGetSourceCode(func); | 509 var source = %FunctionGetSourceCode(func); |
511 if (!IS_STRING(source)) { | 510 if (!IS_STRING(source)) { |
512 var name = %FunctionGetName(func); | 511 var name = %FunctionGetName(func); |
513 if (name) { | 512 if (name) { |
514 // Mimic what KJS does. | 513 // Mimic what KJS does. |
515 return 'function ' + name + '() { [native code] }'; | 514 return 'function ' + name + '() { [native code] }'; |
516 } else { | 515 } else { |
517 return 'function () { [native code] }'; | 516 return 'function () { [native code] }'; |
518 } | 517 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 562 |
564 // ---------------------------------------------------------------------------- | 563 // ---------------------------------------------------------------------------- |
565 | 564 |
566 function SetupFunction() { | 565 function SetupFunction() { |
567 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 566 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
568 "toString", FunctionToString | 567 "toString", FunctionToString |
569 )); | 568 )); |
570 } | 569 } |
571 | 570 |
572 SetupFunction(); | 571 SetupFunction(); |
OLD | NEW |