dop251 / goja

ECMAScript/JavaScript engine in pure Go
MIT License
5.43k stars 365 forks source link

Go binding for function rest params does not work as expected #582

Closed yinxulai closed 2 months ago

yinxulai commented 3 months ago

Reproduce code

func TestRestParams(t *testing.T) {
    vm := goja.New()

    console.Enable(vm)

    vm.RunString(`
        function test(...params) {
            console.log(...params)
        }
    `)

    var test func (params ...any) any
    vm.ExportTo(vm.Get("test"), &test)
    test(1,2,3,4)
}

// output:
// Expected: 1,2,3,4
// Actual: [1,2,3,4]

It looks like goja will pass the go rest parameters as an array to the js function

dop251 commented 2 months ago

Thanks for reporting. There is even an Example, but the way it was written just masked the issue.

yinxulai commented 2 months ago

Can you open your github sponsors? Mybe i want buy you a drink.