Unverified Commit c2cf74dd authored by Simon Esposito's avatar Simon Esposito Committed by GitHub
Browse files

Export js values before storing them in localcache (#845)

parent 5be9ba3f
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -16,29 +16,27 @@ package server

import (
	"sync"

	"github.com/dop251/goja"
)

type RuntimeJavascriptLocalCache struct {
	sync.RWMutex
	data map[string]goja.Value
	data map[string]interface{}
}

func NewRuntimeJavascriptLocalCache() *RuntimeJavascriptLocalCache {
	return &RuntimeJavascriptLocalCache{
		data: make(map[string]goja.Value),
		data: make(map[string]interface{}),
	}
}

func (lc *RuntimeJavascriptLocalCache) Get(key string) (goja.Value, bool) {
func (lc *RuntimeJavascriptLocalCache) Get(key string) (interface{}, bool) {
	lc.RLock()
	value, found := lc.data[key]
	lc.RUnlock()
	return value, found
}

func (lc *RuntimeJavascriptLocalCache) Put(key string, value goja.Value) {
func (lc *RuntimeJavascriptLocalCache) Put(key string, value interface{}) {
	lc.Lock()
	lc.data[key] = value
	lc.Unlock()
+4 −4
Original line number Diff line number Diff line
@@ -7290,11 +7290,11 @@ func (n *runtimeJavascriptNakamaModule) localcacheGet(r *goja.Runtime) func(goja
		}

		value, found := n.localCache.Get(key)
		if found {
			return value
		if !found {
			return defVal
		}

		return defVal
		return r.ToValue(value)
	}
}

@@ -7310,7 +7310,7 @@ func (n *runtimeJavascriptNakamaModule) localcachePut(r *goja.Runtime) func(goja
			panic(r.NewTypeError("expects a non empty value"))
		}

		n.localCache.Put(key, value)
		n.localCache.Put(key, value.Export())

		return goja.Undefined()
	}