diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 17ac189b1..38e8b23b9 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -807,10 +807,10 @@ func (v *VM) execute(ctx *Context, op Instruction) { switch t := elem.value.Value().(type) { case []StackItem: v.estack.PushVal(len(t)) - case []uint8: + case map[interface{}]StackItem: v.estack.PushVal(len(t)) default: - panic("ARRAYSIZE: item not of type []StackItem") + v.estack.PushVal(len(elem.Bytes())) } case SIZE: diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 4b121d6e3..428a24735 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -727,6 +727,34 @@ func TestSIZEBool(t *testing.T) { assert.Equal(t, makeStackItem(1), vm.estack.Pop().value) } +func TestARRAYSIZEArray(t *testing.T) { + prog := makeProgram(ARRAYSIZE) + vm := load(prog) + vm.estack.PushVal([]StackItem{ + makeStackItem(1), + makeStackItem([]byte{}), + }) + vm.Run() + assert.Equal(t, false, vm.HasFailed()) + assert.Equal(t, 1, vm.estack.Len()) + assert.Equal(t, makeStackItem(2), vm.estack.Pop().value) +} + +func TestARRAYSIZEMap(t *testing.T) { + prog := makeProgram(ARRAYSIZE) + vm := load(prog) + + m := NewMapItem() + m.Add(makeStackItem(5), makeStackItem(6)) + m.Add(makeStackItem([]byte{0, 1}), makeStackItem(6)) + vm.estack.Push(&Element{value: m}) + + vm.Run() + assert.Equal(t, false, vm.HasFailed()) + assert.Equal(t, 1, vm.estack.Len()) + assert.Equal(t, makeStackItem(2), vm.estack.Pop().value) +} + func TestKEYSMap(t *testing.T) { prog := makeProgram(KEYS) vm := load(prog)