From 07a7fd9355b4f6f857ec83849ec796a703568c93 Mon Sep 17 00:00:00 2001 From: Dmitry Panov Date: Tue, 17 Aug 2021 16:10:38 +0100 Subject: [PATCH] Fixed argument variable reference resolution in stashless functions --- compiler_test.go | 11 +++++++++++ vm.go | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler_test.go b/compiler_test.go index bbacbf4a..22215f2e 100644 --- a/compiler_test.go +++ b/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) { src, err := ioutil.ReadFile("babel7.js") diff --git a/vm.go b/vm.go index 43b6799d..fb95a81c 100644 --- a/vm.go +++ b/vm.go @@ -2326,7 +2326,7 @@ func (r *resolveMixedStack) exec(vm *vm) { if r.idx > 0 { idx = vm.sb + vm.args + r.idx } else { - idx = vm.sb + r.idx + idx = vm.sb - r.idx } ref = newStashRef(r.typ, r.name, (*[]Value)(&vm.stack), idx)