Fix the shift operators
authorLars Knoll <lars.knoll@digia.com>
Wed, 17 Oct 2012 21:07:41 +0000 (23:07 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Wed, 17 Oct 2012 21:10:28 +0000 (23:10 +0200)
The JS spec demands that the right hand argument is being
masked with 0x1f before applying the nit shift.

See e.g. http://bclary.com/2004/11/07/#a-11.7

Change-Id: I6a7dee4708b2fe93df984f13752f7f00b5f2f367
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qmljs_runtime.h

index c821010..2c22071 100644 (file)
@@ -1078,21 +1078,21 @@ inline Value __qmljs_mod(Value left, Value right, Context *ctx)
 inline Value __qmljs_shl(Value left, Value right, Context *ctx)
 {
     int lval = __qmljs_to_int32(left, ctx);
-    unsigned rval = __qmljs_to_uint32(right, ctx);
+    unsigned rval = __qmljs_to_uint32(right, ctx) & 0x1f;
     return Value::fromInt32(lval << rval);
 }
 
 inline Value __qmljs_shr(Value left, Value right, Context *ctx)
 {
     int lval = __qmljs_to_int32(left, ctx);
-    unsigned rval = __qmljs_to_uint32(right, ctx);
+    unsigned rval = __qmljs_to_uint32(right, ctx) & 0x1f;
     return Value::fromInt32(lval >> rval);
 }
 
 inline Value __qmljs_ushr(Value left, Value right, Context *ctx)
 {
     unsigned lval = __qmljs_to_uint32(left, ctx);
-    unsigned rval = __qmljs_to_uint32(right, ctx);
+    unsigned rval = __qmljs_to_uint32(right, ctx) & 0x1f;
     return Value::fromInt32(lval >> rval);
 }