diff options
author | Lars Knoll <lars.knoll@digia.com> | 2012-12-12 21:33:17 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-12-13 00:07:24 +0100 |
commit | 5968e9bb4eaca7ee08dac91eb3d621dfdc9ba1f8 (patch) | |
tree | 9223624462938c6f4bb50db469273500874e2070 /qmljs_runtime.h | |
parent | 151201ad24f5bd64f2f15e65e0facd366d838769 (diff) |
Fix the bit shift and complement operators
Take care of some corner cases and make them pass the
test suite.
Change-Id: Ic83508859800c62681ee873968b475ef81fffb82
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'qmljs_runtime.h')
-rw-r--r-- | qmljs_runtime.h | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/qmljs_runtime.h b/qmljs_runtime.h index 263c151145..aa2bc4e7cb 100644 --- a/qmljs_runtime.h +++ b/qmljs_runtime.h @@ -472,9 +472,9 @@ inline Value __qmljs_compl(Value value, ExecutionContext *ctx) int n; if (value.isConvertibleToInt()) - n = ~value.int_32; + n = value.int_32; else - n = Value::toInteger(__qmljs_to_number(value, ctx)); + n = Value::toInt32(__qmljs_to_number(value, ctx)); return Value::fromInt32(~n); } @@ -588,8 +588,6 @@ inline Value __qmljs_mod(Value left, Value right, ExecutionContext *ctx) return Value::fromDouble(fmod(lval, rval)); } -// ### unsigned shl missing? - inline Value __qmljs_shl(Value left, Value right, ExecutionContext *ctx) { TRACE2(left, right); @@ -618,12 +616,18 @@ inline Value __qmljs_ushr(Value left, Value right, ExecutionContext *ctx) { TRACE2(left, right); - if (Value::integerCompatible(left, right)) - return Value::fromInt32(uint(left.integerValue()) >> ((uint(right.integerValue()) & 0x1f))); + uint result; + if (Value::integerCompatible(left, right)) { + result = uint(left.integerValue()) >> (uint(right.integerValue()) & 0x1f); + } else { + unsigned lval = Value::toUInt32(__qmljs_to_number(left, ctx)); + unsigned rval = Value::toUInt32(__qmljs_to_number(right, ctx)) & 0x1f; + result = lval >> rval; + } - unsigned lval = Value::toUInt32(__qmljs_to_number(left, ctx)); - unsigned rval = Value::toUInt32(__qmljs_to_number(right, ctx)) & 0x1f; - return Value::fromInt32(lval >> rval); + if (result > INT_MAX) + return Value::fromDouble(result); + return Value::fromInt32(result); } inline Value __qmljs_gt(Value left, Value right, ExecutionContext *ctx) |