Title: [158401] trunk
Revision
158401
Author
[email protected]
Date
2013-10-31 15:38:05 -0700 (Thu, 31 Oct 2013)

Log Message

Source/_javascript_Core: Implement basic ES6 Math functions
https://bugs.webkit.org/show_bug.cgi?id=123536

Reviewed by Michael Saboff.

Fairly trivial patch to implement the core ES6 Math functions.

This doesn't implement Math.hypot as it is not a trivial function.
I've also skipped Math.sign as I am yet to be convinced the spec
behaviour is good.  Everything else is trivial.

* runtime/MathObject.cpp:
(JSC::MathObject::finishCreation):
(JSC::mathProtoFuncACosh):
(JSC::mathProtoFuncASinh):
(JSC::mathProtoFuncATanh):
(JSC::mathProtoFuncCbrt):
(JSC::mathProtoFuncCosh):
(JSC::mathProtoFuncExpm1):
(JSC::mathProtoFuncFround):
(JSC::mathProtoFuncLog1p):
(JSC::mathProtoFuncLog10):
(JSC::mathProtoFuncLog2):
(JSC::mathProtoFuncSinh):
(JSC::mathProtoFuncTanh):
(JSC::mathProtoFuncTrunc):

Source/WTF: Implement basic ES6 Math functions
https://bugs.webkit.org/show_bug.cgi?id=123536

Reviewed by Michael Saboff.

Add basic implementations of necessary methods to MathExtras to
deal with MSVC not supplying them

* wtf/MathExtras.h:
(asinh):
(acosh):
(atanh):
(expm1):
(log1p):
(cbrt):

LayoutTests: Implement ES6 Math functions
https://bugs.webkit.org/show_bug.cgi?id=123536

Reviewed by Michael Saboff.

Add tests for new math functions

* js/Object-getOwnPropertyNames-expected.txt:
* js/math-expected.txt:
* js/script-tests/Object-getOwnPropertyNames.js:
* js/script-tests/math.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (158400 => 158401)


--- trunk/LayoutTests/ChangeLog	2013-10-31 22:29:39 UTC (rev 158400)
+++ trunk/LayoutTests/ChangeLog	2013-10-31 22:38:05 UTC (rev 158401)
@@ -1,3 +1,17 @@
+2013-10-30  Oliver Hunt  <[email protected]>
+
+        Implement ES6 Math functions
+        https://bugs.webkit.org/show_bug.cgi?id=123536
+
+        Reviewed by Michael Saboff.
+
+        Add tests for new math functions
+
+        * js/Object-getOwnPropertyNames-expected.txt:
+        * js/math-expected.txt:
+        * js/script-tests/Object-getOwnPropertyNames.js:
+        * js/script-tests/math.js:
+
 2013-10-31  Alexey Proskuryakov  <[email protected]>
 
         Enable WebCrypto on Mac

Modified: trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt (158400 => 158401)


--- trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt	2013-10-31 22:29:39 UTC (rev 158400)
+++ trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt	2013-10-31 22:38:05 UTC (rev 158401)
@@ -58,7 +58,7 @@
 PASS getSortedOwnPropertyNames(RegExp.prototype) is ['compile', 'constructor', 'exec', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']
 PASS getSortedOwnPropertyNames(Error) is ['length', 'name', 'prototype']
 PASS getSortedOwnPropertyNames(Error.prototype) is ['constructor', 'message', 'name', 'toString']
-PASS getSortedOwnPropertyNames(Math) is ['E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2', 'abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'imul', 'log', 'max', 'min', 'pow', 'random', 'round', 'sin', 'sqrt', 'tan']
+PASS getSortedOwnPropertyNames(Math) is ['E','LN10','LN2','LOG10E','LOG2E','PI','SQRT1_2','SQRT2','abs','acos','acosh','asin','asinh','atan','atan2','atanh','cbrt','ceil','cos','cosh','exp','expm1','floor','fround','imul','log','log10','log1p','log2','max','min','pow','random','round','sin','sinh','sqrt','tan','tanh','trunc']
 PASS getSortedOwnPropertyNames(JSON) is ['parse', 'stringify']
 PASS globalPropertyNames.indexOf('NaN') != -1 is true
 PASS globalPropertyNames.indexOf('Infinity') != -1 is true

Modified: trunk/LayoutTests/js/math-expected.txt (158400 => 158401)


--- trunk/LayoutTests/js/math-expected.txt	2013-10-31 22:29:39 UTC (rev 158400)
+++ trunk/LayoutTests/js/math-expected.txt	2013-10-31 22:38:05 UTC (rev 158401)
@@ -163,6 +163,91 @@
 PASS Math.tan(-0) is -0
 PASS Math.tan(Infinity) is NaN
 PASS Math.tan(-Infinity) is NaN
+PASS Math.acosh(NaN) is NaN
+PASS Math.acosh(0) is NaN
+PASS Math.acosh(0.5) is NaN
+PASS Math.acosh(-1) is NaN
+PASS Math.acosh(Infinity) is Infinity
+PASS Math.acosh(-Infinity) is NaN
+PASS Math.asinh(NaN) is NaN
+PASS Math.asinh(0) is 0
+PASS Math.asinh(-0) is -0
+PASS Math.asinh(Infinity) is Infinity
+PASS Math.asinh(-Infinity) is -Infinity
+PASS Math.atanh(NaN) is NaN
+PASS Math.atanh(0) is 0
+PASS Math.atanh(-0) is -0
+PASS Math.atanh(-1) is -Infinity
+PASS Math.atanh(1) is Infinity
+PASS Math.atanh(Infinity) is NaN
+PASS Math.atanh(-Infinity) is NaN
+PASS Math.cbrt(NaN) is NaN
+PASS Math.cbrt(0) is 0
+PASS Math.cbrt(-0) is -0
+PASS Math.cbrt(27) is 3
+PASS Math.cbrt(-27) is -3
+PASS Math.cbrt(Infinity) is Infinity
+PASS Math.cbrt(-Infinity) is -Infinity
+PASS Math.cosh(NaN) is NaN
+PASS Math.cosh(0) is 1
+PASS Math.cosh(-0) is 1
+PASS Math.cosh(Infinity) is Infinity
+PASS Math.cosh(-Infinity) is Infinity
+PASS Math.expm1(NaN) is NaN
+PASS Math.expm1(0) is 0
+PASS Math.expm1(-0) is -0
+PASS Math.expm1(Infinity) is Infinity
+PASS Math.expm1(-Infinity) is -1
+PASS Math.fround(NaN) is NaN
+PASS Math.fround(0) is 0
+PASS Math.fround(-0) is -0
+PASS Math.fround(Infinity) is Infinity
+PASS Math.fround(-Infinity) is -Infinity
+PASS Math.log1p(NaN) is NaN
+PASS Math.log1p(0) is 0
+PASS Math.log1p(-0) is -0
+PASS Math.log1p(Infinity) is Infinity
+PASS Math.log1p(-1) is -Infinity
+PASS Math.log1p(-Infinity) is NaN
+PASS Math.log10(NaN) is NaN
+PASS Math.log10(0) is -Infinity
+PASS Math.log10(-0) is -Infinity
+PASS Math.log10(10) is 1
+PASS Math.log10(-1) is NaN
+PASS Math.log10(-Infinity) is NaN
+PASS Math.log10(Infinity) is Infinity
+PASS Math.log10(1) is 0
+PASS Math.log2(NaN) is NaN
+PASS Math.log2(0) is -Infinity
+PASS Math.log2(-0) is -Infinity
+PASS Math.log2(2) is 1
+PASS Math.log2(-1) is NaN
+PASS Math.log2(-Infinity) is NaN
+PASS Math.log2(Infinity) is Infinity
+PASS Math.log2(1) is 0
+PASS Math.asinh(NaN) is NaN
+PASS Math.asinh(0) is 0
+PASS Math.asinh(-0) is -0
+PASS Math.asinh(Infinity) is Infinity
+PASS Math.asinh(-Infinity) is -Infinity
+PASS Math.sinh(NaN) is NaN
+PASS Math.sinh(0) is 0
+PASS Math.sinh(-0) is -0
+PASS Math.sinh(Infinity) is Infinity
+PASS Math.sinh(-Infinity) is -Infinity
+PASS Math.tanh(NaN) is NaN
+PASS Math.tanh(0) is 0
+PASS Math.tanh(-0) is -0
+PASS Math.tanh(Infinity) is 1
+PASS Math.tanh(-Infinity) is -1
+PASS Math.trunc(NaN) is NaN
+PASS Math.trunc(0) is 0
+PASS Math.trunc(-0) is -0
+PASS Math.trunc(Infinity) is Infinity
+PASS Math.trunc(-Infinity) is -Infinity
+PASS Math.trunc(-0.5) is -0
+PASS Math.trunc(0.5) is 0
+PASS Math.trunc(0xFFFFFFFF * 2 + 0.5) is 0xFFFFFFFF * 2
 PASS delete Math; is true
 PASS 'Math' in global() is false
 PASS successfullyParsed is true

Modified: trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js (158400 => 158401)


--- trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js	2013-10-31 22:29:39 UTC (rev 158400)
+++ trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js	2013-10-31 22:38:05 UTC (rev 158401)
@@ -66,7 +66,7 @@
     "RegExp.prototype": "['compile', 'constructor', 'exec', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']",
     "Error": "['length', 'name', 'prototype']",
     "Error.prototype": "['constructor', 'message', 'name', 'toString']",
-    "Math": "['E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2', 'abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'imul', 'log', 'max', 'min', 'pow', 'random', 'round', 'sin', 'sqrt', 'tan']",
+    "Math": "['E','LN10','LN2','LOG10E','LOG2E','PI','SQRT1_2','SQRT2','abs','acos','acosh','asin','asinh','atan','atan2','atanh','cbrt','ceil','cos','cosh','exp','expm1','floor','fround','imul','log','log10','log1p','log2','max','min','pow','random','round','sin','sinh','sqrt','tan','tanh','trunc']",
     "JSON": "['parse', 'stringify']"
 };
 

Modified: trunk/LayoutTests/js/script-tests/math.js (158400 => 158401)


--- trunk/LayoutTests/js/script-tests/math.js	2013-10-31 22:29:39 UTC (rev 158400)
+++ trunk/LayoutTests/js/script-tests/math.js	2013-10-31 22:38:05 UTC (rev 158401)
@@ -235,6 +235,108 @@
 shouldBe("Math.tan(Infinity)", "NaN");
 shouldBe("Math.tan(-Infinity)", "NaN");
 
+
+shouldBe("Math.acosh(NaN)", "NaN");
+shouldBe("Math.acosh(0)", "NaN");
+shouldBe("Math.acosh(0.5)", "NaN");
+shouldBe("Math.acosh(-1)", "NaN");
+shouldBe("Math.acosh(Infinity)", "Infinity");
+shouldBe("Math.acosh(-Infinity)", "NaN");
+
+
+shouldBe("Math.asinh(NaN)", "NaN");
+shouldBe("Math.asinh(0)", "0");
+shouldBe("Math.asinh(-0)", "-0");
+shouldBe("Math.asinh(Infinity)", "Infinity");
+shouldBe("Math.asinh(-Infinity)", "-Infinity");
+
+shouldBe("Math.atanh(NaN)", "NaN");
+shouldBe("Math.atanh(0)", "0");
+shouldBe("Math.atanh(-0)", "-0");
+shouldBe("Math.atanh(-1)", "-Infinity");
+shouldBe("Math.atanh(1)", "Infinity");
+shouldBe("Math.atanh(Infinity)", "NaN");
+shouldBe("Math.atanh(-Infinity)", "NaN");
+
+shouldBe("Math.cbrt(NaN)", "NaN");
+shouldBe("Math.cbrt(0)", "0");
+shouldBe("Math.cbrt(-0)", "-0");
+shouldBe("Math.cbrt(27)", "3");
+shouldBe("Math.cbrt(-27)", "-3");
+shouldBe("Math.cbrt(Infinity)", "Infinity");
+shouldBe("Math.cbrt(-Infinity)", "-Infinity");
+
+shouldBe("Math.cosh(NaN)", "NaN");
+shouldBe("Math.cosh(0)", "1");
+shouldBe("Math.cosh(-0)", "1");
+shouldBe("Math.cosh(Infinity)", "Infinity");
+shouldBe("Math.cosh(-Infinity)", "Infinity");
+
+shouldBe("Math.expm1(NaN)", "NaN");
+shouldBe("Math.expm1(0)", "0");
+shouldBe("Math.expm1(-0)", "-0");
+shouldBe("Math.expm1(Infinity)", "Infinity");
+shouldBe("Math.expm1(-Infinity)", "-1");
+
+shouldBe("Math.fround(NaN)", "NaN");
+shouldBe("Math.fround(0)", "0");
+shouldBe("Math.fround(-0)", "-0");
+shouldBe("Math.fround(Infinity)", "Infinity");
+shouldBe("Math.fround(-Infinity)", "-Infinity");
+
+shouldBe("Math.log1p(NaN)", "NaN");
+shouldBe("Math.log1p(0)", "0");
+shouldBe("Math.log1p(-0)", "-0");
+shouldBe("Math.log1p(Infinity)", "Infinity");
+shouldBe("Math.log1p(-1)", "-Infinity");
+shouldBe("Math.log1p(-Infinity)", "NaN");
+
+shouldBe("Math.log10(NaN)", "NaN");
+shouldBe("Math.log10(0)", "-Infinity");
+shouldBe("Math.log10(-0)", "-Infinity");
+shouldBe("Math.log10(10)", "1");
+shouldBe("Math.log10(-1)", "NaN");
+shouldBe("Math.log10(-Infinity)", "NaN");
+shouldBe("Math.log10(Infinity)", "Infinity");
+shouldBe("Math.log10(1)", "0");
+
+shouldBe("Math.log2(NaN)", "NaN");
+shouldBe("Math.log2(0)", "-Infinity");
+shouldBe("Math.log2(-0)", "-Infinity");
+shouldBe("Math.log2(2)", "1");
+shouldBe("Math.log2(-1)", "NaN");
+shouldBe("Math.log2(-Infinity)", "NaN");
+shouldBe("Math.log2(Infinity)", "Infinity");
+shouldBe("Math.log2(1)", "0");
+
+shouldBe("Math.asinh(NaN)", "NaN");
+shouldBe("Math.asinh(0)", "0");
+shouldBe("Math.asinh(-0)", "-0");
+shouldBe("Math.asinh(Infinity)", "Infinity");
+shouldBe("Math.asinh(-Infinity)", "-Infinity");
+
+shouldBe("Math.sinh(NaN)", "NaN");
+shouldBe("Math.sinh(0)", "0");
+shouldBe("Math.sinh(-0)", "-0");
+shouldBe("Math.sinh(Infinity)", "Infinity");
+shouldBe("Math.sinh(-Infinity)", "-Infinity");
+
+shouldBe("Math.tanh(NaN)", "NaN");
+shouldBe("Math.tanh(0)", "0");
+shouldBe("Math.tanh(-0)", "-0");
+shouldBe("Math.tanh(Infinity)", "1");
+shouldBe("Math.tanh(-Infinity)", "-1");
+
+shouldBe("Math.trunc(NaN)", "NaN");
+shouldBe("Math.trunc(0)", "0");
+shouldBe("Math.trunc(-0)", "-0");
+shouldBe("Math.trunc(Infinity)", "Infinity");
+shouldBe("Math.trunc(-Infinity)", "-Infinity");
+shouldBe("Math.trunc(-0.5)", "-0");
+shouldBe("Math.trunc(0.5)", "0");
+shouldBe("Math.trunc(0xFFFFFFFF * 2 + 0.5)", "0xFFFFFFFF * 2");
+
+
 var __Math = Math;
 shouldBeTrue("delete Math;");
 

Modified: trunk/Source/_javascript_Core/ChangeLog (158400 => 158401)


--- trunk/Source/_javascript_Core/ChangeLog	2013-10-31 22:29:39 UTC (rev 158400)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-10-31 22:38:05 UTC (rev 158401)
@@ -1,3 +1,32 @@
+2013-10-30  Oliver Hunt  <[email protected]>
+
+        Implement basic ES6 Math functions
+        https://bugs.webkit.org/show_bug.cgi?id=123536
+
+        Reviewed by Michael Saboff.
+
+        Fairly trivial patch to implement the core ES6 Math functions.
+
+        This doesn't implement Math.hypot as it is not a trivial function.
+        I've also skipped Math.sign as I am yet to be convinced the spec
+        behaviour is good.  Everything else is trivial.
+
+        * runtime/MathObject.cpp:
+        (JSC::MathObject::finishCreation):
+        (JSC::mathProtoFuncACosh):
+        (JSC::mathProtoFuncASinh):
+        (JSC::mathProtoFuncATanh):
+        (JSC::mathProtoFuncCbrt):
+        (JSC::mathProtoFuncCosh):
+        (JSC::mathProtoFuncExpm1):
+        (JSC::mathProtoFuncFround):
+        (JSC::mathProtoFuncLog1p):
+        (JSC::mathProtoFuncLog10):
+        (JSC::mathProtoFuncLog2):
+        (JSC::mathProtoFuncSinh):
+        (JSC::mathProtoFuncTanh):
+        (JSC::mathProtoFuncTrunc):
+
 2013-10-31  Filip Pizlo  <[email protected]>
 
         FTL::Location::restoreInto() doesn't handle stack-related registers correctly if you're using it after pushing a new stack frame

Modified: trunk/Source/_javascript_Core/runtime/MathObject.cpp (158400 => 158401)


--- trunk/Source/_javascript_Core/runtime/MathObject.cpp	2013-10-31 22:29:39 UTC (rev 158400)
+++ trunk/Source/_javascript_Core/runtime/MathObject.cpp	2013-10-31 22:38:05 UTC (rev 158401)
@@ -36,22 +36,35 @@
 
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncAbs(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncACos(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncACosh(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncASin(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncASinh(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncATan(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncATanh(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncATan2(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncCbrt(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncCeil(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncCos(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncCosh(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncExp(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncExpm1(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncFloor(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncFround(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncLog(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncLog1p(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncLog10(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncLog2(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncMax(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncMin(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncPow(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncRandom(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncRound(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncSin(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncSinh(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncSqrt(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncTan(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncTanh(ExecState*);
+static EncodedJSValue JSC_HOST_CALL mathProtoFuncTrunc(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncIMul(ExecState*);
 
 }
@@ -83,20 +96,33 @@
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "acos"), 1, mathProtoFuncACos, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "asin"), 1, mathProtoFuncASin, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "atan"), 1, mathProtoFuncATan, NoIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "acosh"), 1, mathProtoFuncACosh, NoIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "asinh"), 1, mathProtoFuncASinh, NoIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "atanh"), 1, mathProtoFuncATanh, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "atan2"), 2, mathProtoFuncATan2, NoIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "cbrt"), 1, mathProtoFuncCbrt, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "ceil"), 1, mathProtoFuncCeil, CeilIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "cos"), 1, mathProtoFuncCos, CosIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "cosh"), 1, mathProtoFuncCosh, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "exp"), 1, mathProtoFuncExp, ExpIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "expm1"), 1, mathProtoFuncExpm1, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "floor"), 1, mathProtoFuncFloor, FloorIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "fround"), 1, mathProtoFuncFround, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "log"), 1, mathProtoFuncLog, LogIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "log10"), 1, mathProtoFuncLog10, NoIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "log1p"), 1, mathProtoFuncLog1p, NoIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "log2"), 1, mathProtoFuncLog2, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "max"), 2, mathProtoFuncMax, MaxIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "min"), 2, mathProtoFuncMin, MinIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "pow"), 2, mathProtoFuncPow, PowIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "random"), 0, mathProtoFuncRandom, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "round"), 1, mathProtoFuncRound, RoundIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "sin"), 1, mathProtoFuncSin, SinIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "sinh"), 1, mathProtoFuncSinh, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "sqrt"), 1, mathProtoFuncSqrt, SqrtIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "tan"), 1, mathProtoFuncTan, NoIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "tanh"), 1, mathProtoFuncTanh, NoIntrinsic, DontEnum | Function);
+    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "trunc"), 1, mathProtoFuncTrunc, NoIntrinsic, DontEnum | Function);
     putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "imul"), 1, mathProtoFuncIMul, IMulIntrinsic, DontEnum | Function);
 }
 
