MCPcopy Create free account
hub / github.com/buke/quickjs-go / Store

Method Store

handle.go:29–44  ·  view source on GitHub ↗

Store stores a value and returns int32 ID (safe for JS magic parameter)

(value interface{})

Source from the content-addressed store, hash-verified

27
28// Store stores a value and returns int32 ID (safe for JS magic parameter)
29func (hs *handleStore) Store(value interface{}) int32 {
30 if hs == nil {
31 return 0
32 }
33
34 id := hs.nextID.Add(1)
35
36 // check int32 overflow to prevent magic parameter issues
37 if id <= 0 || id == math.MaxInt32 {
38 panic("quickjs: HandleStore ID overflow, too many functions registered")
39 }
40
41 handle := cgo.NewHandle(value)
42 hs.handles.Store(id, handle)
43 return id
44}
45
46// Load loads value by ID
47func (hs *handleStore) Load(id int32) (interface{}, bool) {

Calls

no outgoing calls