Skip to content

Commit

Permalink
Use correct createArgsRest variant when arguments are not in stash. F…
Browse files Browse the repository at this point in the history
…ixes dop251#327

Signed-off-by: Gabri <[email protected]>
  • Loading branch information
dop251 authored and Gabri3l committed Jan 24, 2022
1 parent f605f7b commit f08849b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ func (e *compiledFunctionLiteral) emitGetter(putOnStack bool) {
e.c.p.code[enterFunc2Mark] = ef2
}
}
if emitArgsRestMark != -1 {
if emitArgsRestMark != -1 && s.argsInStash {
e.c.p.code[emitArgsRestMark] = createArgsRestStash
}
} else {
Expand Down
35 changes: 35 additions & 0 deletions compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3942,6 +3942,41 @@ func TestFuncParamRestStashSimple(t *testing.T) {
testScript1(SCRIPT, asciiString("2,3"), t)
}

func TestRestArgsNotInStash(t *testing.T) {
const SCRIPT = `
function f(...rest) {
() => rest;
return rest.length;
}
f(1,2);
`
testScript1(SCRIPT, valueInt(2), t)
}

func TestRestArgsInStash(t *testing.T) {
const SCRIPT = `
function f(first, ...rest) {
() => first;
() => rest;
return rest.length;
}
f(1,2);
`
testScript1(SCRIPT, valueInt(1), t)
}

func TestRestArgsInStashFwdRef(t *testing.T) {
const SCRIPT = `
function f(first = eval(), ...rest) {
() => first;
() => rest;
return rest.length === 1 && rest[0] === 2;
}
f(1,2);
`
testScript1(SCRIPT, valueTrue, t)
}

func TestFuncParamRestPattern(t *testing.T) {
const SCRIPT = `
function f(arg1, ...{0: rest1, 1: rest2}) {
Expand Down

0 comments on commit f08849b

Please sign in to comment.