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/math.js

Issue 1065863003: Use array literals instead of array constructor in native javascript. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase and fix Created 5 years, 8 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/json.js ('k') | src/messages.js » ('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 var rngstate; // Initialized to a Uint32Array during genesis. 5 var rngstate; // Initialized to a Uint32Array during genesis.
6 6
7 var $abs; 7 var $abs;
8 var $exp; 8 var $exp;
9 var $floor; 9 var $floor;
10 var $max; 10 var $max;
11 var $min; 11 var $min;
12 12
13 (function() { 13 (function() {
14 14
15 "use strict"; 15 "use strict";
16 16
17 %CheckIsBootstrapping(); 17 %CheckIsBootstrapping();
18 18
19 var GlobalObject = global.Object; 19 var GlobalObject = global.Object;
20 var GlobalArray = global.Array;
21 20
22 //------------------------------------------------------------------- 21 //-------------------------------------------------------------------
23 22
24 // ECMA 262 - 15.8.2.1 23 // ECMA 262 - 15.8.2.1
25 function MathAbs(x) { 24 function MathAbs(x) {
26 x = +x; 25 x = +x;
27 return (x > 0) ? x : 0 - x; 26 return (x > 0) ? x : 0 - x;
28 } 27 }
29 28
30 // ECMA 262 - 15.8.2.2 29 // ECMA 262 - 15.8.2.2
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 287
289 var Math = new MathConstructor(); 288 var Math = new MathConstructor();
290 289
291 %InternalSetPrototype(Math, GlobalObject.prototype); 290 %InternalSetPrototype(Math, GlobalObject.prototype);
292 %AddNamedProperty(global, "Math", Math, DONT_ENUM); 291 %AddNamedProperty(global, "Math", Math, DONT_ENUM);
293 %FunctionSetInstanceClassName(MathConstructor, 'Math'); 292 %FunctionSetInstanceClassName(MathConstructor, 'Math');
294 293
295 %AddNamedProperty(Math, symbolToStringTag, "Math", READ_ONLY | DONT_ENUM); 294 %AddNamedProperty(Math, symbolToStringTag, "Math", READ_ONLY | DONT_ENUM);
296 295
297 // Set up math constants. 296 // Set up math constants.
298 InstallConstants(Math, GlobalArray( 297 InstallConstants(Math, [
299 // ECMA-262, section 15.8.1.1. 298 // ECMA-262, section 15.8.1.1.
300 "E", 2.7182818284590452354, 299 "E", 2.7182818284590452354,
301 // ECMA-262, section 15.8.1.2. 300 // ECMA-262, section 15.8.1.2.
302 "LN10", 2.302585092994046, 301 "LN10", 2.302585092994046,
303 // ECMA-262, section 15.8.1.3. 302 // ECMA-262, section 15.8.1.3.
304 "LN2", 0.6931471805599453, 303 "LN2", 0.6931471805599453,
305 // ECMA-262, section 15.8.1.4. 304 // ECMA-262, section 15.8.1.4.
306 "LOG2E", 1.4426950408889634, 305 "LOG2E", 1.4426950408889634,
307 "LOG10E", 0.4342944819032518, 306 "LOG10E", 0.4342944819032518,
308 "PI", 3.1415926535897932, 307 "PI", 3.1415926535897932,
309 "SQRT1_2", 0.7071067811865476, 308 "SQRT1_2", 0.7071067811865476,
310 "SQRT2", 1.4142135623730951 309 "SQRT2", 1.4142135623730951
311 )); 310 ]);
312 311
313 // Set up non-enumerable functions of the Math object and 312 // Set up non-enumerable functions of the Math object and
314 // set their names. 313 // set their names.
315 InstallFunctions(Math, DONT_ENUM, GlobalArray( 314 InstallFunctions(Math, DONT_ENUM, [
316 "random", MathRandom, 315 "random", MathRandom,
317 "abs", MathAbs, 316 "abs", MathAbs,
318 "acos", MathAcosJS, 317 "acos", MathAcosJS,
319 "asin", MathAsinJS, 318 "asin", MathAsinJS,
320 "atan", MathAtanJS, 319 "atan", MathAtanJS,
321 "ceil", MathCeil, 320 "ceil", MathCeil,
322 "exp", MathExp, 321 "exp", MathExp,
323 "floor", MathFloorJS, 322 "floor", MathFloorJS,
324 "log", MathLog, 323 "log", MathLog,
325 "round", MathRound, 324 "round", MathRound,
326 "sqrt", MathSqrtJS, 325 "sqrt", MathSqrtJS,
327 "atan2", MathAtan2JS, 326 "atan2", MathAtan2JS,
328 "pow", MathPowJS, 327 "pow", MathPowJS,
329 "max", MathMax, 328 "max", MathMax,
330 "min", MathMin, 329 "min", MathMin,
331 "imul", MathImul, 330 "imul", MathImul,
332 "sign", MathSign, 331 "sign", MathSign,
333 "trunc", MathTrunc, 332 "trunc", MathTrunc,
334 "tanh", MathTanh, 333 "tanh", MathTanh,
335 "asinh", MathAsinh, 334 "asinh", MathAsinh,
336 "acosh", MathAcosh, 335 "acosh", MathAcosh,
337 "atanh", MathAtanh, 336 "atanh", MathAtanh,
338 "hypot", MathHypot, 337 "hypot", MathHypot,
339 "fround", MathFroundJS, 338 "fround", MathFroundJS,
340 "clz32", MathClz32JS, 339 "clz32", MathClz32JS,
341 "cbrt", MathCbrt 340 "cbrt", MathCbrt
342 )); 341 ]);
343 342
344 %SetInlineBuiltinFlag(MathAbs); 343 %SetInlineBuiltinFlag(MathAbs);
345 %SetInlineBuiltinFlag(MathAcosJS); 344 %SetInlineBuiltinFlag(MathAcosJS);
346 %SetInlineBuiltinFlag(MathAsinJS); 345 %SetInlineBuiltinFlag(MathAsinJS);
347 %SetInlineBuiltinFlag(MathAtanJS); 346 %SetInlineBuiltinFlag(MathAtanJS);
348 %SetInlineBuiltinFlag(MathAtan2JS); 347 %SetInlineBuiltinFlag(MathAtan2JS);
349 %SetInlineBuiltinFlag(MathCeil); 348 %SetInlineBuiltinFlag(MathCeil);
350 %SetInlineBuiltinFlag(MathClz32JS); 349 %SetInlineBuiltinFlag(MathClz32JS);
351 %SetInlineBuiltinFlag(MathFloorJS); 350 %SetInlineBuiltinFlag(MathFloorJS);
352 %SetInlineBuiltinFlag(MathRandom); 351 %SetInlineBuiltinFlag(MathRandom);
353 %SetInlineBuiltinFlag(MathSign); 352 %SetInlineBuiltinFlag(MathSign);
354 %SetInlineBuiltinFlag(MathSqrtJS); 353 %SetInlineBuiltinFlag(MathSqrtJS);
355 %SetInlineBuiltinFlag(MathTrunc); 354 %SetInlineBuiltinFlag(MathTrunc);
356 355
357 // Expose to the global scope. 356 // Expose to the global scope.
358 $abs = MathAbs; 357 $abs = MathAbs;
359 $exp = MathExp; 358 $exp = MathExp;
360 $floor = MathFloorJS; 359 $floor = MathFloorJS;
361 $max = MathMax; 360 $max = MathMax;
362 $min = MathMin; 361 $min = MathMin;
363 362
364 })(); 363 })();
OLDNEW
« no previous file with comments | « src/json.js ('k') | src/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698