Chromium Code Reviews| 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 return %NumberToJSUint32(ToNumber(x)); | 569 return %NumberToJSUint32(ToNumber(x)); |
| 570 } | 570 } |
| 571 | 571 |
| 572 | 572 |
| 573 // ECMA-262, section 9.5, page 34 | 573 // ECMA-262, section 9.5, page 34 |
| 574 function ToInt32(x) { | 574 function ToInt32(x) { |
| 575 if (%_IsSmi(x)) return x; | 575 if (%_IsSmi(x)) return x; |
| 576 return %NumberToJSInt32(ToNumber(x)); | 576 return %NumberToJSInt32(ToNumber(x)); |
| 577 } | 577 } |
| 578 | 578 |
| 579 // ES6, section 7.1.15 | |
| 580 function ToLength(x) { | |
| 581 if (%_IsSmi(x) && x > 0) return x; // not >= since -0 >= +0 | |
|
mathias
2014/09/18 06:16:32
Same here.
Dmitry Lomov (no reviews)
2014/09/18 06:26:46
if %_IsSmi(x) then x can only be +0 (-0 is not Sm
| |
| 582 | |
| 583 var len = ToInteger(x); | |
| 584 if (len <= 0) return 0; | |
| 585 return MathMin(len, $Number.MAX_SAFE_INTEGER); | |
| 586 } | |
| 587 | |
| 579 | 588 |
| 580 // ES5, section 9.12 | 589 // ES5, section 9.12 |
| 581 function SameValue(x, y) { | 590 function SameValue(x, y) { |
| 582 if (typeof x != typeof y) return false; | 591 if (typeof x != typeof y) return false; |
| 583 if (IS_NUMBER(x)) { | 592 if (IS_NUMBER(x)) { |
| 584 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; | 593 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; |
| 585 // x is +0 and y is -0 or vice versa. | 594 // x is +0 and y is -0 or vice versa. |
| 586 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) { | 595 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) { |
| 587 return false; | 596 return false; |
| 588 } | 597 } |
| 589 } | 598 } |
| 590 return x === y; | 599 return x === y; |
| 591 } | 600 } |
| 592 | 601 |
| 602 // ES6, section 7.2.4 | |
| 603 function SameValueZero(x, y) { | |
| 604 if (typeof x != typeof y) return false; | |
| 605 if (IS_NUMBER(x)) { | |
| 606 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; | |
| 607 } | |
| 608 return x === y; | |
| 609 } | |
| 610 | |
| 593 | 611 |
| 594 /* --------------------------------- | 612 /* --------------------------------- |
| 595 - - - U t i l i t i e s - - - | 613 - - - U t i l i t i e s - - - |
| 596 --------------------------------- | 614 --------------------------------- |
| 597 */ | 615 */ |
| 598 | 616 |
| 599 // Returns if the given x is a primitive value - not an object or a | 617 // Returns if the given x is a primitive value - not an object or a |
| 600 // function. | 618 // function. |
| 601 function IsPrimitive(x) { | 619 function IsPrimitive(x) { |
| 602 // Even though the type of null is "object", null is still | 620 // Even though the type of null is "object", null is still |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 return i; | 666 return i; |
| 649 } | 667 } |
| 650 | 668 |
| 651 | 669 |
| 652 // NOTE: Setting the prototype for Array must take place as early as | 670 // NOTE: Setting the prototype for Array must take place as early as |
| 653 // possible due to code generation for array literals. When | 671 // possible due to code generation for array literals. When |
| 654 // generating code for a array literal a boilerplate array is created | 672 // generating code for a array literal a boilerplate array is created |
| 655 // that is cloned when running the code. It is essential that the | 673 // that is cloned when running the code. It is essential that the |
| 656 // boilerplate gets the right prototype. | 674 // boilerplate gets the right prototype. |
| 657 %FunctionSetPrototype($Array, new $Array(0)); | 675 %FunctionSetPrototype($Array, new $Array(0)); |
| OLD | NEW |