aboutsummaryrefslogtreecommitdiffstats
path: root/qmljs_runtime.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2012-12-12 22:46:57 +0100
committerErik Verbruggen <erik.verbruggen@digia.com>2012-12-12 14:57:43 +0100
commit42ebe165489b5429d1e1dc9f850bbf7d37dd127f (patch)
tree215f2a078431b3a60250a20065cb6b4047bf47ab /qmljs_runtime.cpp
parent8b9a17e97c67eac5163b25eab4ededdfdf6e9354 (diff)
Fix increment and decrement operators
These operators have semantics that are different from (foo + 1), as they always convert the LHS to a number first. Change-Id: I3fb4a1a328e3dfcb334875435c3cec90d01b67dd Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'qmljs_runtime.cpp')
-rw-r--r--qmljs_runtime.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/qmljs_runtime.cpp b/qmljs_runtime.cpp
index 25a3c11ec0..5ef2c6c9f0 100644
--- a/qmljs_runtime.cpp
+++ b/qmljs_runtime.cpp
@@ -873,6 +873,28 @@ void __qmljs_builtin_declare_var(ExecutionContext *ctx, bool deletable, String *
ctx->createMutableBinding(name, deletable);
}
+Value __qmljs_increment(Value value, ExecutionContext *ctx)
+{
+ TRACE1(value);
+
+ if (value.isInteger())
+ return Value::fromInt32(value.integerValue() + 1);
+
+ double d = __qmljs_to_number(value, ctx);
+ return Value::fromDouble(d + 1);
+}
+
+Value __qmljs_decrement(Value value, ExecutionContext *ctx)
+{
+ TRACE1(value);
+
+ if (value.isInteger())
+ return Value::fromInt32(value.integerValue() - 1);
+
+ double d = __qmljs_to_number(value, ctx);
+ return Value::fromDouble(d - 1);
+}
+
} // extern "C"