@@ -273,6 +299,75 @@
     return JSValue::encode(jsNumber(left * right));
 }
 
+EncodedJSValue JSC_HOST_CALL mathProtoFuncACosh(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(acosh(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncASinh(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(asinh(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncATanh(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(atanh(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncCbrt(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(cbrt(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncCosh(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(cosh(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncExpm1(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(expm1(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncFround(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(static_cast<float>(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncLog1p(ExecState* exec)
+{
+    double value = exec->argument(0).toNumber(exec);
+    if (value == 0)
+        return JSValue::encode(jsDoubleNumber(value));
+    return JSValue::encode(jsDoubleNumber(log1p(value)));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncLog10(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(log10(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncLog2(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(log2(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncSinh(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(sinh(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncTanh(ExecState* exec)
+{
+    return JSValue::encode(jsDoubleNumber(tanh(exec->argument(0).toNumber(exec))));
+}
+
+EncodedJSValue JSC_HOST_CALL mathProtoFuncTrunc(ExecState*exec)
+{
+    return JSValue::encode(jsNumber(exec->argument(0).toIntegerPreserveNaN(exec)));
+}
+
+
 #if PLATFORM(IOS) && CPU(ARM_THUMB2)
 
 // The following code is taken from netlib.org:

Modified: trunk/Source/WTF/ChangeLog (158400 => 158401)


--- trunk/Source/WTF/ChangeLog	2013-10-31 22:29:39 UTC (rev 158400)
+++ trunk/Source/WTF/ChangeLog	2013-10-31 22:38:05 UTC (rev 158401)
@@ -1,3 +1,21 @@
+2013-10-30  Oliver Hunt  <[email protected]>
+
+        Implement basic ES6 Math functions
+        https://bugs.webkit.org/show_bug.cgi?id=123536
+
+        Reviewed by Michael Saboff.
+
+        Add basic implementations of necessary methods to MathExtras to
+        deal with MSVC not supplying them
+
+        * wtf/MathExtras.h:
+        (asinh):
+        (acosh):
+        (atanh):
+        (expm1):
+        (log1p):
+        (cbrt):
+
 2013-10-30  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r158299.

Modified: trunk/Source/WTF/wtf/MathExtras.h (158400 => 158401)


--- trunk/Source/WTF/wtf/MathExtras.h	2013-10-31 22:29:39 UTC (rev 158400)
+++ trunk/Source/WTF/wtf/MathExtras.h	2013-10-31 22:38:05 UTC (rev 158401)
@@ -157,7 +157,36 @@
 
 #endif
 
+inline double asinh(double d)
+{
+    return log(d + sqrt(d * d + 1.0));
+}
 
+inline double acosh(double d)
+{
+    return log(d + sqrt(d + 1) * sqrt(d - 1));
+}
+
+inline double atanh(double d)
+{
+    return (log((1.0 + d) / (1.0 - d))) / 2.0;
+}
+
+inline double expm1(double d)
+{
+    return exp(d) - 1.0;
+}
+
+inline double log1p(double d)
+{
+    return log(1.0 + d);
+}
+
+inline double cbrt(double d)
+{
+    return pow(d, 1.0 / 3.0);
+}
+
 #endif
 
 #if COMPILER(GCC) && OS(QNX)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to