@gtkx/ffi 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,7 +38,26 @@ export declare function getNativeClass(glibTypeName: string): NativeClass | null
38
38
  * @returns The closest registered parent class, or null
39
39
  */
40
40
  export declare const findNativeClass: (glibTypeName: string, walkHierarchy?: boolean) => NativeClass | null;
41
+ /**
42
+ * Registers a native object in the identity registry.
43
+ *
44
+ * Ensures that the same native pointer always resolves to the same
45
+ * JavaScript wrapper, preserving object identity (`===`). The reference
46
+ * is weak, so objects can still be garbage collected.
47
+ *
48
+ * @param obj - The native object wrapper to register
49
+ */
41
50
  export declare function registerNativeObject(obj: NativeObject): void;
51
+ /**
52
+ * Finds an existing JavaScript wrapper for a native pointer.
53
+ *
54
+ * Looks up the identity registry to find a previously registered wrapper
55
+ * for the given native handle. Returns null if no wrapper exists or if
56
+ * the wrapper has been garbage collected.
57
+ *
58
+ * @param handle - The native handle to look up
59
+ * @returns The existing wrapper, or null if not found
60
+ */
42
61
  export declare function findNativeObject(handle: NativeHandle): NativeObject | null;
43
62
  type GetNativeObjectResult<T extends NativeHandle | null | undefined, TClass extends NativeClass | undefined> = T extends null | undefined ? null : TClass extends NativeClass<infer U> ? U : NativeObject;
44
63
  /**
package/dist/registry.js CHANGED
@@ -70,11 +70,30 @@ const objectRegistry = new Map();
70
70
  const cleanupObjectRegistry = new FinalizationRegistry((pointerId) => {
71
71
  objectRegistry.delete(pointerId);
72
72
  });
73
+ /**
74
+ * Registers a native object in the identity registry.
75
+ *
76
+ * Ensures that the same native pointer always resolves to the same
77
+ * JavaScript wrapper, preserving object identity (`===`). The reference
78
+ * is weak, so objects can still be garbage collected.
79
+ *
80
+ * @param obj - The native object wrapper to register
81
+ */
73
82
  export function registerNativeObject(obj) {
74
83
  const pointerId = getNativeId(obj.handle);
75
84
  objectRegistry.set(pointerId, new WeakRef(obj));
76
85
  cleanupObjectRegistry.register(obj, pointerId, obj);
77
86
  }
87
+ /**
88
+ * Finds an existing JavaScript wrapper for a native pointer.
89
+ *
90
+ * Looks up the identity registry to find a previously registered wrapper
91
+ * for the given native handle. Returns null if no wrapper exists or if
92
+ * the wrapper has been garbage collected.
93
+ *
94
+ * @param handle - The native handle to look up
95
+ * @returns The existing wrapper, or null if not found
96
+ */
78
97
  export function findNativeObject(handle) {
79
98
  const pointerId = getNativeId(handle);
80
99
  const ref = objectRegistry.get(pointerId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/ffi",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Generated TypeScript FFI bindings for GTKX",
5
5
  "keywords": [
6
6
  "gtkx",
@@ -51,10 +51,10 @@
51
51
  "dist"
52
52
  ],
53
53
  "dependencies": {
54
- "@gtkx/native": "0.18.0"
54
+ "@gtkx/native": "0.18.1"
55
55
  },
56
56
  "devDependencies": {
57
- "@gtkx/vitest": "0.18.0"
57
+ "@gtkx/vitest": "0.18.1"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "tsc -b && cp ../../README.md .",