Fixed missing ObjectPtr check in OpSetSelLocal (#194)

* fixes #193

* Cleanup
This commit is contained in:
earncef 2019-04-26 06:32:42 +02:00 committed by Daniel
parent adcf05d26f
commit 0440786b8d
2 changed files with 15 additions and 2 deletions

View file

@ -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
}

View file

@ -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) {