Browse Source

Fixed argument variable reference resolution in stashless functions

Dmitry Panov 4 years ago
parent
commit
07a7fd9355
2 changed files with 12 additions and 1 deletions
  1. 11 0
      compiler_test.go
  2. 1 1
      vm.go

+ 11 - 0
compiler_test.go

@@ -4113,6 +4113,17 @@ func TestArrowUseStrict(t *testing.T) {
 	}
 	}
 }
 }
 
 
+func TestParameterOverride(t *testing.T) {
+	const SCRIPT = `
+	function f(arg) {
+		var arg = arg || "default"
+		return arg
+	}
+	f()
+	`
+	testScript1(SCRIPT, asciiString("default"), t)
+}
+
 /*
 /*
 func TestBabel(t *testing.T) {
 func TestBabel(t *testing.T) {
 	src, err := ioutil.ReadFile("babel7.js")
 	src, err := ioutil.ReadFile("babel7.js")

+ 1 - 1
vm.go

@@ -2326,7 +2326,7 @@ func (r *resolveMixedStack) exec(vm *vm) {
 	if r.idx > 0 {
 	if r.idx > 0 {
 		idx = vm.sb + vm.args + r.idx
 		idx = vm.sb + vm.args + r.idx
 	} else {
 	} else {
-		idx = vm.sb + r.idx
+		idx = vm.sb - r.idx
 	}
 	}
 
 
 	ref = newStashRef(r.typ, r.name, (*[]Value)(&vm.stack), idx)
 	ref = newStashRef(r.typ, r.name, (*[]Value)(&vm.stack), idx)