Skip to content

Commit

Permalink
Fixed panic in newArrayFromIter when the iterator is already closed. F…
Browse files Browse the repository at this point in the history
…ixes dop251#375
  • Loading branch information
dop251 committed Mar 24, 2022
1 parent b09a6bf commit a18ffb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1842,9 +1842,11 @@ func (_newArrayFromIter) exec(vm *vm) {
iter := vm.iterStack[l].iter
vm.iterStack[l] = iterStackItem{}
vm.iterStack = vm.iterStack[:l]
iter.iterate(func(val Value) {
values = append(values, val)
})
if iter.iterator != nil {
iter.iterate(func(val Value) {
values = append(values, val)
})
}
vm.push(vm.r.newArrayValues(values))
vm.pc++
}
Expand Down
10 changes: 10 additions & 0 deletions vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ func TestResolveMixedStack1(t *testing.T) {
testScript(SCRIPT, valueInt(42), t)
}

func TestNewArrayFromIterClosed(t *testing.T) {
const SCRIPT = `
const [a, ...other] = [];
assert.sameValue(a, undefined);
assert(Array.isArray(other));
assert.sameValue(other.length, 0);
`
testScriptWithTestLib(SCRIPT, _undefined, t)
}

func BenchmarkVmNOP2(b *testing.B) {
prg := []func(*vm){
//loadVal(0).exec,
Expand Down

0 comments on commit a18ffb9

Please sign in to comment.