GetGoObject retrieves Go object from JavaScript class instance This method extracts the opaque data stored by the constructor proxy
()
| 1197 | // GetGoObject retrieves Go object from JavaScript class instance |
| 1198 | // This method extracts the opaque data stored by the constructor proxy |
| 1199 | func (v *Value) GetGoObject() (interface{}, error) { |
| 1200 | if v == nil || v.ctx == nil { |
| 1201 | return nil, errors.New("value context is not available") |
| 1202 | } |
| 1203 | if v.ctx.runtime == nil || !v.ctx.runtime.ensureOwnerAccess() { |
| 1204 | return nil, errOwnerAccessDenied |
| 1205 | } |
| 1206 | if v.ctx.ref == nil || v.ctx.handleStore == nil { |
| 1207 | return nil, errors.New("value context is not available") |
| 1208 | } |
| 1209 | |
| 1210 | // First check if the value is an object |
| 1211 | if !v.IsObject() { |
| 1212 | return nil, errors.New("value is not an object") |
| 1213 | } |
| 1214 | |
| 1215 | // Get class ID to ensure we have a class instance |
| 1216 | classID := C.JS_GetClassID(v.ref) |
| 1217 | |
| 1218 | // Use JS_GetOpaque2 for type-safe retrieval with context validation |
| 1219 | // This corresponds to point.c: s = JS_GetOpaque2(ctx, this_val, js_point_class_id) |
| 1220 | opaque := C.JS_GetOpaque2(v.ctx.ref, v.ref, classID) |
| 1221 | if opaque == nil { |
| 1222 | return nil, errors.New("no instance data found") |
| 1223 | } |
| 1224 | |
| 1225 | ownerCtx, handleID, ok := resolveClassObjectFromOpaque(v.ctx, opaque) |
| 1226 | if !ok || ownerCtx == nil || ownerCtx.handleStore == nil { |
| 1227 | return nil, errors.New("instance data not found in handle store") |
| 1228 | } |
| 1229 | |
| 1230 | // Retrieve Go object from resolved HandleStore |
| 1231 | if obj, exists := ownerCtx.handleStore.Load(handleID); exists { |
| 1232 | return obj, nil |
| 1233 | } |
| 1234 | |
| 1235 | return nil, errors.New("instance data not found in handle store") |
| 1236 | } |
| 1237 | |
| 1238 | // ============================================================================= |
| 1239 | // SPECIALIZED CLASS TYPE CHECKING METHODS |