[Webkit-unassigned] [Bug 131707] Simple ES6 feature: Number constructor extras

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Sep 17 11:05:05 PDT 2014


https://bugs.webkit.org/show_bug.cgi?id=131707





--- Comment #12 from Diego Pino <dpino at igalia.com>  2014-09-17 11:05:04 PST ---
(From update of attachment 238086)
View in context: https://bugs.webkit.org/attachment.cgi?id=238086&action=review

>> Source/JavaScriptCore/runtime/NumberConstructor.cpp:194
>> +    return JSValue::encode(jsBoolean(std::isfinite(number)));
> 
> Unnecessarily complex and inefficient. It should be more like this:
> 
>     JSValue argument = exec->argument(0);
>     bool isFinite = argument.isNumber() && (!argument.isDouble() || std::isfinite(argument.asDouble());
>     return JSValue::encode(jsBoolean(isFinite));
> 
> Could also do it without the isFinite local variable.

isDouble() is the same as isNumber() && !isInt32(). Since argument is already a number, !argument.isDouble() could be written as argument.isInt32(). My understanding is that this check is here as an optimization, to avoid executing std::isfinite().

>> Source/JavaScriptCore/runtime/NumberConstructor.cpp:206
>> +    return JSValue::encode(jsBoolean(std::isfinite(integer) && integer == arg0.toNumber(exec)));
> 
> Something like this:
> 
>     JSValue argument = exec->argument(0);
>     bool isInteger;
>     if (argument.isInt32())
>          isInteger = true;
>     else if (!argument.isDouble())
>          isInteger = false;
>     else {
>         double number = argument.asDouble();
>          isInteger = number == static_cast<int64_t>(double);
>     }
>     return JSValue::encode(jsBoolean(isInteger));

It doesn't work for Number.MAX_VALUE, which is 1.79E+308 (or 2^1024). Casting Number.MAX_VALUE to int64_t gets 9223372036854775807 (2^64 - 1).

>> Source/JavaScriptCore/runtime/NumberConstructor.cpp:218
>> +    return JSValue::encode(jsBoolean(std::isnan(number)));
> 
> Something like this:
> 
>     JSValue argument = exec->argument(0);
>     return JSValue::encode(jsBoolean(argument.isDouble() && std::isnan(argument.asDouble()));

OK.

>> Source/JavaScriptCore/runtime/NumberConstructor.cpp:232
>> +    return JSValue::encode(jsBoolean(std::abs(number) <= (std::pow(2, 53) - 1)));
> 
> Something like this:
> 
>     return JSValue::encode(jsBoolean(exec->argument(0).isMachineInt()));

It seems it doesn't work for MAX_SAFE_INTEGER, MAX_SAFE_INTEGER - 1, MIN_SAFE_INTEGER and MIN_SAFE_INTEGER + 1. Strange.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list