| 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 305 |
| 306 function BooleanValueOf() { | 306 function BooleanValueOf() { |
| 307 // NOTE: Both Boolean objects and values can enter here as | 307 // NOTE: Both Boolean objects and values can enter here as |
| 308 // 'this'. This is not as dictated by ECMA-262. | 308 // 'this'. This is not as dictated by ECMA-262. |
| 309 if (!IS_BOOLEAN(this) && !%HasBooleanClass(this)) | 309 if (!IS_BOOLEAN(this) && !%HasBooleanClass(this)) |
| 310 throw new $TypeError('Boolean.prototype.valueOf is not generic'); | 310 throw new $TypeError('Boolean.prototype.valueOf is not generic'); |
| 311 return %_ValueOf(this); | 311 return %_ValueOf(this); |
| 312 } | 312 } |
| 313 | 313 |
| 314 | 314 |
| 315 function BooleanToJSON(key) { |
| 316 return CheckJSONPrimitive(this.valueOf()); |
| 317 } |
| 318 |
| 319 |
| 315 // ---------------------------------------------------------------------------- | 320 // ---------------------------------------------------------------------------- |
| 316 | 321 |
| 317 | 322 |
| 318 function SetupBoolean() { | 323 function SetupBoolean() { |
| 319 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( | 324 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( |
| 320 "toString", BooleanToString, | 325 "toString", BooleanToString, |
| 321 "valueOf", BooleanValueOf | 326 "valueOf", BooleanValueOf, |
| 327 "toJSON", BooleanToJSON |
| 322 )); | 328 )); |
| 323 } | 329 } |
| 324 | 330 |
| 325 SetupBoolean(); | 331 SetupBoolean(); |
| 326 | 332 |
| 327 // ---------------------------------------------------------------------------- | 333 // ---------------------------------------------------------------------------- |
| 328 // Number | 334 // Number |
| 329 | 335 |
| 330 // Set the Number function and constructor. | 336 // Set the Number function and constructor. |
| 331 %SetCode($Number, function(x) { | 337 %SetCode($Number, function(x) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); | 417 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); |
| 412 var p = TO_INTEGER(precision); | 418 var p = TO_INTEGER(precision); |
| 413 if (p < 1 || p > 21) { | 419 if (p < 1 || p > 21) { |
| 414 throw new $RangeError("toPrecision() argument must be between 1 and 21"); | 420 throw new $RangeError("toPrecision() argument must be between 1 and 21"); |
| 415 } | 421 } |
| 416 var x = ToNumber(this); | 422 var x = ToNumber(this); |
| 417 return %NumberToPrecision(x, p); | 423 return %NumberToPrecision(x, p); |
| 418 } | 424 } |
| 419 | 425 |
| 420 | 426 |
| 427 function CheckJSONPrimitive(val) { |
| 428 if (!IsPrimitive(val)) |
| 429 throw MakeTypeError('result_not_primitive', ['toJSON', val]); |
| 430 return val; |
| 431 } |
| 432 |
| 433 |
| 434 function NumberToJSON(key) { |
| 435 return CheckJSONPrimitive(this.valueOf()); |
| 436 } |
| 437 |
| 438 |
| 421 // ---------------------------------------------------------------------------- | 439 // ---------------------------------------------------------------------------- |
| 422 | 440 |
| 423 function SetupNumber() { | 441 function SetupNumber() { |
| 424 // Setup the constructor property on the Number prototype object. | 442 // Setup the constructor property on the Number prototype object. |
| 425 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); | 443 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); |
| 426 | 444 |
| 427 // ECMA-262 section 15.7.3.1. | 445 // ECMA-262 section 15.7.3.1. |
| 428 %SetProperty($Number, | 446 %SetProperty($Number, |
| 429 "MAX_VALUE", | 447 "MAX_VALUE", |
| 430 1.7976931348623157e+308, | 448 1.7976931348623157e+308, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 448 1/0, | 466 1/0, |
| 449 DONT_ENUM | DONT_DELETE | READ_ONLY); | 467 DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 450 | 468 |
| 451 // Setup non-enumerable functions on the Number prototype object. | 469 // Setup non-enumerable functions on the Number prototype object. |
| 452 InstallFunctions($Number.prototype, DONT_ENUM, $Array( | 470 InstallFunctions($Number.prototype, DONT_ENUM, $Array( |
| 453 "toString", NumberToString, | 471 "toString", NumberToString, |
| 454 "toLocaleString", NumberToLocaleString, | 472 "toLocaleString", NumberToLocaleString, |
| 455 "valueOf", NumberValueOf, | 473 "valueOf", NumberValueOf, |
| 456 "toFixed", NumberToFixed, | 474 "toFixed", NumberToFixed, |
| 457 "toExponential", NumberToExponential, | 475 "toExponential", NumberToExponential, |
| 458 "toPrecision", NumberToPrecision | 476 "toPrecision", NumberToPrecision, |
| 477 "toJSON", NumberToJSON |
| 459 )); | 478 )); |
| 460 } | 479 } |
| 461 | 480 |
| 462 SetupNumber(); | 481 SetupNumber(); |
| 463 | 482 |
| 464 | 483 |
| 465 | 484 |
| 466 // ---------------------------------------------------------------------------- | 485 // ---------------------------------------------------------------------------- |
| 467 // Function | 486 // Function |
| 468 | 487 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 // ---------------------------------------------------------------------------- | 550 // ---------------------------------------------------------------------------- |
| 532 | 551 |
| 533 function SetupFunction() { | 552 function SetupFunction() { |
| 534 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 553 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 535 "toString", FunctionToString | 554 "toString", FunctionToString |
| 536 )); | 555 )); |
| 537 } | 556 } |
| 538 | 557 |
| 539 SetupFunction(); | 558 SetupFunction(); |
| 540 | 559 |
| OLD | NEW |