From c3f328c6ebbe12947e564dfc23144762cf9e587f Mon Sep 17 00:00:00 2001 From: Mark Striemer Date: Wed, 4 Jun 2014 16:54:31 -0500 Subject: [PATCH] Fix the >>>= operator (bug 1019729) --- .../testcases/javascript/nodedefinitions.py | 4 +++- tests/js/js_helper.py | 3 +++ tests/js/test_math.py | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/appvalidator/testcases/javascript/nodedefinitions.py b/appvalidator/testcases/javascript/nodedefinitions.py index b0afbe6..a3a5d32 100644 --- a/appvalidator/testcases/javascript/nodedefinitions.py +++ b/appvalidator/testcases/javascript/nodedefinitions.py @@ -1,3 +1,4 @@ +import ctypes import types from appvalidator.constants import MAX_STR_SIZE @@ -354,7 +355,8 @@ ASSIGNMENT_OPERATORS = { "%=": lambda l, r, gl, gr: 0 if gr == 0 else (gl % gr), "<<=": lambda l, r, gl, gr: int(gl) << int(gr), ">>=": lambda l, r, gl, gr: int(gl) >> int(gr), - ">>>=": lambda l, r, gl, gr: float(abs(int(gl)) >> gr), + ">>>=": lambda l, r, gl, gr: float( + ctypes.c_uint(int(gl)).value >> int(gr)), "|=": lambda l, r, gl, gr: int(gl) | int(gr), "^=": lambda l, r, gl, gr: int(gl) ^ int(gr), "&=": lambda l, r, gl, gr: int(gl) & int(gr), diff --git a/tests/js/js_helper.py b/tests/js/js_helper.py index e2d3bed..73517ab 100644 --- a/tests/js/js_helper.py +++ b/tests/js/js_helper.py @@ -66,6 +66,8 @@ class TestCase(helper.TestCase): Run the standard set of JS engine tests on the script passed via `script`. """ + print "Running", script + if self.err is None: self.setup_err() @@ -90,6 +92,7 @@ class TestCase(helper.TestCase): Assert that the value of a variable from the final script context contains the value specified. """ + print "Testing {var} == {val}".format(var=name, val=value) val = self.get_var(name) if isinstance(val, float): val *= 100000 diff --git a/tests/js/test_math.py b/tests/js/test_math.py index a5e2ac8..697e04f 100644 --- a/tests/js/test_math.py +++ b/tests/js/test_math.py @@ -170,3 +170,23 @@ class TestMathFuncs(TestCase): """) # We really don't care about the output here. + + def test_bit_shifting(self): + """Test for bit shifting operators.""" + self.setUp() + self.run_script(""" + var x = 1; + x >>= 0;""") + self.assert_var_eq("x", 1) + self.run_script(""" + var x = 1; + x >>= 1""") + self.assert_var_eq("x", 0) + self.run_script(""" + var x = -1; + x >>= 0;""") + self.assert_var_eq("x", -1) + self.run_script(""" + var x = -1; + x >>>= 0.2""") + self.assert_var_eq("x", 0xFFFFFFFF)