File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 "mokapi/engine/common"
66 "reflect"
77 "slices"
8+ "sync"
89
910 "github.com/dop251/goja"
1011)
@@ -117,6 +118,7 @@ func Export(v any) any {
117118type SharedValue struct {
118119 vm * goja.Runtime
119120 source goja.Value
121+ m sync.RWMutex
120122}
121123
122124func NewSharedValue (v goja.Value , vm * goja.Runtime ) * SharedValue {
@@ -131,6 +133,9 @@ func (p *SharedValue) Use(vm *goja.Runtime) *SharedValue {
131133}
132134
133135func (p * SharedValue ) Get (key string ) goja.Value {
136+ p .m .RLock ()
137+ defer p .m .RUnlock ()
138+
134139 switch v := p .source .(type ) {
135140 case * goja.Object :
136141 f := v .Get (key )
@@ -159,6 +164,9 @@ func (p *SharedValue) Has(key string) bool {
159164}
160165
161166func (p * SharedValue ) Set (key string , value goja.Value ) bool {
167+ p .m .Lock ()
168+ defer p .m .Unlock ()
169+
162170 switch v := p .source .(type ) {
163171 case * goja.Object :
164172 sv := useValue (value , p .vm )
@@ -172,6 +180,9 @@ func (p *SharedValue) Set(key string, value goja.Value) bool {
172180}
173181
174182func (p * SharedValue ) Delete (key string ) bool {
183+ p .m .Lock ()
184+ defer p .m .Unlock ()
185+
175186 switch v := p .source .(type ) {
176187 case * goja.Object :
177188 err := v .Delete (key )
@@ -185,6 +196,9 @@ func (p *SharedValue) Delete(key string) bool {
185196}
186197
187198func (p * SharedValue ) Keys () []string {
199+ p .m .RLock ()
200+ defer p .m .RUnlock ()
201+
188202 switch v := p .source .(type ) {
189203 case * goja.Object :
190204 return v .Keys ()
You can’t perform that action at this time.
0 commit comments