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'. | 9 // ALL CAPS. The compiled code passes the first argument in 'this'. |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 var INSTANCE_OF; | 51 var INSTANCE_OF; |
52 var CALL_NON_FUNCTION; | 52 var CALL_NON_FUNCTION; |
53 var CALL_NON_FUNCTION_AS_CONSTRUCTOR; | 53 var CALL_NON_FUNCTION_AS_CONSTRUCTOR; |
54 var CALL_FUNCTION_PROXY; | 54 var CALL_FUNCTION_PROXY; |
55 var CALL_FUNCTION_PROXY_AS_CONSTRUCTOR; | 55 var CALL_FUNCTION_PROXY_AS_CONSTRUCTOR; |
56 var CONCAT_ITERABLE_TO_ARRAY; | 56 var CONCAT_ITERABLE_TO_ARRAY; |
57 var APPLY_PREPARE; | 57 var APPLY_PREPARE; |
58 var REFLECT_APPLY_PREPARE; | 58 var REFLECT_APPLY_PREPARE; |
59 var REFLECT_CONSTRUCT_PREPARE; | 59 var REFLECT_CONSTRUCT_PREPARE; |
60 var STACK_OVERFLOW; | 60 var STACK_OVERFLOW; |
61 var TO_OBJECT; | |
62 var TO_NUMBER; | 61 var TO_NUMBER; |
63 var TO_STRING; | 62 var TO_STRING; |
64 var TO_NAME; | 63 var TO_NAME; |
65 | 64 |
66 var $defaultNumber; | 65 var $defaultNumber; |
67 var $defaultString; | 66 var $defaultString; |
68 var $NaN; | 67 var $NaN; |
69 var $nonNumberToNumber; | 68 var $nonNumberToNumber; |
70 var $nonStringToString; | 69 var $nonStringToString; |
71 var $sameValue; | 70 var $sameValue; |
72 var $sameValueZero; | 71 var $sameValueZero; |
73 var $toBoolean; | 72 var $toBoolean; |
74 var $toInt32; | 73 var $toInt32; |
75 var $toInteger; | 74 var $toInteger; |
76 var $toLength; | 75 var $toLength; |
77 var $toName; | 76 var $toName; |
78 var $toNumber; | 77 var $toNumber; |
79 var $toObject; | |
80 var $toPositiveInteger; | 78 var $toPositiveInteger; |
81 var $toPrimitive; | 79 var $toPrimitive; |
82 var $toString; | 80 var $toString; |
83 var $toUint32; | 81 var $toUint32; |
84 | 82 |
85 (function(global, utils) { | 83 (function(global, utils) { |
86 | 84 |
87 %CheckIsBootstrapping(); | 85 %CheckIsBootstrapping(); |
88 | 86 |
89 var GlobalArray = global.Array; | 87 var GlobalArray = global.Array; |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 } | 503 } |
506 | 504 |
507 | 505 |
508 /* ----------------------------- | 506 /* ----------------------------- |
509 - - - H e l p e r s - - - | 507 - - - H e l p e r s - - - |
510 ----------------------------- | 508 ----------------------------- |
511 */ | 509 */ |
512 | 510 |
513 // ECMA-262, section 11.4.1, page 46. | 511 // ECMA-262, section 11.4.1, page 46. |
514 DELETE = function DELETE(key, language_mode) { | 512 DELETE = function DELETE(key, language_mode) { |
515 return %DeleteProperty(%$toObject(this), key, language_mode); | 513 return %DeleteProperty(TO_OBJECT(this), key, language_mode); |
516 } | 514 } |
517 | 515 |
518 | 516 |
519 // ECMA-262, section 11.8.7, page 54. | 517 // ECMA-262, section 11.8.7, page 54. |
520 IN = function IN(x) { | 518 IN = function IN(x) { |
521 if (!IS_SPEC_OBJECT(x)) { | 519 if (!IS_SPEC_OBJECT(x)) { |
522 throw %MakeTypeError(kInvalidInOperatorUse, this, x); | 520 throw %MakeTypeError(kInvalidInOperatorUse, this, x); |
523 } | 521 } |
524 if (%_IsNonNegativeSmi(this)) { | 522 if (%_IsNonNegativeSmi(this)) { |
525 if (IS_ARRAY(x) && %_HasFastPackedElements(x)) { | 523 if (IS_ARRAY(x) && %_HasFastPackedElements(x)) { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 CONCAT_ITERABLE_TO_ARRAY = function CONCAT_ITERABLE_TO_ARRAY(iterable) { | 721 CONCAT_ITERABLE_TO_ARRAY = function CONCAT_ITERABLE_TO_ARRAY(iterable) { |
724 return %$concatIterableToArray(this, iterable); | 722 return %$concatIterableToArray(this, iterable); |
725 }; | 723 }; |
726 | 724 |
727 | 725 |
728 STACK_OVERFLOW = function STACK_OVERFLOW(length) { | 726 STACK_OVERFLOW = function STACK_OVERFLOW(length) { |
729 throw %MakeRangeError(kStackOverflow); | 727 throw %MakeRangeError(kStackOverflow); |
730 } | 728 } |
731 | 729 |
732 | 730 |
733 // Convert the receiver to an object - forward to ToObject. | |
734 TO_OBJECT = function TO_OBJECT() { | |
735 return %$toObject(this); | |
736 } | |
737 | |
738 | |
739 // Convert the receiver to a number - forward to ToNumber. | 731 // Convert the receiver to a number - forward to ToNumber. |
740 TO_NUMBER = function TO_NUMBER() { | 732 TO_NUMBER = function TO_NUMBER() { |
741 return %$toNumber(this); | 733 return %$toNumber(this); |
742 } | 734 } |
743 | 735 |
744 | 736 |
745 // Convert the receiver to a string - forward to ToString. | 737 // Convert the receiver to a string - forward to ToString. |
746 TO_STRING = function TO_STRING() { | 738 TO_STRING = function TO_STRING() { |
747 return %$toString(this); | 739 return %$toString(this); |
748 } | 740 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x)); | 817 return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x)); |
826 } | 818 } |
827 | 819 |
828 | 820 |
829 // ES6 symbols | 821 // ES6 symbols |
830 function ToName(x) { | 822 function ToName(x) { |
831 return IS_SYMBOL(x) ? x : ToString(x); | 823 return IS_SYMBOL(x) ? x : ToString(x); |
832 } | 824 } |
833 | 825 |
834 | 826 |
835 // ECMA-262, section 9.9, page 36. | |
836 function ToObject(x) { | |
837 if (IS_STRING(x)) return new GlobalString(x); | |
838 if (IS_NUMBER(x)) return new GlobalNumber(x); | |
839 if (IS_BOOLEAN(x)) return new GlobalBoolean(x); | |
840 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x); | |
841 if (IS_FLOAT32X4(x)) return %NewFloat32x4Wrapper(x); | |
842 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { | |
843 throw MakeTypeError(kUndefinedOrNullToObject); | |
844 } | |
845 return x; | |
846 } | |
847 | |
848 | |
849 // ECMA-262, section 9.4, page 34. | 827 // ECMA-262, section 9.4, page 34. |
850 function ToInteger(x) { | 828 function ToInteger(x) { |
851 if (%_IsSmi(x)) return x; | 829 if (%_IsSmi(x)) return x; |
852 return %NumberToInteger(ToNumber(x)); | 830 return %NumberToInteger(ToNumber(x)); |
853 } | 831 } |
854 | 832 |
855 | 833 |
856 // ES6, draft 08-24-14, section 7.1.15 | 834 // ES6, draft 08-24-14, section 7.1.15 |
857 function ToLength(arg) { | 835 function ToLength(arg) { |
858 arg = ToInteger(arg); | 836 arg = ToInteger(arg); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 $nonNumberToNumber = NonNumberToNumber; | 977 $nonNumberToNumber = NonNumberToNumber; |
1000 $nonStringToString = NonStringToString; | 978 $nonStringToString = NonStringToString; |
1001 $sameValue = SameValue; | 979 $sameValue = SameValue; |
1002 $sameValueZero = SameValueZero; | 980 $sameValueZero = SameValueZero; |
1003 $toBoolean = ToBoolean; | 981 $toBoolean = ToBoolean; |
1004 $toInt32 = ToInt32; | 982 $toInt32 = ToInt32; |
1005 $toInteger = ToInteger; | 983 $toInteger = ToInteger; |
1006 $toLength = ToLength; | 984 $toLength = ToLength; |
1007 $toName = ToName; | 985 $toName = ToName; |
1008 $toNumber = ToNumber; | 986 $toNumber = ToNumber; |
1009 $toObject = ToObject; | |
1010 $toPositiveInteger = ToPositiveInteger; | 987 $toPositiveInteger = ToPositiveInteger; |
1011 $toPrimitive = ToPrimitive; | 988 $toPrimitive = ToPrimitive; |
1012 $toString = ToString; | 989 $toString = ToString; |
1013 $toUint32 = ToUint32; | 990 $toUint32 = ToUint32; |
1014 | 991 |
1015 }) | 992 }) |
OLD | NEW |