Răsfoiți Sursa

Applied fix for #148 to for-of loops.

Dmitry Panov 5 ani în urmă
părinte
comite
33474631bf
2 a modificat fișierele cu 12 adăugiri și 1 ștergeri
  1. 1 1
      compiler_stmt.go
  2. 11 0
      compiler_test.go

+ 1 - 1
compiler_stmt.go

@@ -345,7 +345,7 @@ func (c *compiler) compileForOfStatement(v *ast.ForOfStatement, needResult bool)
 
 func (c *compiler) compileLabeledForOfStatement(v *ast.ForOfStatement, needResult bool, label unistring.String) {
 	c.block = &block{
-		typ:        blockLoop,
+		typ:        blockLoopEnum,
 		outer:      c.block,
 		label:      label,
 		needResult: needResult,

+ 11 - 0
compiler_test.go

@@ -2032,6 +2032,17 @@ func TestReturnFromForInLoop(t *testing.T) {
 	testScript1(SCRIPT, valueTrue, t)
 }
 
+func TestReturnFromForOfLoop(t *testing.T) {
+	const SCRIPT = `
+	(function f() {
+		for (var i of [1]) {
+			return true;
+		}
+	})();
+	`
+	testScript1(SCRIPT, valueTrue, t)
+}
+
 func TestIfStackLeaks(t *testing.T) {
 	const SCRIPT = `
 	var t = 0;