diff --git a/Source/JavaScriptCore/dfg/DFGOperations.cpp b/Source/JavaScriptCore/dfg/DFGOperations.cpp index 3e24a3851547..2119b699a6ce 100644 --- a/Source/JavaScriptCore/dfg/DFGOperations.cpp +++ b/Source/JavaScriptCore/dfg/DFGOperations.cpp @@ -177,9 +177,6 @@ static ALWAYS_INLINE void putWithThis(JSGlobalObject* globalObject, EncodedJSVal static ALWAYS_INLINE EncodedJSValue parseIntResult(double input) { - int asInt = static_cast(input); - if (static_cast(asInt) == input && (asInt || !std::signbit(input))) [[likely]] - return JSValue::encode(jsNumber(asInt)); return JSValue::encode(jsNumber(input)); } diff --git a/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp b/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp index a22e99811a07..98c9052155b6 100644 --- a/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp +++ b/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp @@ -613,7 +613,7 @@ JSValue JSInjectedScriptHost::weakMapEntries(JSGlobalObject* globalObject, CallF MarkedArgumentBuffer buffer; auto fetchCount = callFrame->argument(1).toIntegerOrInfinity(globalObject); - weakMap->takeSnapshot(buffer, fetchCount >= 0 ? static_cast(fetchCount) : 0); + weakMap->takeSnapshot(buffer, clampTo(fetchCount)); ASSERT(!buffer.hasOverflowed()); JSArray* array = constructEmptyArray(globalObject, nullptr); @@ -740,7 +740,7 @@ JSValue JSInjectedScriptHost::iteratorEntries(JSGlobalObject* globalObject, Call double fetchDouble = numberToFetchArg.toIntegerOrInfinity(globalObject); RETURN_IF_EXCEPTION(scope, { }); if (fetchDouble >= 0) - numberToFetch = static_cast(fetchDouble); + numberToFetch = clampTo(fetchDouble); JSArray* array = constructEmptyArray(globalObject, nullptr); RETURN_IF_EXCEPTION(scope, { }); diff --git a/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp b/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp index e7dc0fca3fab..3a4db00921af 100644 --- a/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp +++ b/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp @@ -1885,7 +1885,7 @@ LLINT_SLOW_PATH_DECL(slow_path_switch_imm) auto bytecode = pc->as(); JSValue scrutinee = getOperand(callFrame, bytecode.m_scrutinee); double value = scrutinee.asNumber(); - int32_t intValue = static_cast(value); + int32_t intValue = truncateDoubleToInt32(value); auto& unlinkedTable = codeBlock->unlinkedSwitchJumpTable(bytecode.m_tableIndex); if (value == intValue) [[likely]] { if (!unlinkedTable.isList()) { diff --git a/Source/JavaScriptCore/runtime/JSCJSValue.h b/Source/JavaScriptCore/runtime/JSCJSValue.h index e47a2590b0ee..34ad1c2c9949 100644 --- a/Source/JavaScriptCore/runtime/JSCJSValue.h +++ b/Source/JavaScriptCore/runtime/JSCJSValue.h @@ -1352,7 +1352,7 @@ ALWAYS_INLINE bool JSValue::getUInt32(uint32_t& v) const } if (isDouble()) { double d = asDouble(); - v = static_cast(d); + v = truncateDoubleToUint32(d); return v == d; } return false; diff --git a/Source/JavaScriptCore/runtime/LiteralParser.cpp b/Source/JavaScriptCore/runtime/LiteralParser.cpp index 15a45d8f5d13..b69114a05e7a 100644 --- a/Source/JavaScriptCore/runtime/LiteralParser.cpp +++ b/Source/JavaScriptCore/runtime/LiteralParser.cpp @@ -97,7 +97,7 @@ bool LiteralParser::tryJSONPParse(Vector& resu if (m_lexer.next() != TokNumber) return false; double doubleIndex = m_lexer.currentToken()->numberToken; - int index = (int)doubleIndex; + int index = truncateDoubleToInt32(doubleIndex); if (index != doubleIndex || index < 0) return false; entry.m_pathIndex = index; diff --git a/Source/JavaScriptCore/runtime/NumberPrototype.cpp b/Source/JavaScriptCore/runtime/NumberPrototype.cpp index 06fbf5303d22..5261115ed4b2 100644 --- a/Source/JavaScriptCore/runtime/NumberPrototype.cpp +++ b/Source/JavaScriptCore/runtime/NumberPrototype.cpp @@ -401,15 +401,16 @@ JSC_DEFINE_HOST_FUNCTION(numberProtoFuncToExponential, (JSGlobalObject* globalOb JSValue arg = callFrame->argument(0); // Perform ToInteger on the argument before remaining steps. - int decimalPlaces = static_cast(arg.toIntegerOrInfinity(globalObject)); + double decimalPlacesDouble = arg.toIntegerOrInfinity(globalObject); RETURN_IF_EXCEPTION(scope, { }); // Handle NaN and Infinity. if (!std::isfinite(x)) return JSValue::encode(jsNontrivialString(vm, String::number(x))); - if (decimalPlaces < 0 || decimalPlaces > 100) + if (decimalPlacesDouble < 0 || decimalPlacesDouble > 100) return throwVMRangeError(globalObject, scope, "toExponential() argument must be between 0 and 100"_s); + int decimalPlaces = static_cast(decimalPlacesDouble); // Round if the argument is not undefined, always format as exponential. NumberToStringBuffer buffer; @@ -477,15 +478,16 @@ JSC_DEFINE_HOST_FUNCTION(numberProtoFuncToPrecision, (JSGlobalObject* globalObje return JSValue::encode(jsString(vm, String::number(x))); // Perform ToInteger on the argument before remaining steps. - int significantFigures = static_cast(arg.toIntegerOrInfinity(globalObject)); + double significantFiguresDouble = arg.toIntegerOrInfinity(globalObject); RETURN_IF_EXCEPTION(scope, { }); // Handle NaN and Infinity. if (!std::isfinite(x)) return JSValue::encode(jsNontrivialString(vm, String::number(x))); - if (significantFigures < 1 || significantFigures > 100) + if (significantFiguresDouble < 1 || significantFiguresDouble > 100) return throwVMRangeError(globalObject, scope, "toPrecision() argument must be between 1 and 100"_s); + int significantFigures = static_cast(significantFiguresDouble); return JSValue::encode(jsString(vm, String::numberToStringFixedPrecision(x, significantFigures, TrailingZerosPolicy::Keep))); } diff --git a/Source/JavaScriptCore/runtime/StringConstructor.cpp b/Source/JavaScriptCore/runtime/StringConstructor.cpp index 740df0e74a5a..1637552b775c 100644 --- a/Source/JavaScriptCore/runtime/StringConstructor.cpp +++ b/Source/JavaScriptCore/runtime/StringConstructor.cpp @@ -129,7 +129,7 @@ JSC_DEFINE_HOST_FUNCTION(stringFromCodePoint, (JSGlobalObject* globalObject, Cal double codePointAsDouble = callFrame->uncheckedArgument(i).toNumber(globalObject); RETURN_IF_EXCEPTION(scope, encodedJSValue()); - uint32_t codePoint = static_cast(codePointAsDouble); + uint32_t codePoint = truncateDoubleToUint32(codePointAsDouble); if (codePoint != codePointAsDouble || codePoint > UCHAR_MAX_VALUE) return throwVMError(globalObject, scope, createRangeError(globalObject, "Arguments contain a value that is out of range of code points"_s));