Unreviewed, rolling out r226937.
authorryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jan 2018 22:35:39 +0000 (22:35 +0000)
committerryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jan 2018 22:35:39 +0000 (22:35 +0000)
Tests added with this change are failing due to a missing
exception check.

Reverted changeset:

"[JSC] NumberPrototype::extractRadixFromArgs incorrectly cast
double to int32_t"
https://bugs.webkit.org/show_bug.cgi?id=181182
https://trac.webkit.org/changeset/226937

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227004 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
JSTests/ChangeLog
JSTests/bigIntTests.yaml
JSTests/stress/big-int-constructor.js
JSTests/stress/big-int-prototype-to-string-cast-overflow.js [deleted file]
JSTests/stress/big-int-prototype-to-string-exception.js [deleted file]
JSTests/stress/big-int-prototype-to-string-wrong-values.js [deleted file]
JSTests/stress/number-prototype-to-string-cast-overflow.js [deleted file]
JSTests/stress/number-prototype-to-string-exception.js [deleted file]
JSTests/stress/number-prototype-to-string-wrong-values.js [deleted file]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/BigIntPrototype.cpp
Source/JavaScriptCore/runtime/NumberPrototype.cpp
Source/JavaScriptCore/runtime/NumberPrototype.h

index 305ac086befcb368338311cdf2d29d81906c2976..9c7631ad4d8bc0cc097acade8ec47f714c8cab0d 100644 (file)
@@ -1,3 +1,17 @@
+2018-01-16  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r226937.
+
+        Tests added with this change are failing due to a missing
+        exception check.
+
+        Reverted changeset:
+
+        "[JSC] NumberPrototype::extractRadixFromArgs incorrectly cast
+        double to int32_t"
+        https://bugs.webkit.org/show_bug.cgi?id=181182
+        https://trac.webkit.org/changeset/226937
+
 2018-01-13  Caio Lima  <ticaiolima@gmail.com>
 
         [JSC] NumberPrototype::extractRadixFromArgs incorrectly cast double to int32_t
index cd8636efd1ea6b72ccab3e1fd60a3af9027ee156..7ae22cb1bb2aff62cc4ddf496299f96a0744f7ae 100644 (file)
 - path: stress/big-int-to-string.js
   cmd: runBigIntEnabled
 
-- path: stress/big-int-prototype-to-string-cast-overflow.js
-  cmd: runBigIntEnabled
-
-- path: stress/big-int-prototype-to-string-exception.js
-  cmd: runBigIntEnabled
-
-- path: stress/big-int-prototype-to-string-wrong-values.js
-  cmd: runBigIntEnabled
-
index 4faefbcb3d1791134aa5a9afac18674a29694d9c..c76843bf82f45eb93ae6711eeb6ea9f1323a119e 100644 (file)
@@ -75,7 +75,7 @@ assert(n.toString() === "15");
 n = BigInt("0b10");
 assert(n.toString() === "2");
 
-n = BigInt("0b010");
+n = BigInt("0b10");
 assert(n.toString() === "2");
 
 let binaryString = "0b1";
@@ -91,7 +91,7 @@ assert(n.toString() === "15");
 n = BigInt("0B10");
 assert(n.toString() === "2");
 
-n = BigInt("0B010");
+n = BigInt("0B10");
 assert(n.toString() === "2");
 
 binaryString = "0B1";
