Fix regression caused by earlier bitwise and optimisation. 1 & undefined != 1.
authoroliver <oliver@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Nov 2007 04:32:55 +0000 (04:32 +0000)
committeroliver <oliver@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Nov 2007 04:32:55 +0000 (04:32 +0000)
Reviewed by Maciej.

The implementation of JSImmediate::areBothImmediateNumbers relies on
(JSImmediate::getTag(immediate1) & JSImmediate::getTag(immediate2)) having
a unique result when both immediate values are numbers.

The regression was due to UndefinedType & NumberType returning NumberType (3 & 1).
By swapping the value of NumberType and UndefinedType this ceases to be a problem.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27630 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/JSType.h
LayoutTests/ChangeLog
LayoutTests/fast/js/bitwise-and-on-undefined-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/bitwise-and-on-undefined.html [new file with mode: 0644]

index eeef947c889a1d7d60e82ed367859ba22af43a2a..4abf76bf64b9aedd3965eb05ef29e35af968ccca 100644 (file)
@@ -1,3 +1,19 @@
+2007-11-08  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Maciej.
+
+        Fix regression caused by earlier bitwise and optimisation.  1 & undefined != 1.
+
+        The implementation of JSImmediate::areBothImmediateNumbers relies on 
+        (JSImmediate::getTag(immediate1) & JSImmediate::getTag(immediate2)) having 
+        a unique result when both immediate values are numbers.
+
+        The regression was due to UndefinedType & NumberType returning NumberType (3 & 1).
+        By swapping the value of NumberType and UndefinedType this ceases to be a problem.
+
+        * kjs/JSType.h:
+        (KJS::):
+
 2007-11-08  Darin Adler  <darin@apple.com>
 
         - fix build
index 1b7ad94c99175dce3cfaa3ffaef28080efb2a1c7..1c9418c9e5accb5eb1775f1c48ce60ba4aa01e6f 100644 (file)
@@ -29,9 +29,9 @@ namespace KJS {
  */
 enum JSType {
     UnspecifiedType   = 0,
-    NumberType        = 1,
+    UndefinedType     = 1,
     BooleanType       = 2,
-    UndefinedType     = 3,
+    NumberType        = 3,
     NullType          = 4,
     StringType        = 5,
     ObjectType        = 6,
index eaf559a375114404023833a72acb0e47487aa4e5..9ea2d8ccafe1951ef17a7c1cb6d46962666a7d0a 100644 (file)
@@ -1,3 +1,12 @@
+2007-11-08  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Maciej.
+
+        Layout test to guard against bit operation regressions.
+
+        * fast/js/bitwise-and-on-undefined-expected.txt: Added.
+        * fast/js/bitwise-and-on-undefined.html: Added.
+
 2007-11-08  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Beth Dakin.
diff --git a/LayoutTests/fast/js/bitwise-and-on-undefined-expected.txt b/LayoutTests/fast/js/bitwise-and-on-undefined-expected.txt
new file mode 100644 (file)
index 0000000..601e64f
--- /dev/null
@@ -0,0 +1,13 @@
+This tests the bitwise operators work correctly in conjunction with undefined and null.
+SUCCESS: 0 & null = 0
+SUCCESS: 0 & undefined = 0
+SUCCESS: 1 & null = 0
+SUCCESS: 1 & undefined = 0
+SUCCESS: 0 | null = 0
+SUCCESS: 0 | undefined = 0
+SUCCESS: 1 | null = 1
+SUCCESS: 1 | undefined = 1
+SUCCESS: 0 ^ null = 0
+SUCCESS: 0 ^ undefined = 0
+SUCCESS: 1 ^ null = 1
+SUCCESS: 1 ^ undefined = 1
diff --git a/LayoutTests/fast/js/bitwise-and-on-undefined.html b/LayoutTests/fast/js/bitwise-and-on-undefined.html
new file mode 100644 (file)
index 0000000..889a281
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+
+<html>
+    <head>
+        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+        <title>test of bitwise operators mixing integers, null, and undefined</title>
+        <style>
+            .failure { color: red; }
+            .success { color: green; }
+        </style>
+        <script type="text/javascript">
+
+            if (window.layoutTestController)  layoutTestController.dumpAsText();
+
+            function log(msg) {
+                document.getElementById("log").innerHTML += msg;
+            }
+
+            function logTest(expression, expected) {
+                var result;
+                try {
+                    result = eval(expression);
+                } catch (e) {
+                    result = e;
+                }
+                if (result != expected)
+                    log("<li class='failure'>FAILED: " + expression + " = " + result + " -- expected: " + expected + "</li>");
+                else
+                    log("<li class='success'>SUCCESS: " + expression + " = " + result + "</li>");
+                
+            }
+            
+            function runTest() {
+                logTest("0 & null", 0);
+                logTest("0 & undefined", 0);
+                logTest("1 & null", 0);
+                logTest("1 & undefined", 0);
+                logTest("0 | null", 0);
+                logTest("0 | undefined", 0);
+                logTest("1 | null", 1);
+                logTest("1 | undefined", 1);
+                logTest("0 ^ null", 0);
+                logTest("0 ^ undefined", 0);
+                logTest("1 ^ null", 1);
+                logTest("1 ^ undefined", 1);
+            }
+            
+        </script>
+        
+    </head>
+    This tests the bitwise operators work correctly in conjunction with undefined and null.<br />
+    <body onload="runTest()">
+        <ul id="log"></ul>
+    </body>
+</html>