Store stores a value and returns int32 ID (safe for JS magic parameter)
(value interface{})
| 27 | |
| 28 | // Store stores a value and returns int32 ID (safe for JS magic parameter) |
| 29 | func (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 |
| 47 | func (hs *handleStore) Load(id int32) (interface{}, bool) { |
no outgoing calls