aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qmljs_engine.cpp5
-rw-r--r--qmljs_objects.cpp16
-rw-r--r--qmljs_objects.h14
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;