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

Side by Side Diff: src/runtime.js

Issue 1275013004: [runtime] Simplify TO_INT32/TO_UINT32 abstract operations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 | « src/macros.py ('k') | src/runtime/runtime.h » ('j') | 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 var TO_NAME; 63 var TO_NAME;
64 64
65 var $defaultNumber; 65 var $defaultNumber;
66 var $defaultString; 66 var $defaultString;
67 var $NaN; 67 var $NaN;
68 var $nonNumberToNumber; 68 var $nonNumberToNumber;
69 var $nonStringToString; 69 var $nonStringToString;
70 var $sameValue; 70 var $sameValue;
71 var $sameValueZero; 71 var $sameValueZero;
72 var $toBoolean; 72 var $toBoolean;
73 var $toInt32;
74 var $toInteger; 73 var $toInteger;
75 var $toLength; 74 var $toLength;
76 var $toName; 75 var $toName;
77 var $toNumber; 76 var $toNumber;
78 var $toPositiveInteger; 77 var $toPositiveInteger;
79 var $toPrimitive; 78 var $toPrimitive;
80 var $toString; 79 var $toString;
81 var $toUint32;
82 80
83 (function(global, utils) { 81 (function(global, utils) {
84 82
85 %CheckIsBootstrapping(); 83 %CheckIsBootstrapping();
86 84
87 var GlobalArray = global.Array; 85 var GlobalArray = global.Array;
88 var GlobalBoolean = global.Boolean; 86 var GlobalBoolean = global.Boolean;
89 var GlobalString = global.String; 87 var GlobalString = global.String;
90 var GlobalNumber = global.Number; 88 var GlobalNumber = global.Number;
91 89
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 // array. This is the fast case. If this fails, we do the slow case 601 // array. This is the fast case. If this fails, we do the slow case
604 // that takes care of more eventualities. 602 // that takes care of more eventualities.
605 if (IS_ARRAY(args)) { 603 if (IS_ARRAY(args)) {
606 length = args.length; 604 length = args.length;
607 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && 605 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength &&
608 IS_SPEC_FUNCTION(this)) { 606 IS_SPEC_FUNCTION(this)) {
609 return length; 607 return length;
610 } 608 }
611 } 609 }
612 610
613 length = (args == null) ? 0 : %$toUint32(args.length); 611 length = (args == null) ? 0 : TO_UINT32(args.length);
614 612
615 // We can handle any number of apply arguments if the stack is 613 // We can handle any number of apply arguments if the stack is
616 // big enough, but sanity check the value to avoid overflow when 614 // big enough, but sanity check the value to avoid overflow when
617 // multiplying with pointer size. 615 // multiplying with pointer size.
618 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); 616 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow);
619 617
620 if (!IS_SPEC_FUNCTION(this)) { 618 if (!IS_SPEC_FUNCTION(this)) {
621 throw %MakeTypeError(kApplyNonFunction, %$toString(this), typeof this); 619 throw %MakeTypeError(kApplyNonFunction, %$toString(this), typeof this);
622 } 620 }
623 621
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 829
832 // ES6, draft 08-24-14, section 7.1.15 830 // ES6, draft 08-24-14, section 7.1.15
833 function ToLength(arg) { 831 function ToLength(arg) {
834 arg = ToInteger(arg); 832 arg = ToInteger(arg);
835 if (arg < 0) return 0; 833 if (arg < 0) return 0;
836 return arg < GlobalNumber.MAX_SAFE_INTEGER ? arg 834 return arg < GlobalNumber.MAX_SAFE_INTEGER ? arg
837 : GlobalNumber.MAX_SAFE_INTEGER; 835 : GlobalNumber.MAX_SAFE_INTEGER;
838 } 836 }
839 837
840 838
841 // ECMA-262, section 9.6, page 34.
842 function ToUint32(x) {
843 if (%_IsSmi(x) && x >= 0) return x;
844 return %NumberToJSUint32(ToNumber(x));
845 }
846
847
848 // ECMA-262, section 9.5, page 34
849 function ToInt32(x) {
850 if (%_IsSmi(x)) return x;
851 return %NumberToJSInt32(ToNumber(x));
852 }
853
854
855 // ES5, section 9.12 839 // ES5, section 9.12
856 function SameValue(x, y) { 840 function SameValue(x, y) {
857 if (typeof x != typeof y) return false; 841 if (typeof x != typeof y) return false;
858 if (IS_NUMBER(x)) { 842 if (IS_NUMBER(x)) {
859 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; 843 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
860 // x is +0 and y is -0 or vice versa. 844 // x is +0 and y is -0 or vice versa.
861 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) { 845 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) {
862 return false; 846 return false;
863 } 847 }
864 } 848 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 950
967 $concatIterableToArray = ConcatIterableToArray; 951 $concatIterableToArray = ConcatIterableToArray;
968 $defaultNumber = DefaultNumber; 952 $defaultNumber = DefaultNumber;
969 $defaultString = DefaultString; 953 $defaultString = DefaultString;
970 $NaN = %GetRootNaN(); 954 $NaN = %GetRootNaN();
971 $nonNumberToNumber = NonNumberToNumber; 955 $nonNumberToNumber = NonNumberToNumber;
972 $nonStringToString = NonStringToString; 956 $nonStringToString = NonStringToString;
973 $sameValue = SameValue; 957 $sameValue = SameValue;
974 $sameValueZero = SameValueZero; 958 $sameValueZero = SameValueZero;
975 $toBoolean = ToBoolean; 959 $toBoolean = ToBoolean;
976 $toInt32 = ToInt32;
977 $toInteger = ToInteger; 960 $toInteger = ToInteger;
978 $toLength = ToLength; 961 $toLength = ToLength;
979 $toName = ToName; 962 $toName = ToName;
980 $toNumber = ToNumber; 963 $toNumber = ToNumber;
981 $toPositiveInteger = ToPositiveInteger; 964 $toPositiveInteger = ToPositiveInteger;
982 $toPrimitive = ToPrimitive; 965 $toPrimitive = ToPrimitive;
983 $toString = ToString; 966 $toString = ToString;
984 $toUint32 = ToUint32;
985 967
986 }) 968 })
OLDNEW
« no previous file with comments | « src/macros.py ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698