diff options
author | Lars Knoll <lars.knoll@digia.com> | 2012-12-12 23:43:53 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-12-12 16:04:53 +0100 |
commit | 949303cd7da0edcab235bc19d5fad7d4af7eaed3 (patch) | |
tree | 8fd968a837d10dbc18b3a1135f2be41dfda838fa /qmljs_objects.cpp | |
parent | 42ebe165489b5429d1e1dc9f850bbf7d37dd127f (diff) |
Fix isNaN and isFinite
We need to convert objects to numbers before doing the
check.
Change-Id: Ie25128b6145845a3eb3e0098f5c5fc09f2be6830
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'qmljs_objects.cpp')
-rw-r--r-- | qmljs_objects.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index d7d0365db3..12269f2030 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)); } |