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

Side by Side Diff: src/v8natives.js

Issue 1323543002: [runtime] Replace %to_string_fun with %_ToString. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@ToStringStub
Patch Set: REBASE. Fixes Created 5 years, 2 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/uri.js ('k') | test/cctest/compiler/test-run-jscalls.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 (function(global, utils) { 5 (function(global, utils) {
6 6
7 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ---------------------------------------------------------------------------- 9 // ----------------------------------------------------------------------------
10 // Imports 10 // Imports
11 11
12 var FLAG_harmony_tostring; 12 var FLAG_harmony_tostring;
13 var GlobalArray = global.Array; 13 var GlobalArray = global.Array;
14 var GlobalBoolean = global.Boolean; 14 var GlobalBoolean = global.Boolean;
15 var GlobalFunction = global.Function; 15 var GlobalFunction = global.Function;
16 var GlobalNumber = global.Number; 16 var GlobalNumber = global.Number;
17 var GlobalObject = global.Object; 17 var GlobalObject = global.Object;
18 var InternalArray = utils.InternalArray; 18 var InternalArray = utils.InternalArray;
19 var iteratorSymbol = utils.ImportNow("iterator_symbol"); 19 var iteratorSymbol = utils.ImportNow("iterator_symbol");
20 var MathAbs; 20 var MathAbs;
21 var ProxyDelegateCallAndConstruct; 21 var ProxyDelegateCallAndConstruct;
22 var ProxyDerivedHasOwnTrap; 22 var ProxyDerivedHasOwnTrap;
23 var ProxyDerivedKeysTrap; 23 var ProxyDerivedKeysTrap;
24 var StringIndexOf; 24 var StringIndexOf;
25 var ToBoolean = utils.ImportNow("ToBoolean"); 25 var ToBoolean = utils.ImportNow("ToBoolean");
26 var ToNumber = utils.ImportNow("ToNumber"); 26 var ToNumber = utils.ImportNow("ToNumber");
27 var ToString;
28 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); 27 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
29 28
30 utils.Import(function(from) { 29 utils.Import(function(from) {
31 MathAbs = from.MathAbs; 30 MathAbs = from.MathAbs;
32 StringIndexOf = from.StringIndexOf; 31 StringIndexOf = from.StringIndexOf;
33 ToString = from.ToString;
34 }); 32 });
35 33
36 utils.ImportFromExperimental(function(from) { 34 utils.ImportFromExperimental(function(from) {
37 FLAG_harmony_tostring = from.FLAG_harmony_tostring; 35 FLAG_harmony_tostring = from.FLAG_harmony_tostring;
38 ProxyDelegateCallAndConstruct = from.ProxyDelegateCallAndConstruct; 36 ProxyDelegateCallAndConstruct = from.ProxyDelegateCallAndConstruct;
39 ProxyDerivedHasOwnTrap = from.ProxyDerivedHasOwnTrap; 37 ProxyDerivedHasOwnTrap = from.ProxyDerivedHasOwnTrap;
40 ProxyDerivedKeysTrap = from.ProxyDerivedKeysTrap; 38 ProxyDerivedKeysTrap = from.ProxyDerivedKeysTrap;
41 }); 39 });
42 40
43 // ---------------------------------------------------------------------------- 41 // ----------------------------------------------------------------------------
(...skipping 21 matching lines...) Expand all
65 // vs 800ns). The following optimization makes parseInt on a 63 // vs 800ns). The following optimization makes parseInt on a
66 // non-Smi number 9 times faster (230ns vs 2070ns). Together 64 // non-Smi number 9 times faster (230ns vs 2070ns). Together
67 // they make parseInt on a string 1.4% slower (274ns vs 270ns). 65 // they make parseInt on a string 1.4% slower (274ns vs 270ns).
68 if (%_IsSmi(string)) return string; 66 if (%_IsSmi(string)) return string;
69 if (IS_NUMBER(string) && 67 if (IS_NUMBER(string) &&
70 ((0.01 < string && string < 1e9) || 68 ((0.01 < string && string < 1e9) ||
71 (-1e9 < string && string < -0.01))) { 69 (-1e9 < string && string < -0.01))) {
72 // Truncate number. 70 // Truncate number.
73 return string | 0; 71 return string | 0;
74 } 72 }
75 string = TO_STRING_INLINE(string); 73 string = TO_STRING(string);
76 radix = radix | 0; 74 radix = radix | 0;
77 } else { 75 } else {
78 // The spec says ToString should be evaluated before ToInt32. 76 // The spec says ToString should be evaluated before ToInt32.
79 string = TO_STRING_INLINE(string); 77 string = TO_STRING(string);
80 radix = TO_INT32(radix); 78 radix = TO_INT32(radix);
81 if (!(radix == 0 || (2 <= radix && radix <= 36))) { 79 if (!(radix == 0 || (2 <= radix && radix <= 36))) {
82 return NAN; 80 return NAN;
83 } 81 }
84 } 82 }
85 83
86 if (%_HasCachedArrayIndex(string) && 84 if (%_HasCachedArrayIndex(string) &&
87 (radix == 0 || radix == 10)) { 85 (radix == 0 || radix == 10)) {
88 return %_GetCachedArrayIndex(string); 86 return %_GetCachedArrayIndex(string);
89 } 87 }
90 return %StringParseInt(string, radix); 88 return %StringParseInt(string, radix);
91 } 89 }
92 90
93 91
94 // ECMA-262 - 15.1.2.3 92 // ECMA-262 - 15.1.2.3
95 function GlobalParseFloat(string) { 93 function GlobalParseFloat(string) {
96 string = TO_STRING_INLINE(string); 94 string = TO_STRING(string);
97 if (%_HasCachedArrayIndex(string)) return %_GetCachedArrayIndex(string); 95 if (%_HasCachedArrayIndex(string)) return %_GetCachedArrayIndex(string);
98 return %StringParseFloat(string); 96 return %StringParseFloat(string);
99 } 97 }
100 98
101 99
102 function GlobalEval(x) { 100 function GlobalEval(x) {
103 if (!IS_STRING(x)) return x; 101 if (!IS_STRING(x)) return x;
104 102
105 var global_proxy = %GlobalProxy(GlobalEval); 103 var global_proxy = %GlobalProxy(GlobalEval);
106 104
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 return true; 797 return true;
800 } 798 }
801 799
802 800
803 // ES5 section 15.4.5.1. 801 // ES5 section 15.4.5.1.
804 function DefineArrayProperty(obj, p, desc, should_throw) { 802 function DefineArrayProperty(obj, p, desc, should_throw) {
805 // Step 3 - Special handling for array index. 803 // Step 3 - Special handling for array index.
806 if (!IS_SYMBOL(p)) { 804 if (!IS_SYMBOL(p)) {
807 var index = TO_UINT32(p); 805 var index = TO_UINT32(p);
808 var emit_splice = false; 806 var emit_splice = false;
809 if (ToString(index) == p && index != 4294967295) { 807 if (TO_STRING(index) == p && index != 4294967295) {
810 var length = obj.length; 808 var length = obj.length;
811 if (index >= length && %IsObserved(obj)) { 809 if (index >= length && %IsObserved(obj)) {
812 emit_splice = true; 810 emit_splice = true;
813 $observeBeginPerformSplice(obj); 811 $observeBeginPerformSplice(obj);
814 } 812 }
815 813
816 var length_desc = GetOwnPropertyJS(obj, "length"); 814 var length_desc = GetOwnPropertyJS(obj, "length");
817 if ((index >= length && !length_desc.isWritable()) || 815 if ((index >= length && !length_desc.isWritable()) ||
818 !DefineObjectProperty(obj, p, desc, true)) { 816 !DefineObjectProperty(obj, p, desc, true)) {
819 if (emit_splice) 817 if (emit_splice)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 var seenKeys = { __proto__: null }; 965 var seenKeys = { __proto__: null };
968 var j = 0; 966 var j = 0;
969 for (var i = 0; i < propertyNames.length; ++i) { 967 for (var i = 0; i < propertyNames.length; ++i) {
970 var name = propertyNames[i]; 968 var name = propertyNames[i];
971 if (IS_SYMBOL(name)) { 969 if (IS_SYMBOL(name)) {
972 if ((filter & PROPERTY_ATTRIBUTES_SYMBOLIC) || IS_PRIVATE(name)) { 970 if ((filter & PROPERTY_ATTRIBUTES_SYMBOLIC) || IS_PRIVATE(name)) {
973 continue; 971 continue;
974 } 972 }
975 } else { 973 } else {
976 if (filter & PROPERTY_ATTRIBUTES_STRING) continue; 974 if (filter & PROPERTY_ATTRIBUTES_STRING) continue;
977 name = ToString(name); 975 name = TO_STRING(name);
978 } 976 }
979 if (seenKeys[name]) continue; 977 if (seenKeys[name]) continue;
980 seenKeys[name] = true; 978 seenKeys[name] = true;
981 propertyNames[j++] = name; 979 propertyNames[j++] = name;
982 } 980 }
983 propertyNames.length = j; 981 propertyNames.length = j;
984 } 982 }
985 983
986 return propertyNames; 984 return propertyNames;
987 } 985 }
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 function NumberToPrecisionJS(precision) { 1529 function NumberToPrecisionJS(precision) {
1532 var x = this; 1530 var x = this;
1533 if (!IS_NUMBER(this)) { 1531 if (!IS_NUMBER(this)) {
1534 if (!IS_NUMBER_WRAPPER(this)) { 1532 if (!IS_NUMBER_WRAPPER(this)) {
1535 throw MakeTypeError(kIncompatibleMethodReceiver, 1533 throw MakeTypeError(kIncompatibleMethodReceiver,
1536 "Number.prototype.toPrecision", this); 1534 "Number.prototype.toPrecision", this);
1537 } 1535 }
1538 // Get the value of this number in case it's an object. 1536 // Get the value of this number in case it's an object.
1539 x = %_ValueOf(this); 1537 x = %_ValueOf(this);
1540 } 1538 }
1541 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); 1539 if (IS_UNDEFINED(precision)) return TO_STRING(x);
1542 var p = TO_INTEGER(precision); 1540 var p = TO_INTEGER(precision);
1543 1541
1544 if (NUMBER_IS_NAN(x)) return "NaN"; 1542 if (NUMBER_IS_NAN(x)) return "NaN";
1545 if (x == INFINITY) return "Infinity"; 1543 if (x == INFINITY) return "Infinity";
1546 if (x == -INFINITY) return "-Infinity"; 1544 if (x == -INFINITY) return "-Infinity";
1547 1545
1548 if (p < 1 || p > 21) { 1546 if (p < 1 || p > 21) {
1549 throw MakeRangeError(kToPrecisionFormatRange); 1547 throw MakeRangeError(kToPrecisionFormatRange);
1550 } 1548 }
1551 return %NumberToPrecision(x, p); 1549 return %NumberToPrecision(x, p);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 // To be consistent with our normal functions we leave this as it is. 1749 // To be consistent with our normal functions we leave this as it is.
1752 // TODO(lrn): Do set these to be thrower. 1750 // TODO(lrn): Do set these to be thrower.
1753 return result; 1751 return result;
1754 } 1752 }
1755 1753
1756 1754
1757 function NewFunctionString(args, function_token) { 1755 function NewFunctionString(args, function_token) {
1758 var n = args.length; 1756 var n = args.length;
1759 var p = ''; 1757 var p = '';
1760 if (n > 1) { 1758 if (n > 1) {
1761 p = ToString(args[0]); 1759 p = TO_STRING(args[0]);
1762 for (var i = 1; i < n - 1; i++) { 1760 for (var i = 1; i < n - 1; i++) {
1763 p += ',' + ToString(args[i]); 1761 p += ',' + TO_STRING(args[i]);
1764 } 1762 }
1765 // If the formal parameters string include ) - an illegal 1763 // If the formal parameters string include ) - an illegal
1766 // character - it may make the combined function expression 1764 // character - it may make the combined function expression
1767 // compile. We avoid this problem by checking for this early on. 1765 // compile. We avoid this problem by checking for this early on.
1768 if (%_CallFunction(p, ')', StringIndexOf) != -1) { 1766 if (%_CallFunction(p, ')', StringIndexOf) != -1) {
1769 throw MakeSyntaxError(kParenthesisInArgString); 1767 throw MakeSyntaxError(kParenthesisInArgString);
1770 } 1768 }
1771 // If the formal parameters include an unbalanced block comment, the 1769 // If the formal parameters include an unbalanced block comment, the
1772 // function must be rejected. Since JavaScript does not allow nested 1770 // function must be rejected. Since JavaScript does not allow nested
1773 // comments we can include a trailing block comment to catch this. 1771 // comments we can include a trailing block comment to catch this.
1774 p += '\n/' + '**/'; 1772 p += '\n/' + '**/';
1775 } 1773 }
1776 var body = (n > 0) ? ToString(args[n - 1]) : ''; 1774 var body = (n > 0) ? TO_STRING(args[n - 1]) : '';
1777 return '(' + function_token + '(' + p + ') {\n' + body + '\n})'; 1775 return '(' + function_token + '(' + p + ') {\n' + body + '\n})';
1778 } 1776 }
1779 1777
1780 1778
1781 function FunctionConstructor(arg1) { // length == 1 1779 function FunctionConstructor(arg1) { // length == 1
1782 var source = NewFunctionString(arguments, 'function'); 1780 var source = NewFunctionString(arguments, 'function');
1783 var global_proxy = %GlobalProxy(FunctionConstructor); 1781 var global_proxy = %GlobalProxy(FunctionConstructor);
1784 // Compile the string in the constructor and not a helper so that errors 1782 // Compile the string in the constructor and not a helper so that errors
1785 // appear to come from here. 1783 // appear to come from here.
1786 var f = %_CallFunction(global_proxy, %CompileString(source, true)); 1784 var f = %_CallFunction(global_proxy, %CompileString(source, true));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 %InstallToContext([ 1843 %InstallToContext([
1846 "global_eval_fun", GlobalEval, 1844 "global_eval_fun", GlobalEval,
1847 "object_value_of", ObjectValueOf, 1845 "object_value_of", ObjectValueOf,
1848 "object_to_string", ObjectToString, 1846 "object_to_string", ObjectToString,
1849 "object_define_own_property", DefineOwnPropertyFromAPI, 1847 "object_define_own_property", DefineOwnPropertyFromAPI,
1850 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, 1848 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor,
1851 "to_complete_property_descriptor", ToCompletePropertyDescriptor, 1849 "to_complete_property_descriptor", ToCompletePropertyDescriptor,
1852 ]); 1850 ]);
1853 1851
1854 }) 1852 })
OLDNEW
« no previous file with comments | « src/uri.js ('k') | test/cctest/compiler/test-run-jscalls.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698