HasInstanceData checks if the value has associated Go object data This is the most reliable way to identify our class instances
()
| 1155 | // HasInstanceData checks if the value has associated Go object data |
| 1156 | // This is the most reliable way to identify our class instances |
| 1157 | func (v *Value) HasInstanceData() bool { |
| 1158 | if v == nil || !v.hasValidContext() || v.ctx.handleStore == nil || !v.IsObject() { |
| 1159 | return false |
| 1160 | } |
| 1161 | |
| 1162 | // Get class ID first |
| 1163 | classID := C.JS_GetClassID(v.ref) |
| 1164 | |
| 1165 | // Use JS_GetOpaque2 for type-safe check (like point.c methods) |
| 1166 | opaque := C.JS_GetOpaque2(v.ctx.ref, v.ref, classID) |
| 1167 | if opaque == nil { |
| 1168 | return false |
| 1169 | } |
| 1170 | |
| 1171 | ownerCtx, handleID, ok := resolveClassObjectFromOpaque(v.ctx, opaque) |
| 1172 | if !ok || ownerCtx == nil || ownerCtx.handleStore == nil { |
| 1173 | return false |
| 1174 | } |
| 1175 | _, exists := ownerCtx.handleStore.Load(handleID) |
| 1176 | return exists |
| 1177 | } |
| 1178 | |
| 1179 | // IsInstanceOfClassID checks if the value is an instance of a specific class ID |
| 1180 | // This provides type-safe class instance checking with double validation |