X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/2d39b0e377c0896910ee49ae70082ba665faf986..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/tests/controlFlowProfiler/if-statement.js?ds=inline diff --git a/tests/controlFlowProfiler/if-statement.js b/tests/controlFlowProfiler/if-statement.js new file mode 100644 index 0000000..f31f719 --- /dev/null +++ b/tests/controlFlowProfiler/if-statement.js @@ -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.");