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

Function goClassFinalizerProxy

class_bridge.go:167–210  ·  view source on GitHub ↗

export goClassFinalizerProxy

(rt *C.JSRuntime, val C.JSValue)

Source from the content-addressed store, hash-verified

165
166//export goClassFinalizerProxy
167func goClassFinalizerProxy(rt *C.JSRuntime, val C.JSValue) {
168 goRt := getRuntimeFromJS(rt)
169 if goRt == nil {
170 return
171 }
172
173 classID := C.JS_GetClassID(val)
174 opaque := C.JS_GetOpaque(val, classID)
175 if opaque == nil {
176 return
177 }
178
179 objectID := int32(C.OpaqueToInt(opaque))
180
181 var targetCtx *Context
182 var handleID int32
183
184 if objectID < 0 {
185 identity, ok := goRt.takeClassObjectIdentity(objectID)
186 if !ok {
187 return
188 }
189 targetCtx = goRt.getOwnedContextByID(identity.contextID)
190 handleID = identity.handleID
191 } else {
192 return
193 }
194
195 if targetCtx == nil || targetCtx.handleStore == nil {
196 return
197 }
198
199 if goObj, exists := targetCtx.handleStore.Load(handleID); exists {
200 if finalizer, ok := goObj.(ClassFinalizer); ok {
201 func() {
202 defer func() {
203 recover()
204 }()
205 finalizer.Finalize()
206 }()
207 }
208 targetCtx.handleStore.Delete(handleID)
209 }
210}

Calls 6

getRuntimeFromJSFunction · 0.85
getOwnedContextByIDMethod · 0.80
LoadMethod · 0.80
FinalizeMethod · 0.65
DeleteMethod · 0.45