Fixed missing ObjectPtr check in OpSetSelLocal (#194)
* fixes #193 * Cleanup
This commit is contained in:
parent
adcf05d26f
commit
0440786b8d
2 changed files with 15 additions and 2 deletions
|
@ -859,9 +859,12 @@ func (v *VM) run() {
|
||||||
val := v.stack[v.sp-numSelectors-1]
|
val := v.stack[v.sp-numSelectors-1]
|
||||||
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
|
v.err = e
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,16 @@ func TestFunction(t *testing.T) {
|
||||||
out = f2(10);
|
out = f2(10);
|
||||||
`, nil, 60)
|
`, 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
|
// closures
|
||||||
expect(t, `
|
expect(t, `
|
||||||
newAdder := func(x) {
|
newAdder := func(x) {
|
||||||
|
|
Loading…
Reference in a new issue