+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
- 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
-
n = BigInt("0b10");
assert(n.toString() === "2");
-n = BigInt("0b010");
+n = BigInt("0b10");
assert(n.toString() === "2");
let binaryString = "0b1";
n = BigInt("0B10");
assert(n.toString() === "2");
-n = BigInt("0B010");
+n = BigInt("0B10");
assert(n.toString() === "2");
binaryString = "0B1";
+++ /dev/null
-//@ 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);
-
+++ /dev/null
-//@ 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");
-}
-
+++ /dev/null
-//@ 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);
-
+++ /dev/null
-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);
-
+++ /dev/null
-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");
-}
-
+++ /dev/null
-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);
-
+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
#include "JSFunction.h"
#include "JSGlobalObject.h"
#include "JSString.h"
-#include "NumberPrototype.h"
#include <wtf/Assertions.h>
-#include <wtf/Variant.h>
namespace JSC {
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]));
#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;
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));
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)
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
#pragma once
#include "NumberObject.h"
-#include <wtf/Variant.h>
namespace JSC {
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