]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - tests/controlFlowProfiler/if-statement.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / controlFlowProfiler / if-statement.js
diff --git a/tests/controlFlowProfiler/if-statement.js b/tests/controlFlowProfiler/if-statement.js
new file mode 100644 (file)
index 0000000..f31f719
--- /dev/null
@@ -0,0 +1,56 @@
+load("./driver/driver.js");
+
+var a, b, c, d;
+
+function testIf(x) {
+    if (x > 10 && x < 20) {
+        return a;
+    } else if (x > 20 && x < 30) {
+        return b;
+    } else if (x > 30 && x < 40) {
+        return c;
+    } else {
+        return d;
+    }
+
+    return null;
+}
+
+function noMatches(x) {
+    if (x > 10 && x < 20) {
+        return a;
+    } else if (x > 20 && x < 30) {
+        return b;
+    } else {
+        return c;
+    }
+}
+
+assert(!hasBasicBlockExecuted(testIf, "return a"), "should not have executed yet.");
+assert(!hasBasicBlockExecuted(testIf, "return b"), "should not have executed yet.");
+assert(!hasBasicBlockExecuted(testIf, "return c"), "should not have executed yet.");
+assert(!hasBasicBlockExecuted(testIf, "return d"), "should not have executed yet.");
+
+testIf(11);
+assert(hasBasicBlockExecuted(testIf, "return a"), "should have executed.");
+assert(hasBasicBlockExecuted(testIf, "x > 10"), "should have executed.");
+assert(!hasBasicBlockExecuted(testIf, "return b"), "should not have executed yet.");
+
+testIf(21);
+assert(hasBasicBlockExecuted(testIf, "return b"), "should have executed.");
+assert(!hasBasicBlockExecuted(testIf, "return c"), "should not have executed yet.");
+
+testIf(31);
+assert(hasBasicBlockExecuted(testIf, "return c"), "should have executed.");
+assert(!hasBasicBlockExecuted(testIf, "return d"), "should not have executed yet.");
+
+testIf(0);
+assert(hasBasicBlockExecuted(testIf, "return d"), "should have executed.");
+
+
+noMatches(0);
+assert(!hasBasicBlockExecuted(noMatches, "return a"), "should not have executed yet.");
+assert(hasBasicBlockExecuted(noMatches, "x > 10"), "should have executed.");
+assert(!hasBasicBlockExecuted(noMatches, "return b"), "should not have executed yet.");
+assert(hasBasicBlockExecuted(noMatches, "x > 20"), "should have executed.");
+assert(hasBasicBlockExecuted(noMatches, "return c"), "should have executed.");