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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 return %ToNumber(this); | 457 return %ToNumber(this); |
458 } | 458 } |
459 | 459 |
460 | 460 |
461 // Convert the receiver to a string - forward to ToString. | 461 // Convert the receiver to a string - forward to ToString. |
462 function TO_STRING() { | 462 function TO_STRING() { |
463 return %ToString(this); | 463 return %ToString(this); |
464 } | 464 } |
465 | 465 |
466 | 466 |
| 467 // ES6, draft 05-22-14, section 7.1.15 |
| 468 function TO_LENGTH(arg) { |
| 469 arg = ToInteger(arg); |
| 470 if (arg < +0) { |
| 471 return 0; |
| 472 } |
| 473 return arg < $Number.MAX_SAFE_INTEGER ? arg : $Number.MAX_SAFE_INTEGER; |
| 474 } |
| 475 |
| 476 |
467 /* ------------------------------------- | 477 /* ------------------------------------- |
468 - - - C o n v e r s i o n s - - - | 478 - - - C o n v e r s i o n s - - - |
469 ------------------------------------- | 479 ------------------------------------- |
470 */ | 480 */ |
471 | 481 |
472 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, | 482 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, |
473 // (1) for number hint, and (2) for string hint. | 483 // (1) for number hint, and (2) for string hint. |
474 function ToPrimitive(x, hint) { | 484 function ToPrimitive(x, hint) { |
475 // Fast case check. | 485 // Fast case check. |
476 if (IS_STRING(x)) return x; | 486 if (IS_STRING(x)) return x; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 return i; | 657 return i; |
648 } | 658 } |
649 | 659 |
650 | 660 |
651 // NOTE: Setting the prototype for Array must take place as early as | 661 // NOTE: Setting the prototype for Array must take place as early as |
652 // possible due to code generation for array literals. When | 662 // possible due to code generation for array literals. When |
653 // generating code for a array literal a boilerplate array is created | 663 // generating code for a array literal a boilerplate array is created |
654 // that is cloned when running the code. It is essential that the | 664 // that is cloned when running the code. It is essential that the |
655 // boilerplate gets the right prototype. | 665 // boilerplate gets the right prototype. |
656 %FunctionSetPrototype($Array, new $Array(0)); | 666 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |