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

Unified Diff: src/math.js

Issue 990883002: Hide Math function implementations in a closure. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove printf and unnecessary test case change. Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/macros.py ('k') | src/third_party/fdlibm/fdlibm.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/math.js
diff --git a/src/math.js b/src/math.js
index cc478d344895361648b0bdba55a7bc5a96822e8d..2da38779e7cc31a1f7fcd29c9c83e83f1cbdb7cd 100644
--- a/src/math.js
+++ b/src/math.js
@@ -8,19 +8,23 @@
// in runtime.js:
// var $Object = global.Object;
-// Keep reference to original values of some global properties. This
-// has the added benefit that the code in this file is isolated from
-// changes to these properties.
-var $floor = MathFloor;
-var $abs = MathAbs;
-
// Instance class name can only be set on functions. That is the only
// purpose for MathConstructor.
function MathConstructor() {}
var $Math = new MathConstructor();
+var rngstate; // Initialized to a Uint32Array during genesis.
+
+var $abs;
+var $exp;
+var $floor;
+var $max;
+var $min;
+
// -------------------------------------------------------------------
+(function() {
+
// ECMA 262 - 15.8.2.1
function MathAbs(x) {
if (%_IsSmi(x)) return x >= 0 ? x : -x;
@@ -142,7 +146,6 @@ function MathPow(x, y) {
}
// ECMA 262 - 15.8.2.14
-var rngstate; // Initialized to a Uint32Array during genesis.
function MathRandom() {
var r0 = (MathImul(18030, rngstate[0] & 0xFFFF) + (rngstate[0] >>> 16)) | 0;
rngstate[0] = r0;
@@ -303,75 +306,71 @@ function CubeRoot(x) {
// -------------------------------------------------------------------
-function SetUpMath() {
- %CheckIsBootstrapping();
-
- %InternalSetPrototype($Math, $Object.prototype);
- %AddNamedProperty(global, "Math", $Math, DONT_ENUM);
- %FunctionSetInstanceClassName(MathConstructor, 'Math');
-
- %AddNamedProperty($Math, symbolToStringTag, "Math", READ_ONLY | DONT_ENUM);
-
- // Set up math constants.
- InstallConstants($Math, $Array(
- // ECMA-262, section 15.8.1.1.
- "E", 2.7182818284590452354,
- // ECMA-262, section 15.8.1.2.
- "LN10", 2.302585092994046,
- // ECMA-262, section 15.8.1.3.
- "LN2", 0.6931471805599453,
- // ECMA-262, section 15.8.1.4.
- "LOG2E", 1.4426950408889634,
- "LOG10E", 0.4342944819032518,
- "PI", 3.1415926535897932,
- "SQRT1_2", 0.7071067811865476,
- "SQRT2", 1.4142135623730951
- ));
-
- // Set up non-enumerable functions of the Math object and
- // set their names.
- InstallFunctions($Math, DONT_ENUM, $Array(
- "random", MathRandom,
- "abs", MathAbs,
- "acos", MathAcosJS,
- "asin", MathAsinJS,
- "atan", MathAtanJS,
- "ceil", MathCeil,
- "cos", MathCos, // implemented by third_party/fdlibm
- "exp", MathExp,
- "floor", MathFloor,
- "log", MathLog,
- "round", MathRound,
- "sin", MathSin, // implemented by third_party/fdlibm
- "sqrt", MathSqrt,
- "tan", MathTan, // implemented by third_party/fdlibm
- "atan2", MathAtan2JS,
- "pow", MathPow,
- "max", MathMax,
- "min", MathMin,
- "imul", MathImul,
- "sign", MathSign,
- "trunc", MathTrunc,
- "sinh", MathSinh, // implemented by third_party/fdlibm
- "cosh", MathCosh, // implemented by third_party/fdlibm
- "tanh", MathTanh,
- "asinh", MathAsinh,
- "acosh", MathAcosh,
- "atanh", MathAtanh,
- "log10", MathLog10, // implemented by third_party/fdlibm
- "log2", MathLog2, // implemented by third_party/fdlibm
- "hypot", MathHypot,
- "fround", MathFroundJS,
- "clz32", MathClz32,
- "cbrt", MathCbrt,
- "log1p", MathLog1p, // implemented by third_party/fdlibm
- "expm1", MathExpm1 // implemented by third_party/fdlibm
- ));
-
- %SetInlineBuiltinFlag(MathCeil);
- %SetInlineBuiltinFlag(MathRandom);
- %SetInlineBuiltinFlag(MathSin);
- %SetInlineBuiltinFlag(MathCos);
-}
+%CheckIsBootstrapping();
+
+%InternalSetPrototype($Math, $Object.prototype);
+%AddNamedProperty(global, "Math", $Math, DONT_ENUM);
+%FunctionSetInstanceClassName(MathConstructor, 'Math');
+
+%AddNamedProperty($Math, symbolToStringTag, "Math", READ_ONLY | DONT_ENUM);
+
+// Set up math constants.
+InstallConstants($Math, $Array(
+ // ECMA-262, section 15.8.1.1.
+ "E", 2.7182818284590452354,
+ // ECMA-262, section 15.8.1.2.
+ "LN10", 2.302585092994046,
+ // ECMA-262, section 15.8.1.3.
+ "LN2", 0.6931471805599453,
+ // ECMA-262, section 15.8.1.4.
+ "LOG2E", 1.4426950408889634,
+ "LOG10E", 0.4342944819032518,
+ "PI", 3.1415926535897932,
+ "SQRT1_2", 0.7071067811865476,
+ "SQRT2", 1.4142135623730951
+));
+
+// Set up non-enumerable functions of the Math object and
+// set their names.
+InstallFunctions($Math, DONT_ENUM, $Array(
+ "random", MathRandom,
+ "abs", MathAbs,
+ "acos", MathAcosJS,
+ "asin", MathAsinJS,
+ "atan", MathAtanJS,
+ "ceil", MathCeil,
+ "exp", MathExp,
+ "floor", MathFloor,
+ "log", MathLog,
+ "round", MathRound,
+ "sqrt", MathSqrt,
+ "atan2", MathAtan2JS,
+ "pow", MathPow,
+ "max", MathMax,
+ "min", MathMin,
+ "imul", MathImul,
+ "sign", MathSign,
+ "trunc", MathTrunc,
+ "tanh", MathTanh,
+ "asinh", MathAsinh,
+ "acosh", MathAcosh,
+ "atanh", MathAtanh,
+ "hypot", MathHypot,
+ "fround", MathFroundJS,
+ "clz32", MathClz32,
+ "cbrt", MathCbrt
+));
+
+%SetInlineBuiltinFlag(MathCeil);
+%SetInlineBuiltinFlag(MathRandom);
+
+// Keep reference to original values of some global properties. This
+// has the added benefit that the code in this file is isolated from
+// changes to these properties.
+$abs = MathAbs;
+$exp = MathExp;
+$floor = MathFloor;
+$max = MathMax;
+$min = MathMin;
-SetUpMath();
+})();
« no previous file with comments | « src/macros.py ('k') | src/third_party/fdlibm/fdlibm.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698