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

Side by Side Diff: src/js/v8natives.js

Issue 2424403002: [builtins] Migrate Number.parseInt to TurboFan builtin. (Closed)
Patch Set: Created 4 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/builtins/builtins-number.cc ('k') | src/runtime/runtime-numbers.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 GlobalNumber = global.Number; 12 var GlobalNumber = global.Number;
13 var GlobalObject = global.Object; 13 var GlobalObject = global.Object;
14 var iteratorSymbol = utils.ImportNow("iterator_symbol"); 14 var iteratorSymbol = utils.ImportNow("iterator_symbol");
15 var NaN = %GetRootNaN(); 15 var NaN = %GetRootNaN();
16 var ObjectToString = utils.ImportNow("object_to_string"); 16 var ObjectToString = utils.ImportNow("object_to_string");
17 17
18 // ---------------------------------------------------------------------------- 18 // ----------------------------------------------------------------------------
19 19
20 20
21 // ES6 18.2.5 parseInt(string, radix)
22 function GlobalParseInt(string, radix) {
23 if (IS_UNDEFINED(radix) || radix === 10 || radix === 0) {
24 // Some people use parseInt instead of Math.floor. This
25 // optimization makes parseInt on a Smi 12 times faster (60ns
26 // vs 800ns). The following optimization makes parseInt on a
27 // non-Smi number 9 times faster (230ns vs 2070ns). Together
28 // they make parseInt on a string 1.4% slower (274ns vs 270ns).
29 if (%_IsSmi(string)) return string;
30 if (IS_NUMBER(string) &&
31 ((0.01 < string && string < 1e9) ||
32 (-1e9 < string && string < -0.01))) {
33 // Truncate number.
34 return string | 0;
35 }
36 string = TO_STRING(string);
37 radix = radix | 0;
38 } else {
39 // The spec says ToString should be evaluated before ToInt32.
40 string = TO_STRING(string);
41 radix = TO_INT32(radix);
42 if (!(radix == 0 || (2 <= radix && radix <= 36))) {
43 return NaN;
44 }
45 }
46
47 if (%_HasCachedArrayIndex(string) &&
48 (radix == 0 || radix == 10)) {
49 return %_GetCachedArrayIndex(string);
50 }
51 return %StringParseInt(string, radix);
52 }
53
54
55 // ----------------------------------------------------------------------------
56
57 // Set up global object. 21 // Set up global object.
58 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; 22 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY;
59 23
60 utils.InstallConstants(global, [ 24 utils.InstallConstants(global, [
61 // ES6 18.1.1 25 // ES6 18.1.1
62 "Infinity", INFINITY, 26 "Infinity", INFINITY,
63 // ES6 18.1.2 27 // ES6 18.1.2
64 "NaN", NaN, 28 "NaN", NaN,
65 // ES6 18.1.3 29 // ES6 18.1.3
66 "undefined", UNDEFINED, 30 "undefined", UNDEFINED,
67 ]); 31 ]);
68 32
69 // Set up non-enumerable function on the global object.
70 utils.InstallFunctions(global, DONT_ENUM, [
71 "parseInt", GlobalParseInt,
72 ]);
73
74 33
75 // ---------------------------------------------------------------------------- 34 // ----------------------------------------------------------------------------
76 // Object 35 // Object
77 36
78 // ES6 19.1.3.5 Object.prototype.toLocaleString([reserved1 [,reserved2]]) 37 // ES6 19.1.3.5 Object.prototype.toLocaleString([reserved1 [,reserved2]])
79 function ObjectToLocaleString() { 38 function ObjectToLocaleString() {
80 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString"); 39 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString");
81 return this.toString(); 40 return this.toString();
82 } 41 }
83 42
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // ECMA-262 section 15.7.3.5. 111 // ECMA-262 section 15.7.3.5.
153 "POSITIVE_INFINITY", INFINITY, 112 "POSITIVE_INFINITY", INFINITY,
154 113
155 // --- Harmony constants (no spec refs until settled.) 114 // --- Harmony constants (no spec refs until settled.)
156 115
157 "MAX_SAFE_INTEGER", 9007199254740991, 116 "MAX_SAFE_INTEGER", 9007199254740991,
158 "MIN_SAFE_INTEGER", -9007199254740991, 117 "MIN_SAFE_INTEGER", -9007199254740991,
159 "EPSILON", 2.220446049250313e-16, 118 "EPSILON", 2.220446049250313e-16,
160 ]); 119 ]);
161 120
162 // Harmony Number constructor additions
163 utils.InstallFunctions(GlobalNumber, DONT_ENUM, [
164 "parseInt", GlobalParseInt,
165 ]);
166
167
168 121
169 // ---------------------------------------------------------------------------- 122 // ----------------------------------------------------------------------------
170 // Iterator related spec functions. 123 // Iterator related spec functions.
171 124
172 // ES6 7.4.1 GetIterator(obj, method) 125 // ES6 7.4.1 GetIterator(obj, method)
173 function GetIterator(obj, method) { 126 function GetIterator(obj, method) {
174 if (IS_UNDEFINED(method)) { 127 if (IS_UNDEFINED(method)) {
175 method = obj[iteratorSymbol]; 128 method = obj[iteratorSymbol];
176 } 129 }
177 if (!IS_CALLABLE(method)) { 130 if (!IS_CALLABLE(method)) {
(...skipping 13 matching lines...) Expand all
191 to.GetIterator = GetIterator; 144 to.GetIterator = GetIterator;
192 to.GetMethod = GetMethod; 145 to.GetMethod = GetMethod;
193 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; 146 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty;
194 }); 147 });
195 148
196 %InstallToContext([ 149 %InstallToContext([
197 "object_value_of", ObjectValueOf, 150 "object_value_of", ObjectValueOf,
198 ]); 151 ]);
199 152
200 }) 153 })
OLDNEW
« no previous file with comments | « src/builtins/builtins-number.cc ('k') | src/runtime/runtime-numbers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698