diff --git a/JSTests/stress/big-int-prototype-to-string-cast-overflow.js b/JSTests/stress/big-int-prototype-to-string-cast-overflow.js
deleted file mode 100644 (file)
index a9fa302..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-//@ runBigIntEnabled
-
-function assert(a) {
-    if (!a)
-        throw new Error("Bad assertion");
-}
-
-function assertThrowRangeError(input) {
-    try {
-        let number = 3n;
-        number.toString(input);
-        assert(false);
-    } catch (e) {
-        assert(e instanceof RangeError);
-    }
-}
-
-assertThrowRangeError(1e100);
-assertThrowRangeError(-1e101);
-
diff --git a/JSTests/stress/big-int-prototype-to-string-exception.js b/JSTests/stress/big-int-prototype-to-string-exception.js
deleted file mode 100644 (file)
index 6c1d3c0..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-//@ runBigIntEnabled
-
-function assert(a) {
-    if (!a)
-        throw new Error("Bad assertion");
-}
-
-let o = {
-    valueOf: () => {
-        throw new Error("Bad");
-        return 2;
-    }
-}
-
-let a = 20n;
-try {
-    a.toString(o);
-    assert(false);
-} catch (e) {
-    assert(e.message == "Bad");
-}
-
diff --git a/JSTests/stress/big-int-prototype-to-string-wrong-values.js b/JSTests/stress/big-int-prototype-to-string-wrong-values.js
deleted file mode 100644 (file)
index 79e51d5..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-//@ runBigIntEnabled
-
-function assert(a) {
-    if (!a)
-        throw new Error("Bad assertion");
-}
-
-function assertRangeError(v) {
-    let a = 456n;
-    try {
-        a.toString(v);
-        assert(false);
-    } catch (e) {
-        assert(e instanceof RangeError);
-    }
-}
-
-assertRangeError(1);
-assertRangeError(37);
-assertRangeError(37.1);
-assertRangeError(37.2);
-assertRangeError(0);
-assertRangeError(-1);
-assertRangeError(1.999999);
-assertRangeError(37.00000000000000001);
-assertRangeError(NaN);
-assertRangeError(null);
-assertRangeError(+Infinity);
-assertRangeError(-Infinity);
-assertRangeError(-0);
-
diff --git a/JSTests/stress/number-prototype-to-string-cast-overflow.js b/JSTests/stress/number-prototype-to-string-cast-overflow.js
deleted file mode 100644 (file)
index f12ab05..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-function assert(a) {
-    if (!a)
-        throw new Error("Bad assertion");
-}
-
-function assertThrowRangeError(input) {
-    try {
-        let number = 3;
-        number.toString(input);
-        assert(false);
-    } catch (e) {
-        assert(e instanceof RangeError);
-    }
-}
-
-assertThrowRangeError(1e100);
-assertThrowRangeError(-1e101);
-
diff --git a/JSTests/stress/number-prototype-to-string-exception.js b/JSTests/stress/number-prototype-to-string-exception.js
deleted file mode 100644 (file)
index 7445907..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-function assert(a) {
-    if (!a)
-        throw new Error("Bad assertion");
-}
-
-let o = {
-    valueOf: () => {
-        throw new Error("Bad");
-        return 2;
-    }
-}
-
-let a = 2;
-try {
-    a.toString(o);
-    assert(false);
-} catch (e) {
-    assert(e.message == "Bad");
-}
-
diff --git a/JSTests/stress/number-prototype-to-string-wrong-values.js b/JSTests/stress/number-prototype-to-string-wrong-values.js
deleted file mode 100644 (file)
index 52e6e11..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-function assert(a) {
-    if (!a)
-        throw new Error("Bad assertion");
-}
-
-function assertRangeError(v) {
-    let a = 2;
-    try {
-        a.toString(v);
-        assert(false);
-    } catch (e) {
-        assert(e instanceof RangeError);
-    }
-}
-
-assertRangeError(1);
-assertRangeError(37);
-assertRangeError(37.1);
-assertRangeError(37.2);
-assertRangeError(0);
-assertRangeError(-1);
-assertRangeError(1.999999);
-assertRangeError(37.00000000000000001);
-assertRangeError(NaN);
-assertRangeError(null);
-assertRangeError(+Infinity);
-assertRangeError(-Infinity);
-assertRangeError(-0);
-
index 517d33f70ce286909af76f8a53bae6b4ac77d6a5..026c26e16e08546ecaf4321669d45a3cee0691b1 100644 (file)
@@ -1,3 +1,17 @@
+2018-01-16  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r226937.
+
+        Tests added with this change are failing due to a missing
+        exception check.
+
+        Reverted changeset:
+
+        "[JSC] NumberPrototype::extractRadixFromArgs incorrectly cast
+        double to int32_t"
+        https://bugs.webkit.org/show_bug.cgi?id=181182
+        https://trac.webkit.org/changeset/226937
+
 2018-01-16  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Test programs should only be built in developer mode
index 19971422448fc1ece65f840339cba3678ae7c2dc..bb903e4be54344df19155527b41dba26c0b41765 100644 (file)
@@ -35,9 +35,7 @@
 #include "JSFunction.h"
 #include "JSGlobalObject.h"
 #include "JSString.h"
-#include "NumberPrototype.h"
 #include <wtf/Assertions.h>
-#include <wtf/Variant.h>
 
 namespace JSC {
 
@@ -101,11 +99,21 @@ EncodedJSValue JSC_HOST_CALL bigIntProtoFuncToString(ExecState* state)
     
     ASSERT(value);
 
-    auto radix = extractToStringRadixArgument(state, state->argument(0));
-    if (WTF::holds_alternative<EncodedJSValue>(radix))
-        return WTF::get<EncodedJSValue>(radix);
+    int64_t radix;
+    JSValue radixValue = state->argument(0);
+    if (radixValue.isInt32())
+        radix = radixValue.asInt32();
+    else if (radixValue.isUndefined())
+        radix = 10;
+    else {
+        radix = static_cast<int64_t>(radixValue.toInteger(state));
+        RETURN_IF_EXCEPTION(scope, encodedJSValue());
+    }
+
+    if (radix < 2 || radix > 36)
+        return throwVMError(state, scope, createRangeError(state, ASCIILiteral("toString() radix argument must be between 2 and 36")));
 
-    String resultString = value->toString(*state, WTF::get<int32_t>(radix));
+    String resultString = value->toString(*state, static_cast<int32_t>(radix));
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
     if (resultString.length() == 1)
         return JSValue::encode(vm.smallStrings.singleCharacterString(resultString[0]));
index 01b23421155a10bd995681d29caa35b6e086cea0..a63d01e4d8bdaf8d9c9a461207b5b42a08745055 100644 (file)
@@ -34,7 +34,6 @@
 #include <wtf/dtoa.h>
 #include <wtf/Assertions.h>
 #include <wtf/MathExtras.h>
-#include <wtf/Variant.h>
 #include <wtf/dtoa/double-conversion.h>
 
 using DoubleToStringConverter = WTF::double_conversion::DoubleToStringConverter;
@@ -505,6 +504,20 @@ EncodedJSValue JSC_HOST_CALL numberProtoFuncToPrecision(ExecState* exec)
     return JSValue::encode(jsString(exec, String(numberToFixedPrecisionString(x, significantFigures, buffer))));
 }
 
