Fix Greater and GreaterEq nodes to emit code in the correct order.
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jun 2008 05:09:27 +0000 (05:09 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jun 2008 05:09:27 +0000 (05:09 +0000)
Reviewed by Alexey.

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

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/nodes.cpp
LayoutTests/ChangeLog
LayoutTests/fast/js/order-of-operations-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/order-of-operations.html [new file with mode: 0644]
LayoutTests/fast/js/resources/order-of-operations.js [new file with mode: 0644]

index 74de875..ff2088d 100644 (file)
@@ -1,3 +1,14 @@
+2008-06-05  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Alexey.
+
+        Fix Greater and GreaterEq nodes to emit code for the left
+        and right sub-expressions in the correct order.
+
+        * kjs/nodes.cpp:
+        (KJS::GreaterNode::emitCode):
+        (KJS::GreaterEqNode::emitCode):
+
 2008-06-05  Antti Koivisto  <antti@apple.com>
 
         Reviewed by Alp Toker.
index d1b5798..67e46a4 100644 (file)
@@ -876,9 +876,9 @@ RegisterID* LessNode::emitCode(CodeGenerator& generator, RegisterID* dst)
 
 RegisterID* GreaterNode::emitCode(CodeGenerator& generator, RegisterID* dst)
 {
-    RefPtr<RegisterID> src1 = generator.emitNode(m_expr2.get());
-    RegisterID* src2 = generator.emitNode(m_expr1.get());
-    return generator.emitLess(generator.finalDestination(dst, src1.get()), src1.get(), src2);
+    RefPtr<RegisterID> src1 = generator.emitNode(m_expr1.get());
+    RegisterID* src2 = generator.emitNode(m_expr2.get());
+    return generator.emitLess(generator.finalDestination(dst, src1.get()), src2, src1.get());
 }
 
 RegisterID* LessEqNode::emitCode(CodeGenerator& generator, RegisterID* dst)
@@ -890,9 +890,9 @@ RegisterID* LessEqNode::emitCode(CodeGenerator& generator, RegisterID* dst)
 
 RegisterID* GreaterEqNode::emitCode(CodeGenerator& generator, RegisterID* dst)
 {
-    RefPtr<RegisterID> src1 = generator.emitNode(m_expr2.get());
-    RegisterID* src2 = generator.emitNode(m_expr1.get());
-    return generator.emitLessEq(generator.finalDestination(dst, src1.get()), src1.get(), src2);
+    RefPtr<RegisterID> src1 = generator.emitNode(m_expr1.get());
+    RegisterID* src2 = generator.emitNode(m_expr2.get());
+    return generator.emitLessEq(generator.finalDestination(dst, src1.get()), src2, src1.get());
 }
 
 RegisterID* InstanceOfNode::emitCode(CodeGenerator& generator, RegisterID* dst)
index ea5095a..1249a4b 100644 (file)
@@ -1,3 +1,13 @@
+2008-06-05  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Alexey.
+
+        Tests to ensure we evaluate binary operators in the correct order.
+
+        * fast/js/order-of-operations-expected.txt: Added.
+        * fast/js/order-of-operations.html: Added.
+        * fast/js/resources/order-of-operations.js: Added.
+
 2008-06-05  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by Eric.
diff --git a/LayoutTests/fast/js/order-of-operations-expected.txt b/LayoutTests/fast/js/order-of-operations-expected.txt
new file mode 100644 (file)
index 0000000..13c7a83
--- /dev/null
@@ -0,0 +1,21 @@
+PASS (function(){ leftRight = ""; left() > right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() >= right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() < right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() <= right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() + right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() - right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() / right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() * right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() % right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() << right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() >> right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() >>> right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() || right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() && right(); return leftRight; })() is "Left"
+PASS (function(){ leftRight = ""; left() & right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() | right(); return leftRight; })() is "LeftRight"
+PASS (function(){ leftRight = ""; left() ^ right(); return leftRight; })() is "LeftRight"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/js/order-of-operations.html b/LayoutTests/fast/js/order-of-operations.html
new file mode 100644 (file)
index 0000000..b0b1383
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/order-of-operations.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/js/resources/order-of-operations.js b/LayoutTests/fast/js/resources/order-of-operations.js
new file mode 100644 (file)
index 0000000..fdcef7f
--- /dev/null
@@ -0,0 +1,28 @@
+var leftRight;
+function left() {
+    leftRight = leftRight + "Left";
+}
+
+function right() {
+    leftRight = leftRight + "Right";
+}
+
+shouldBe('(function(){ leftRight = ""; left() > right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() >= right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() < right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() <= right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() + right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() - right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() / right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() * right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() % right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() << right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() >> right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() >>> right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() || right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() && right(); return leftRight; })()', '"Left"');
+shouldBe('(function(){ leftRight = ""; left() & right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() | right(); return leftRight; })()', '"LeftRight"');
+shouldBe('(function(){ leftRight = ""; left() ^ right(); return leftRight; })()', '"LeftRight"');
+
+var successfullyParsed = true;