From: Lars Knoll Date: Wed, 12 Dec 2012 22:43:53 +0000 (+0100) Subject: Fix isNaN and isFinite X-Git-Tag: upstream/5.2.1~669^2~659^2~701 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=949303cd7da0edcab235bc19d5fad7d4af7eaed3;p=platform%2Fupstream%2Fqtdeclarative.git Fix isNaN and isFinite We need to convert objects to numbers before doing the check. Change-Id: Ie25128b6145845a3eb3e0098f5c5fc09f2be6830 Reviewed-by: Simon Hausmann --- diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index d7d0365..12269f2 100644 --- a/qmljs_objects.cpp +++ b/qmljs_objects.cpp @@ -670,11 +670,14 @@ IsNaNFunction::IsNaNFunction(ExecutionContext *scope) 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] @@ -684,11 +687,14 @@ IsFiniteFunction::IsFiniteFunction(ExecutionContext *scope) 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)); } diff --git a/qmljs_value.h b/qmljs_value.h index 3d29deb..7f095ca 100644 --- a/qmljs_value.h +++ b/qmljs_value.h @@ -205,6 +205,10 @@ struct Value 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; @@ -214,6 +218,9 @@ struct Value 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; }