Fix optimization in JS BE
Don't apply while condition folding when corresponding break statement breaks outer loop.
This commit is contained in:
@@ -105,7 +105,7 @@ class WhileConditionFolding(val body: JsBlock) {
|
||||
// therefore for single `break` we should return `false`.
|
||||
is JsBreak -> {
|
||||
val target = statement.label?.name
|
||||
if (label == null || label == target) JsLiteral.FALSE else null
|
||||
if (label == target) JsLiteral.FALSE else null
|
||||
}
|
||||
|
||||
// Code like this
|
||||
|
||||
@@ -40,4 +40,6 @@ class WhileConditionFoldingTest : BasicOptimizerTest("while-condition-folding")
|
||||
@Test fun doWhileWithNestedContinue() = box()
|
||||
|
||||
@Test fun labeledContinueInNestedLoop() = box()
|
||||
|
||||
@Test fun labeledBreak() = box()
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
function box() {
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var log = "";
|
||||
outer: while (i < 10) {
|
||||
while (j < 10) {
|
||||
if (i + j >= 3) {
|
||||
break outer;
|
||||
}
|
||||
log += i + "," + j + ";";
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (log != "0,0;0,1;0,2;") return "fail: " + log;
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
function box() {
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var log = "";
|
||||
outer: while (i < 10) {
|
||||
while (j < 10) {
|
||||
if (i + j >= 3) {
|
||||
break outer;
|
||||
}
|
||||
log += i + "," + j + ";";
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (log != "0,0;0,1;0,2;") return "fail: " + log;
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user