Skip to content
3 changes: 0 additions & 3 deletions Source/JavaScriptCore/dfg/DFGOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ static ALWAYS_INLINE void putWithThis(JSGlobalObject* globalObject, EncodedJSVal

static ALWAYS_INLINE EncodedJSValue parseIntResult(double input)
{
int asInt = static_cast<int>(input);
if (static_cast<double>(asInt) == input && (asInt || !std::signbit(input))) [[likely]]
return JSValue::encode(jsNumber(asInt));
return JSValue::encode(jsNumber(input));
}

Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned>(fetchCount) : 0);
weakMap->takeSnapshot(buffer, clampTo<unsigned>(fetchCount));
ASSERT(!buffer.hasOverflowed());

JSArray* array = constructEmptyArray(globalObject, nullptr);
Expand Down Expand Up @@ -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<unsigned>(fetchDouble);
numberToFetch = clampTo<unsigned>(fetchDouble);

JSArray* array = constructEmptyArray(globalObject, nullptr);
RETURN_IF_EXCEPTION(scope, { });
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/llint/LLIntSlowPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ LLINT_SLOW_PATH_DECL(slow_path_switch_imm)
auto bytecode = pc->as<OpSwitchImm>();
JSValue scrutinee = getOperand(callFrame, bytecode.m_scrutinee);
double value = scrutinee.asNumber();
int32_t intValue = static_cast<int32_t>(value);
int32_t intValue = truncateDoubleToInt32(value);
auto& unlinkedTable = codeBlock->unlinkedSwitchJumpTable(bytecode.m_tableIndex);
if (value == intValue) [[likely]] {
if (!unlinkedTable.isList()) {
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/JSCJSValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ ALWAYS_INLINE bool JSValue::getUInt32(uint32_t& v) const
}
if (isDouble()) {
double d = asDouble();
v = static_cast<uint32_t>(d);
v = truncateDoubleToUint32(d);
return v == d;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/LiteralParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool LiteralParser<CharType, reviverMode>::tryJSONPParse(Vector<JSONPData>& 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;
Expand Down
10 changes: 6 additions & 4 deletions Source/JavaScriptCore/runtime/NumberPrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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<int>(decimalPlacesDouble);

// Round if the argument is not undefined, always format as exponential.
NumberToStringBuffer buffer;
Expand Down Expand Up @@ -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<int>(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<int>(significantFiguresDouble);

return JSValue::encode(jsString(vm, String::numberToStringFixedPrecision(x, significantFigures, TrailingZerosPolicy::Keep)));
}
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/StringConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(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));
Expand Down
Loading