Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: src/runtime.js

Issue 1260273002: Optimize ToNumber and NonNumberToNumber. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add comments. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 785
786 // ECMA-262, section 9.3, page 31. 786 // ECMA-262, section 9.3, page 31.
787 function ToNumber(x) { 787 function ToNumber(x) {
788 if (IS_NUMBER(x)) return x; 788 if (IS_NUMBER(x)) return x;
789 if (IS_STRING(x)) { 789 if (IS_STRING(x)) {
790 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) 790 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x)
791 : %StringToNumber(x); 791 : %StringToNumber(x);
792 } 792 }
793 if (IS_BOOLEAN(x)) return x ? 1 : 0; 793 if (IS_BOOLEAN(x)) return x ? 1 : 0;
794 if (IS_UNDEFINED(x)) return NAN; 794 if (IS_UNDEFINED(x)) return NAN;
795 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); 795 // Types that can't be converted to number are caught in DefaultNumber.
796 if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber);
797 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); 796 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
798 } 797 }
799 798
800 function NonNumberToNumber(x) { 799 function NonNumberToNumber(x) {
801 if (IS_STRING(x)) { 800 if (IS_STRING(x)) {
802 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) 801 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x)
803 : %StringToNumber(x); 802 : %StringToNumber(x);
804 } 803 }
805 if (IS_BOOLEAN(x)) return x ? 1 : 0; 804 if (IS_BOOLEAN(x)) return x ? 1 : 0;
806 if (IS_UNDEFINED(x)) return NAN; 805 if (IS_UNDEFINED(x)) return NAN;
807 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); 806 // Types that can't be converted to number are caught in DefaultNumber.
808 if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber);
809 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); 807 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
810 } 808 }
811 809
812 810
813 // ECMA-262, section 9.8, page 35. 811 // ECMA-262, section 9.8, page 35.
814 function ToString(x) { 812 function ToString(x) {
815 if (IS_STRING(x)) return x; 813 if (IS_STRING(x)) return x;
816 if (IS_NUMBER(x)) return %_NumberToString(x); 814 if (IS_NUMBER(x)) return %_NumberToString(x);
817 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; 815 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
818 if (IS_UNDEFINED(x)) return 'undefined'; 816 if (IS_UNDEFINED(x)) return 'undefined';
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 function IsConcatSpreadable(O) { 935 function IsConcatSpreadable(O) {
938 if (!IS_SPEC_OBJECT(O)) return false; 936 if (!IS_SPEC_OBJECT(O)) return false;
939 var spreadable = O[symbolIsConcatSpreadable]; 937 var spreadable = O[symbolIsConcatSpreadable];
940 if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O); 938 if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O);
941 return ToBoolean(spreadable); 939 return ToBoolean(spreadable);
942 } 940 }
943 941
944 942
945 // ECMA-262, section 8.6.2.6, page 28. 943 // ECMA-262, section 8.6.2.6, page 28.
946 function DefaultNumber(x) { 944 function DefaultNumber(x) {
947 if (!IS_SYMBOL_WRAPPER(x) && !IS_FLOAT32X4_WRAPPER(x)) { 945 var valueOf = x.valueOf;
948 var valueOf = x.valueOf; 946 if (IS_SPEC_FUNCTION(valueOf)) {
949 if (IS_SPEC_FUNCTION(valueOf)) { 947 var v = %_CallFunction(x, valueOf);
950 var v = %_CallFunction(x, valueOf); 948 if (IS_SYMBOL(v)) throw MakeTypeError(kSymbolToNumber);
951 if (IsPrimitive(v)) return v; 949 if (IS_FLOAT32X4(v)) throw MakeTypeError(kSimdToNumber);
952 } 950 if (IsPrimitive(v)) return v;
953 951 }
954 var toString = x.toString; 952 var toString = x.toString;
955 if (IS_SPEC_FUNCTION(toString)) { 953 if (IS_SPEC_FUNCTION(toString)) {
956 var s = %_CallFunction(x, toString); 954 var s = %_CallFunction(x, toString);
957 if (IsPrimitive(s)) return s; 955 if (IsPrimitive(s)) return s;
958 }
959 } 956 }
960 throw MakeTypeError(kCannotConvertToPrimitive); 957 throw MakeTypeError(kCannotConvertToPrimitive);
961 } 958 }
962 959
963 // ECMA-262, section 8.6.2.6, page 28. 960 // ECMA-262, section 8.6.2.6, page 28.
964 function DefaultString(x) { 961 function DefaultString(x) {
965 if (!IS_SYMBOL_WRAPPER(x)) { 962 if (!IS_SYMBOL_WRAPPER(x)) {
966 var toString = x.toString; 963 var toString = x.toString;
967 if (IS_SPEC_FUNCTION(toString)) { 964 if (IS_SPEC_FUNCTION(toString)) {
968 var s = %_CallFunction(x, toString); 965 var s = %_CallFunction(x, toString);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 $toLength = ToLength; 1006 $toLength = ToLength;
1010 $toName = ToName; 1007 $toName = ToName;
1011 $toNumber = ToNumber; 1008 $toNumber = ToNumber;
1012 $toObject = ToObject; 1009 $toObject = ToObject;
1013 $toPositiveInteger = ToPositiveInteger; 1010 $toPositiveInteger = ToPositiveInteger;
1014 $toPrimitive = ToPrimitive; 1011 $toPrimitive = ToPrimitive;
1015 $toString = ToString; 1012 $toString = ToString;
1016 $toUint32 = ToUint32; 1013 $toUint32 = ToUint32;
1017 1014
1018 }) 1015 })
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698