Title: [171278] trunk
Revision
171278
Author
[email protected]
Date
2014-07-20 09:16:57 -0700 (Sun, 20 Jul 2014)

Log Message

ES6: Implement Math.sign()
https://bugs.webkit.org/show_bug.cgi?id=134980

Patch by Diego Pino Garcia <[email protected]> on 2014-07-20
Reviewed by Darin Adler.

Source/_javascript_Core:
* runtime/MathObject.cpp:
(JSC::MathObject::finishCreation):
(JSC::mathProtoFuncSign):

LayoutTests:
* js/script-tests/Object-getOwnPropertyNames.js:
* js/script-tests/math.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (171277 => 171278)


--- trunk/LayoutTests/ChangeLog	2014-07-20 15:08:06 UTC (rev 171277)
+++ trunk/LayoutTests/ChangeLog	2014-07-20 16:16:57 UTC (rev 171278)
@@ -1,3 +1,13 @@
+2014-07-20  Diego Pino Garcia  <[email protected]>
+
+        ES6: Implement Math.sign()
+        https://bugs.webkit.org/show_bug.cgi?id=134980
+
+        Reviewed by Darin Adler.
+
+        * js/script-tests/Object-getOwnPropertyNames.js:
+        * js/script-tests/math.js:
+
 2014-07-19  Carlos Alberto Lopez Perez  <[email protected]>
 
         [GTK] Unreviewed GTK gardening.

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


--- trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt	2014-07-20 15:08:06 UTC (rev 171277)
+++ trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt	2014-07-20 16:16:57 UTC (rev 171278)
@@ -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','acosh','asin','asinh','atan','atan2','atanh','cbrt','ceil','cos','cosh','exp','expm1','floor','fround','hypot','imul','log','log10','log1p','log2','max','min','pow','random','round','sin','sinh','sqrt','tan','tanh','trunc']
+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','hypot','imul','log','log10','log1p','log2','max','min','pow','random','round','sign','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 (171277 => 171278)


--- trunk/LayoutTests/js/math-expected.txt	2014-07-20 15:08:06 UTC (rev 171277)
+++ trunk/LayoutTests/js/math-expected.txt	2014-07-20 16:16:57 UTC (rev 171278)
@@ -181,6 +181,24 @@
 PASS Math.round(-1.7976931348623157e+308) is -1.7976931348623157e+308
 PASS Math.round(Infinity) is Infinity
 PASS Math.round(-Infinity) is -Infinity
+PASS Math.sign(NaN) is NaN
+PASS Math.sign('string') is NaN
+PASS Math.sign([1, 2, 3]) is NaN
+PASS Math.sign({}) is NaN
+PASS Math.sign(0) is 0
+PASS Math.sign(-0) is -0
+PASS Math.sign(-1) is -1
+PASS Math.sign(1) is 1
+PASS Math.sign(0.1) is 1
+PASS Math.sign(-0.1) is -1
+PASS Math.sign(10000) is 1
+PASS Math.sign(-10000) is -1
+PASS Math.sign(Number.MIN_VALUE) is 1
+PASS Math.sign(-Number.MIN_VALUE) is -1
+PASS Math.sign(Number.MAX_VALUE) is 1
+PASS Math.sign(-Number.MAX_VALUE) is -1
+PASS Math.sign(Infinity) is 1
+PASS Math.sign(-Infinity) is -1
 PASS Math.sin(NaN) is NaN
 PASS Math.sin(0) is 0
 PASS Math.sin(-0) is -0

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


--- trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js	2014-07-20 15:08:06 UTC (rev 171277)
+++ trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js	2014-07-20 16:16:57 UTC (rev 171278)
@@ -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','acosh','asin','asinh','atan','atan2','atanh','cbrt','ceil','cos','cosh','exp','expm1','floor','fround','hypot','imul','log','log10','log1p','log2','max','min','pow','random','round','sin','sinh','sqrt','tan','tanh','trunc']",
+    "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','hypot','imul','log','log10','log1p','log2','max','min','pow','random','round','sign','sin','sinh','sqrt','tan','tanh','trunc']",
     "JSON": "['parse', 'stringify']"
 };
 

