diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2012-11-19 11:54:54 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2012-11-19 13:57:51 +0100 |
commit | b072fd9317fa20d9206e9faaca7b0b45ae28a519 (patch) | |
tree | 8df50b7305108c52ed6899e5fa5d7f4655a14076 | |
parent | a2676884804fb523ee586f1ebc6a11353ec79fcb (diff) |
Added isNaN and isFinite to the global context.
Change-Id: Ia85d27a6ac82fd5dbf6b0f706747afa6418626b1
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r-- | qmljs_engine.cpp | 5 | ||||
-rw-r--r-- | qmljs_objects.cpp | 16 | ||||
-rw-r--r-- | qmljs_objects.h | 14 |
3 files changed, 34 insertions, 1 deletions
diff --git a/qmljs_engine.cpp b/qmljs_engine.cpp index 8097639e54..4415231934 100644 --- a/qmljs_engine.cpp +++ b/qmljs_engine.cpp @@ -162,7 +162,10 @@ ExecutionEngine::ExecutionEngine() glo->__put__(rootContext, identifier(QStringLiteral("Infinity")), Value::fromDouble(INFINITY)); glo->__put__(rootContext, identifier(QStringLiteral("eval")), Value::fromObject(new EvalFunction(rootContext))); - + // TODO: parseInt [15.1.2.2] + // TODO: parseFloat [15.1.2.3] + glo->__put__(rootContext, identifier(QStringLiteral("isNaN")), Value::fromObject(new IsNaNFunction(rootContext))); // isNaN [15.1.2.4] + glo->__put__(rootContext, identifier(QStringLiteral("isFinite")), Value::fromObject(new IsFiniteFunction(rootContext))); // isFinite [15.1.2.5] } ExecutionContext *ExecutionEngine::newContext() diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index 4f831b01bf..290a4f793c 100644 --- a/qmljs_objects.cpp +++ b/qmljs_objects.cpp @@ -487,6 +487,22 @@ Value EvalFunction::call(ExecutionContext *context, Value thisObject, Value *arg ctx->leaveCallContext(); } +/// isNaN [15.1.2.4] +Value IsNaNFunction::call(ExecutionContext * /*context*/, Value /*thisObject*/, Value *args, int /*argc*/, bool /*strictMode*/) +{ + // 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); +} + +/// isFinite [15.1.2.5] +Value IsFiniteFunction::call(ExecutionContext * /*context*/, Value /*thisObject*/, Value *args, int /*argc*/, bool /*strictMode*/) +{ + // 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); +} + static inline bool protect(const void *addr, size_t size) { size_t pageSize = sysconf(_SC_PAGESIZE); diff --git a/qmljs_objects.h b/qmljs_objects.h index 6d0e0fa35d..a2b956f567 100644 --- a/qmljs_objects.h +++ b/qmljs_objects.h @@ -532,6 +532,20 @@ struct EvalFunction : FunctionObject virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc, bool strictMode = false); }; +struct IsNaNFunction: FunctionObject +{ + IsNaNFunction(ExecutionContext *scope): FunctionObject(scope) {} + + virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc, bool strictMode = false); +}; + +struct IsFiniteFunction: FunctionObject +{ + IsFiniteFunction(ExecutionContext *scope): FunctionObject(scope) {} + + virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc, bool strictMode = false); +}; + struct RegExpObject: Object { QRegularExpression value; Value lastIndex; |