Skip to content

Commit d0d8f4d

Browse files
committed
Added fix for Number.MIN_VALUE when denormal support is disabled
1 parent 4f71d85 commit d0d8f4d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

JavaScriptCore/runtime/NumberConstructor.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ NumberConstructor::NumberConstructor(VM& vm, Structure* structure)
6060
{
6161
}
6262

63+
static double MinValueAccountingForDenormals = DBL_MIN;
64+
6365
void NumberConstructor::finishCreation(VM& vm, NumberPrototype* numberPrototype)
6466
{
6567
Base::finishCreation(vm, NumberPrototype::info()->className);
@@ -70,6 +72,14 @@ void NumberConstructor::finishCreation(VM& vm, NumberPrototype* numberPrototype)
7072

7173
// no. of arguments for constructor
7274
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
75+
76+
// Test for denormal support. Use 5E-324 as MIN_VALUE if we have denormals
77+
// Careful: this test gets easily optimized away by the compiler, hence
78+
// the assignment to another var.
79+
double denormalTest = MinValueAccountingForDenormals / 2;
80+
if( denormalTest != 0 ) {
81+
MinValueAccountingForDenormals = 5E-324;
82+
}
7383
}
7484

7585
bool NumberConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
@@ -104,7 +114,7 @@ static EncodedJSValue numberConstructorMaxValue(ExecState*, EncodedJSValue, Enco
104114

105115
static EncodedJSValue numberConstructorMinValue(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName)
106116
{
107-
return JSValue::encode(jsNumber(5E-324));
117+
return JSValue::encode(jsNumber(MinValueAccountingForDenormals));
108118
}
109119

110120
// ECMA 15.7.1

0 commit comments

Comments
 (0)