+static inline int32_t extractRadixFromArgs(ExecState* exec)
+{
+    JSValue radixValue = exec->argument(0);
+    int32_t radix;
+    if (radixValue.isInt32())
+        radix = radixValue.asInt32();
+    else if (radixValue.isUndefined())
+        radix = 10;
+    else
+        radix = static_cast<int32_t>(radixValue.toInteger(exec)); // nan -> 0
+
+    return radix;
+}
+
 static ALWAYS_INLINE JSString* int32ToStringInternal(VM& vm, int32_t value, int32_t radix)
 {
     ASSERT(!(radix < 2 || radix > 36));
@@ -573,21 +586,22 @@ JSString* numberToString(VM& vm, double doubleValue, int32_t radix)
     return numberToStringInternal(vm, doubleValue, radix);
 }
 
-EncodedJSValue JSC_HOST_CALL numberProtoFuncToString(ExecState* state)
+EncodedJSValue JSC_HOST_CALL numberProtoFuncToString(ExecState* exec)
 {
-    VM& vm = state->vm();
+    VM& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
 
     double doubleValue;
-    if (!toThisNumber(state->thisValue(), doubleValue))
-        return throwVMTypeError(state, scope);
+    if (!toThisNumber(exec->thisValue(), doubleValue))
+        return throwVMTypeError(exec, scope);
 
-    scope.release();
-    auto radix = extractToStringRadixArgument(state, state->argument(0));
-    if (WTF::holds_alternative<EncodedJSValue>(radix))
-        return WTF::get<EncodedJSValue>(radix);
+    int32_t radix = extractRadixFromArgs(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
+    if (radix < 2 || radix > 36)
+        return throwVMError(exec, scope, createRangeError(exec, ASCIILiteral("toString() radix argument must be between 2 and 36")));
 
-    return JSValue::encode(numberToStringInternal(vm, doubleValue, WTF::get<int32_t>(radix)));
+    scope.release();
+    return JSValue::encode(numberToStringInternal(vm, doubleValue, radix));
 }
 
 EncodedJSValue JSC_HOST_CALL numberProtoFuncToLocaleString(ExecState* exec)
@@ -614,24 +628,4 @@ EncodedJSValue JSC_HOST_CALL numberProtoFuncValueOf(ExecState* exec)
     return JSValue::encode(jsNumber(x));
 }
 
-Variant<int32_t, EncodedJSValue> extractToStringRadixArgument(ExecState* state, JSValue radixValue)
-{
-    if (radixValue.isUndefined())
-        return 10;
-
-    auto scope = DECLARE_THROW_SCOPE(state->vm());
-    if (radixValue.isInt32()) {
-        int32_t radix = radixValue.asInt32();
-        if (radix >= 2 && radix <= 36)
-            return radix;
-    } else {
-        double radixDouble = radixValue.toInteger(state);
-        RETURN_IF_EXCEPTION(scope, encodedJSValue());
-        if (radixDouble >= 2 && radixDouble <= 36)
-            return static_cast<int32_t>(radixDouble);   
-    }
-
-    return throwVMError(state, scope, createRangeError(state, ASCIILiteral("toString() radix argument must be between 2 and 36")));
-}
-
 } // namespace JSC
index 3796187b48d81f939459787c05222a921b7720dd..039b0d59d1ec5bd35a5ac2faf511017aaab58ade 100644 (file)
@@ -21,7 +21,6 @@
 #pragma once
 
 #include "NumberObject.h"
-#include <wtf/Variant.h>
 
 namespace JSC {
 
@@ -56,6 +55,5 @@ JSString* int32ToString(VM&, int32_t value, int32_t radix);
 JSString* int52ToString(VM&, int64_t value, int32_t radix);
 JSString* numberToString(VM&, double value, int32_t radix);
 String toStringWithRadix(double doubleValue, int32_t radix);
-Variant<int32_t, EncodedJSValue> extractToStringRadixArgument(ExecState*, JSValue radixValue);
 
 } // namespace JSC