Modified: trunk/LayoutTests/js/script-tests/math.js (171277 => 171278)


--- trunk/LayoutTests/js/script-tests/math.js	2014-07-20 15:08:06 UTC (rev 171277)
+++ trunk/LayoutTests/js/script-tests/math.js	2014-07-20 16:16:57 UTC (rev 171278)
@@ -254,6 +254,25 @@
 shouldBe("Math.round(Infinity)", "Infinity");
 shouldBe("Math.round(-Infinity)", "-Infinity");
 
+shouldBe("Math.sign(NaN)", "NaN");
+shouldBe("Math.sign('string')", "NaN");
+shouldBe("Math.sign([1, 2, 3])", "NaN");
+shouldBe("Math.sign({})", "NaN");
+shouldBe("Math.sign(0)", "0");
+shouldBe("Math.sign(-0)", "-0");
+shouldBe("Math.sign(-1)", "-1");
+shouldBe("Math.sign(1)", "1");
+shouldBe("Math.sign(0.1)", "1");
+shouldBe("Math.sign(-0.1)", "-1");
+shouldBe("Math.sign(10000)", "1");
+shouldBe("Math.sign(-10000)", "-1");
+shouldBe("Math.sign(Number.MIN_VALUE)", "1");
+shouldBe("Math.sign(-Number.MIN_VALUE)", "-1");
+shouldBe("Math.sign(Number.MAX_VALUE)", "1");
+shouldBe("Math.sign(-Number.MAX_VALUE)", "-1");
+shouldBe("Math.sign(Infinity)", "1");
+shouldBe("Math.sign(-Infinity)", "-1");
+
 shouldBe("Math.sin(NaN)", "NaN");
 shouldBe("Math.sin(0)", "0");
 shouldBe("Math.sin(-0)", "-0");

Modified: trunk/Source/_javascript_Core/ChangeLog (171277 => 171278)


--- trunk/Source/_javascript_Core/ChangeLog	2014-07-20 15:08:06 UTC (rev 171277)
+++ trunk/Source/_javascript_Core/ChangeLog	2014-07-20 16:16:57 UTC (rev 171278)
@@ -1,3 +1,14 @@
+2014-07-20  Diego Pino Garcia  <[email protected]>
+
+        ES6: Implement Math.sign()
+        https://bugs.webkit.org/show_bug.cgi?id=134980
+
+        Reviewed by Darin Adler.
+
+        * runtime/MathObject.cpp:
+        (JSC::MathObject::finishCreation):
+        (JSC::mathProtoFuncSign):
+
 2014-07-18  Filip Pizlo  <[email protected]>
 
         Exception fuzzing should work on iOS

Modified: trunk/Source/_javascript_Core/runtime/MathObject.cpp (171277 => 171278)


--- trunk/Source/_javascript_Core/runtime/MathObject.cpp	2014-07-20 15:08:06 UTC (rev 171277)
+++ trunk/Source/_javascript_Core/runtime/MathObject.cpp	2014-07-20 16:16:57 UTC (rev 171278)
@@ -61,6 +61,7 @@
 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 mathProtoFuncSign(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncSin(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncSinh(ExecState*);
 static EncodedJSValue JSC_HOST_CALL mathProtoFuncSqrt(ExecState*);
@@ -120,6 +121,7 @@
     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, "sign"), 1, mathProtoFuncSign, NoIntrinsic, 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);
@@ -303,6 +305,16 @@
     return JSValue::encode(jsNumber(integer - (integer - arg > 0.5)));
 }
 
+EncodedJSValue JSC_HOST_CALL mathProtoFuncSign(ExecState* exec)
+{
+    double arg = exec->argument(0).toNumber(exec);
+    if (std::isnan(arg))
+        return JSValue::encode(jsNaN());
+    if (!arg)
+        return JSValue::encode(std::signbit(arg) ? jsNumber(-0.0) : jsNumber(0));
+    return JSValue::encode(jsNumber(std::signbit(arg) ? -1 : 1));
+}
+
 EncodedJSValue JSC_HOST_CALL mathProtoFuncSin(ExecState* exec)
 {
     return JSValue::encode(jsDoubleNumber(sin(exec->argument(0).toNumber(exec))));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to