src.dualinventive.com/go/devsim/simulator/js/storage.go

42 lines
852 B
Go

package js
import (
"github.com/dop251/goja"
)
func (s *Simulator) storageSet(call goja.FunctionCall) goja.Value {
key := call.Argument(0)
value := call.Argument(1)
if err := s.m.Set(key.String(), value.Export()); err != nil {
s.m.WithField("err", err).Warning("storage: not set")
s.vm.NewTypeError("Not set")
}
return nil
}
func (s *Simulator) storageGet(call goja.FunctionCall) goja.Value {
key := call.Argument(0)
val, err := s.m.Get(key.String())
if err != nil {
s.m.WithField("err", err).Warning("storage: not get")
s.vm.NewTypeError("Not get")
}
return s.vm.ToValue(val)
}
func (s *Simulator) storageDel(call goja.FunctionCall) goja.Value {
key := call.Argument(0)
err := s.m.Del(key.String())
if err != nil {
s.m.WithField("err", err).Warning("storage: not del")
s.vm.NewTypeError("Not del")
}
return nil
}