Skip to content

Commit

Permalink
Fixed missing ObjectPtr check in OpSetSelLocal (#194)
Browse files Browse the repository at this point in the history
* fixes #193

* Cleanup
  • Loading branch information
geseq authored and d5 committed Apr 26, 2019
1 parent adcf05d commit 0440786
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions runtime/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,9 +859,12 @@ func (v *VM) run() {
val := v.stack[v.sp-numSelectors-1]
v.sp -= numSelectors + 1

sp := v.curFrame.basePointer + localIndex
dst := v.stack[v.curFrame.basePointer+localIndex]
if obj, ok := dst.(*objects.ObjectPtr); ok {
dst = *obj.Value
}

if e := indexAssign(v.stack[sp], val, selectors); e != nil {
if e := indexAssign(dst, val, selectors); e != nil {
v.err = e
return
}
Expand Down
10 changes: 10 additions & 0 deletions runtime/vm_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ func TestFunction(t *testing.T) {
out = f2(10);
`, nil, 60)

expect(t, `
f1 := func(f) {
a := [undefined]
a[0] = func() { return f(a) }
return a[0]()
}
out = f1(func(a) { return 2 })
`, nil, 2)

// closures
expect(t, `
newAdder := func(x) {
Expand Down

0 comments on commit 0440786

Please sign in to comment.