Browse Source

Fixed dynamic variable resolution in iteration scopes

Dmitry Panov 4 years ago
parent
commit
6cede2fa03
2 changed files with 11 additions and 0 deletions
  1. 10 0
      compiler_test.go
  2. 1 0
      vm.go

+ 10 - 0
compiler_test.go

@@ -4159,6 +4159,16 @@ func TestParameterOverride(t *testing.T) {
 	testScript1(SCRIPT, asciiString("default"), t)
 	testScript1(SCRIPT, asciiString("default"), t)
 }
 }
 
 
+func TestEvalInIterScope(t *testing.T) {
+	const SCRIPT = `
+	for (let a = 0; a < 1; a++) {
+		eval("a");
+	}
+	`
+
+	testScript1(SCRIPT, valueInt(0), t)
+}
+
 /*
 /*
 func TestBabel(t *testing.T) {
 func TestBabel(t *testing.T) {
 	src, err := ioutil.ReadFile("babel7.js")
 	src, err := ioutil.ReadFile("babel7.js")

+ 1 - 0
vm.go

@@ -3820,6 +3820,7 @@ func (copyStash) exec(vm *vm) {
 	}
 	}
 	vm.stashAllocs++
 	vm.stashAllocs++
 	newStash.values = append([]Value(nil), oldStash.values...)
 	newStash.values = append([]Value(nil), oldStash.values...)
+	newStash.names = oldStash.names
 	vm.stash = newStash
 	vm.stash = newStash
 	vm.pc++
 	vm.pc++
 }
 }