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 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This files contains runtime support implemented in JavaScript. | 5 // This files contains runtime support implemented in JavaScript. |
6 | 6 |
7 // CAUTION: Some of the functions specified in this file are called | 7 // CAUTION: Some of the functions specified in this file are called |
8 // directly from compiled code. These are the functions with names in | 8 // directly from compiled code. These are the functions with names in |
9 // ALL CAPS. The compiled code passes the first argument in 'this' and | 9 // ALL CAPS. The compiled code passes the first argument in 'this' and |
10 // it does not push the function onto the stack. This means that you | 10 // it does not push the function onto the stack. This means that you |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 return %ToNumber(this); | 458 return %ToNumber(this); |
459 } | 459 } |
460 | 460 |
461 | 461 |
462 // Convert the receiver to a string - forward to ToString. | 462 // Convert the receiver to a string - forward to ToString. |
463 function TO_STRING() { | 463 function TO_STRING() { |
464 return %ToString(this); | 464 return %ToString(this); |
465 } | 465 } |
466 | 466 |
467 | 467 |
| 468 // ES6, draft 07-18-14, section 7.1.15 |
| 469 function TO_LENGTH(arg) { |
| 470 arg = ToInteger(arg); |
| 471 if (arg < +0) { |
| 472 return 0; |
| 473 } |
| 474 return arg < $Number.MAX_SAFE_INTEGER ? arg : $Number.MAX_SAFE_INTEGER; |
| 475 } |
| 476 |
| 477 |
468 /* ------------------------------------- | 478 /* ------------------------------------- |
469 - - - C o n v e r s i o n s - - - | 479 - - - C o n v e r s i o n s - - - |
470 ------------------------------------- | 480 ------------------------------------- |
471 */ | 481 */ |
472 | 482 |
473 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, | 483 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, |
474 // (1) for number hint, and (2) for string hint. | 484 // (1) for number hint, and (2) for string hint. |
475 function ToPrimitive(x, hint) { | 485 function ToPrimitive(x, hint) { |
476 // Fast case check. | 486 // Fast case check. |
477 if (IS_STRING(x)) return x; | 487 if (IS_STRING(x)) return x; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 return i; | 658 return i; |
649 } | 659 } |
650 | 660 |
651 | 661 |
652 // NOTE: Setting the prototype for Array must take place as early as | 662 // NOTE: Setting the prototype for Array must take place as early as |
653 // possible due to code generation for array literals. When | 663 // possible due to code generation for array literals. When |
654 // generating code for a array literal a boilerplate array is created | 664 // generating code for a array literal a boilerplate array is created |
655 // that is cloned when running the code. It is essential that the | 665 // that is cloned when running the code. It is essential that the |
656 // boilerplate gets the right prototype. | 666 // boilerplate gets the right prototype. |
657 %FunctionSetPrototype($Array, new $Array(0)); | 667 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |