name = scope->engine->newString(QLatin1String("isNaN"));
}
-Value IsNaNFunction::call(ExecutionContext * /*context*/, Value /*thisObject*/, Value *args, int /*argc*/)
+Value IsNaNFunction::call(ExecutionContext *context, Value /*thisObject*/, Value *args, int /*argc*/)
{
- // TODO: see if we can generate code for this directly
const Value &v = args[0];
- return Value::fromBoolean(v.isDouble() ? std::isnan(v.doubleValue()) : false);
+ if (v.integerCompatible())
+ return Value::fromBoolean(false);
+
+ double d = v.toNumber(context);
+ return Value::fromBoolean(std::isnan(d));
}
/// isFinite [15.1.2.5]
name = scope->engine->newString(QLatin1String("isFinite"));
}
-Value IsFiniteFunction::call(ExecutionContext * /*context*/, Value /*thisObject*/, Value *args, int /*argc*/)
+Value IsFiniteFunction::call(ExecutionContext *context, Value /*thisObject*/, Value *args, int /*argc*/)
{
- // TODO: see if we can generate code for this directly
const Value &v = args[0];
- return Value::fromBoolean(v.isDouble() ? std::isfinite(v.doubleValue()) : true);
+ if (v.integerCompatible())
+ return Value::fromBoolean(true);
+
+ double d = v.toNumber(context);
+ return Value::fromBoolean(std::isfinite(d));
}
inline bool isPrimitive() const { return !isObject(); }
#if CPU(X86_64)
+ inline bool integerCompatible() const {
+ const quint64 mask = quint64(ConvertibleToInt) << 32;
+ return (val & mask) == mask;
+ }
static inline bool integerCompatible(Value a, Value b) {
const quint64 mask = quint64(ConvertibleToInt) << 32;
return ((a.val & b.val) & mask) == mask;
return ((a.val | b.val) & mask) != mask;
}
#else
+ inline bool integerCompatible() const {
+ return (tag & ConvertibleToInt) == ConvertibleToInt;
+ }
static inline bool integerCompatible(Value a, Value b) {
return ((a.tag & b.tag) & ConvertibleToInt) == ConvertibleToInt;
}