@gtkx/runtime 1.0.0-rc.4 → 1.1.0

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.
Files changed (156) hide show
  1. package/README.md +5 -5
  2. package/dist/application-class.d.ts +37 -0
  3. package/dist/application-class.d.ts.map +1 -0
  4. package/dist/application-class.js +78 -0
  5. package/dist/application-class.js.map +1 -0
  6. package/dist/arg.d.ts +2 -1
  7. package/dist/arg.d.ts.map +1 -1
  8. package/dist/arg.js +2 -1
  9. package/dist/arg.js.map +1 -1
  10. package/dist/bind.d.ts +11 -0
  11. package/dist/bind.d.ts.map +1 -1
  12. package/dist/bind.js +11 -0
  13. package/dist/bind.js.map +1 -1
  14. package/dist/callback.d.ts +4 -3
  15. package/dist/callback.d.ts.map +1 -1
  16. package/dist/callback.js +124 -29
  17. package/dist/callback.js.map +1 -1
  18. package/dist/closure.d.ts +26 -0
  19. package/dist/closure.d.ts.map +1 -0
  20. package/dist/closure.js +99 -0
  21. package/dist/closure.js.map +1 -0
  22. package/dist/default-application.d.ts +4 -0
  23. package/dist/default-application.d.ts.map +1 -0
  24. package/dist/default-application.js +17 -0
  25. package/dist/default-application.js.map +1 -0
  26. package/dist/descriptors.d.ts +98 -4
  27. package/dist/descriptors.d.ts.map +1 -1
  28. package/dist/descriptors.js +72 -6
  29. package/dist/descriptors.js.map +1 -1
  30. package/dist/error.d.ts +1 -0
  31. package/dist/error.d.ts.map +1 -1
  32. package/dist/error.js.map +1 -1
  33. package/dist/exit-hook.js +13 -0
  34. package/dist/exit-hook.js.map +1 -1
  35. package/dist/fn.d.ts +24 -2
  36. package/dist/fn.d.ts.map +1 -1
  37. package/dist/fn.js +67 -32
  38. package/dist/fn.js.map +1 -1
  39. package/dist/folded-lengths.d.ts +16 -0
  40. package/dist/folded-lengths.d.ts.map +1 -0
  41. package/dist/folded-lengths.js +38 -0
  42. package/dist/folded-lengths.js.map +1 -0
  43. package/dist/index.d.ts +14 -6
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +12 -4
  46. package/dist/index.js.map +1 -1
  47. package/dist/internal.d.ts +2 -0
  48. package/dist/internal.d.ts.map +1 -1
  49. package/dist/internal.js +2 -0
  50. package/dist/internal.js.map +1 -1
  51. package/dist/library.d.ts +3 -1
  52. package/dist/library.d.ts.map +1 -1
  53. package/dist/library.js +3 -1
  54. package/dist/library.js.map +1 -1
  55. package/dist/lifecycle.d.ts +58 -11
  56. package/dist/lifecycle.d.ts.map +1 -1
  57. package/dist/lifecycle.js +95 -22
  58. package/dist/lifecycle.js.map +1 -1
  59. package/dist/listeners.d.ts.map +1 -1
  60. package/dist/listeners.js +19 -5
  61. package/dist/listeners.js.map +1 -1
  62. package/dist/mixin.d.ts +3 -2
  63. package/dist/mixin.d.ts.map +1 -1
  64. package/dist/mixin.js +13 -1
  65. package/dist/mixin.js.map +1 -1
  66. package/dist/native-value.d.ts.map +1 -1
  67. package/dist/native-value.js +4 -3
  68. package/dist/native-value.js.map +1 -1
  69. package/dist/object.d.ts +40 -7
  70. package/dist/object.d.ts.map +1 -1
  71. package/dist/object.js +95 -26
  72. package/dist/object.js.map +1 -1
  73. package/dist/param-spec.d.ts +11 -0
  74. package/dist/param-spec.d.ts.map +1 -0
  75. package/dist/param-spec.js +147 -0
  76. package/dist/param-spec.js.map +1 -0
  77. package/dist/promisify.d.ts.map +1 -1
  78. package/dist/promisify.js +3 -2
  79. package/dist/promisify.js.map +1 -1
  80. package/dist/properties.d.ts +39 -7
  81. package/dist/properties.d.ts.map +1 -1
  82. package/dist/properties.js +310 -43
  83. package/dist/properties.js.map +1 -1
  84. package/dist/register-class.d.ts +147 -12
  85. package/dist/register-class.d.ts.map +1 -1
  86. package/dist/register-class.js +129 -83
  87. package/dist/register-class.js.map +1 -1
  88. package/dist/registry.d.ts +80 -21
  89. package/dist/registry.d.ts.map +1 -1
  90. package/dist/registry.js +86 -33
  91. package/dist/registry.js.map +1 -1
  92. package/dist/signal.d.ts +11 -4
  93. package/dist/signal.d.ts.map +1 -1
  94. package/dist/signal.js +85 -25
  95. package/dist/signal.js.map +1 -1
  96. package/dist/t.d.ts +2 -0
  97. package/dist/t.d.ts.map +1 -1
  98. package/dist/t.js +1 -0
  99. package/dist/t.js.map +1 -1
  100. package/dist/tuple.d.ts +6 -3
  101. package/dist/tuple.d.ts.map +1 -1
  102. package/dist/tuple.js +9 -7
  103. package/dist/tuple.js.map +1 -1
  104. package/dist/type.d.ts +2 -1
  105. package/dist/type.d.ts.map +1 -1
  106. package/dist/type.js +2 -0
  107. package/dist/type.js.map +1 -1
  108. package/dist/value.d.ts +10 -1
  109. package/dist/value.d.ts.map +1 -1
  110. package/dist/value.js +99 -24
  111. package/dist/value.js.map +1 -1
  112. package/dist/vfunc-call.d.ts +37 -0
  113. package/dist/vfunc-call.d.ts.map +1 -0
  114. package/dist/vfunc-call.js +172 -0
  115. package/dist/vfunc-call.js.map +1 -0
  116. package/dist/vfunc-seeds.d.ts +12 -0
  117. package/dist/vfunc-seeds.d.ts.map +1 -0
  118. package/dist/vfunc-seeds.js +19 -0
  119. package/dist/vfunc-seeds.js.map +1 -0
  120. package/dist/vfunc.d.ts +8 -0
  121. package/dist/vfunc.d.ts.map +1 -0
  122. package/dist/vfunc.js +29 -0
  123. package/dist/vfunc.js.map +1 -0
  124. package/package.json +14 -4
  125. package/src/application-class.ts +126 -0
  126. package/src/arg.ts +2 -1
  127. package/src/bind.ts +11 -0
  128. package/src/callback.ts +178 -34
  129. package/src/closure.ts +136 -0
  130. package/src/default-application.ts +21 -0
  131. package/src/descriptors.ts +150 -34
  132. package/src/error.ts +1 -0
  133. package/src/exit-hook.ts +18 -0
  134. package/src/fn.ts +107 -36
  135. package/src/folded-lengths.ts +64 -0
  136. package/src/index.ts +21 -6
  137. package/src/internal.ts +2 -0
  138. package/src/library.ts +3 -1
  139. package/src/lifecycle.ts +138 -25
  140. package/src/listeners.ts +25 -6
  141. package/src/mixin.ts +15 -2
  142. package/src/native-value.ts +5 -3
  143. package/src/object.ts +134 -35
  144. package/src/param-spec.ts +234 -0
  145. package/src/promisify.ts +4 -2
  146. package/src/properties.ts +473 -46
  147. package/src/register-class.ts +386 -114
  148. package/src/registry.ts +169 -49
  149. package/src/signal.ts +116 -42
  150. package/src/t.ts +3 -0
  151. package/src/tuple.ts +18 -12
  152. package/src/type.ts +3 -1
  153. package/src/value.ts +143 -23
  154. package/src/vfunc-call.ts +247 -0
  155. package/src/vfunc-seeds.ts +36 -0
  156. package/src/vfunc.ts +38 -0
@@ -1,36 +1,88 @@
1
- import type { AnyClass } from "@gtkx/utils";
2
1
  import { type ExternalObject, type Handle, type RegisterClassVfunc as NativeRegisterClassVfunc } from "@gtkx/native";
2
+ import { type AnyClass } from "@gtkx/utils";
3
3
  import type { Mixin } from "./mixin.js";
4
4
  import { type TypedClass } from "./type.js";
5
5
  /**
6
6
  * Static side of class `C` with its construct signature preserved but the member
7
- * named `K` (default `"new"`) removed.
7
+ * named `K` (default `"new"`) removed. The signature is kept abstract so an abstract
8
+ * `C` survives it: a subclass extends the result, and only the subclass's own
9
+ * declaration decides whether `new` reaches it.
8
10
  */
9
- type StaticBase<C, K extends PropertyKey = "new"> = Omit<C, K> & (C extends new (...args: infer A) => infer R ? new (...args: A) => R : never);
11
+ type StaticBase<C, K extends PropertyKey = "new"> = Omit<C, K> & (C extends abstract new (...args: infer A) => infer R ? abstract new (...args: A) => R : never);
10
12
  /** One overridable vtable slot: where it sits in the vtable struct and how it is marshalled. */
11
- type VfuncDescriptor<K extends "class" | "interface"> = {
12
- /** Whether the slot lives in a class struct or in an interface vtable. */
13
- kind: K;
13
+ type VfuncDescriptor = {
14
14
  /** GIR name of the type struct holding the slot, without its namespace, such as `WidgetClass`. */
15
15
  className: string;
16
16
  /** Name of the slot's field in that struct. */
17
17
  vfuncName: string;
18
18
  /** Byte offset of the slot within the struct. */
19
19
  byteOffset: number;
20
- /** Byte size of the struct, used to bounds-check `VfuncDescriptor.byteOffset`. */
21
- vtableSize: number;
20
+ /**
21
+ * Byte size of an interface's vtable struct, used to bounds-check `VfuncDescriptor.byteOffset`.
22
+ * A class struct is bounds-checked against the size `g_type_query` reports for it, so a slot in
23
+ * one carries no size of its own.
24
+ */
25
+ vtableSize?: number;
22
26
  /** Descriptor for each argument the slot receives, starting with the instance. */
23
27
  argDescriptors: NativeRegisterClassVfunc["argDescriptors"];
24
28
  /** Descriptor for the value the slot returns. */
25
29
  returnDescriptor: NativeRegisterClassVfunc["returnDescriptor"];
30
+ /**
31
+ * GIR marks the slot's return value as one the bindings do not surface, so a call through the
32
+ * slot drops it and an implementation of the slot reports success in its place, while
33
+ * `VfuncDescriptor.returnDescriptor` keeps the C type the slot is called against either way.
34
+ */
35
+ isReturnSkipped?: boolean;
36
+ /**
37
+ * The slot takes a trailing `GError**` that `VfuncDescriptor.argDescriptors` leaves out, the
38
+ * way GIR leaves it out of a callable's parameters. A call through the slot has to append it
39
+ * or it passes one argument fewer than the implementation reads.
40
+ */
41
+ canThrow?: boolean;
26
42
  };
27
43
  /**
28
44
  * The vtable slots a wrapper class or interface exposes, keyed by the JavaScript method name that
29
45
  * overrides each one.
30
46
  */
31
- type VfuncRegistry = Record<string, VfuncDescriptor<"class"> | VfuncDescriptor<"interface">>;
32
- declare function getClassType(cls: AnyClass): bigint;
33
- /** Returns the GType tag of the given wrapper instance. */
47
+ type VfuncRegistry = Record<string, VfuncDescriptor>;
48
+ /**
49
+ * How one property an interface declares reaches the vtable, given as the interface's own accessor
50
+ * members. A direction introspection does not route through a vtable slot is left out, and the
51
+ * property owns that direction's state itself.
52
+ */
53
+ type InterfaceProperty = {
54
+ /** Member reading the slot the property's value comes from, such as `getEnabled`. */
55
+ getter?: string;
56
+ /** Member writing the slot the property's value goes to, such as `setActionName`. */
57
+ setter?: string;
58
+ };
59
+ /**
60
+ * What an interface's vtable struct looks like, for the classes that adopt the interface.
61
+ * `g_type_query` reports no size for an interface, so each slot's generated metadata carries the
62
+ * struct's byte size to bounds-check the slot's offset; an interface introspection describes no
63
+ * vtable for simply contributes no slots.
64
+ */
65
+ type InterfaceLayout = {
66
+ /** The slots the struct declares, keyed by the JavaScript method name that fills each one. */
67
+ vfuncs?: VfuncRegistry;
68
+ /**
69
+ * The properties a vtable slot backs, keyed by canonical property name, so a class adopting the
70
+ * interface answers `g_object_get` and `g_object_set` with what the slot holds.
71
+ */
72
+ properties?: Record<string, InterfaceProperty>;
73
+ };
74
+ /**
75
+ * Returns the GType a class was registered under, or the invalid type when it carries none. The tag is
76
+ * read off the class's own prototype, so a subclass that never went through `registerClass` reports the
77
+ * invalid type rather than inheriting the one its parent was registered with.
78
+ */
79
+ declare function getClassType(cls: AnyClass | undefined): bigint;
80
+ /**
81
+ * Returns the GType the given instance's handle carries, or the invalid type when it has no handle.
82
+ * This is the object's own type rather than the type of the class it was wrapped as, and the two differ
83
+ * for an object GTK created itself, such as the row widget inside a `Gtk.ListView`, which GTKX wraps as
84
+ * the nearest registered ancestor.
85
+ */
34
86
  declare function getInstanceType(instance: object): bigint;
35
87
  declare function registerClassType(cls: AnyClass, type: bigint): void;
36
88
  /**
@@ -42,21 +94,24 @@ declare function registerClassType(cls: AnyClass, type: bigint): void;
42
94
  * overrides.
43
95
  */
44
96
  declare function registerWrapperClass(cls: AnyClass, type: bigint, vfuncs?: VfuncRegistry): void;
97
+ declare function markDerivedClass(cls: AnyClass): void;
98
+ declare function resolveWrapperType(instance: object): bigint;
45
99
  /**
46
100
  * Registers a GInterface, associating its GType with a mixin used to compose the
47
- * interface onto wrapper classes and an optional virtual function registry.
101
+ * interface onto wrapper classes and, when introspection describes its vtable, that layout.
48
102
  * @param cls Class carrying the interface's GType tag.
49
103
  * @param type GType of the interface.
50
104
  * @param mixin Mixin that applies the interface to a wrapper class.
51
- * @param vfuncs Vtable slots the interface exposes, so `registerClass` can bind the ones an
52
- * implementing class overrides.
105
+ * @param layout The interface's vtable struct, so `registerClass` can bind the slots an
106
+ * implementing class overrides and take over the ones it leaves alone.
53
107
  */
54
- declare function registerInterface(cls: AnyClass, type: bigint, mixin: Mixin, vfuncs?: VfuncRegistry): void;
108
+ declare function registerInterface(cls: AnyClass, type: bigint, mixin: Mixin, layout?: InterfaceLayout): void;
55
109
  /**
56
110
  * Wraps a native handle in a JS wrapper instance. With no class, resolves and
57
- * reuses the wrapper for the handle's runtime GType (composing interface mixins);
58
- * with an explicit class, creates a bare instance backed by the handle. Returns
59
- * null for a null or undefined handle.
111
+ * reuses the wrapper for the handle's runtime GType (composing interface mixins),
112
+ * and hands back an instance that already carries a handle unchanged; with an
113
+ * explicit class, creates a bare instance backed by the handle. Returns null for
114
+ * a null or undefined handle.
60
115
  * @param handle Native handle to wrap.
61
116
  * @param cls Wrapper class to instantiate, or omitted to resolve it from the runtime type.
62
117
  */
@@ -71,13 +126,17 @@ declare function wrapHandle(handle: ExternalObject<Handle> | null | undefined, c
71
126
  */
72
127
  declare function getWrapperClass(type: bigint): AnyClass;
73
128
  declare function resolveWrapperClass(type: bigint): AnyClass | null;
129
+ declare function getInterfaceMixin(type: bigint): Mixin | undefined;
130
+ declare function wrapObject(value: unknown): object | null;
131
+ declare function wrapCallScopedObject(value: unknown): object | null;
132
+ declare function instanceClassName(instance: object): string;
74
133
  /** Returns the native handle bound to a wrapper instance, throwing if none is set. */
75
134
  declare function getHandle(instance: object): ExternalObject<Handle>;
76
- /** Returns the native handle bound to an instance, or undefined when there is none or the instance is null. */
77
- declare function tryGetHandle(instance: object | null | undefined): ExternalObject<Handle> | undefined;
78
135
  /** Associates a native handle with a wrapper instance. */
79
136
  declare function setHandle(instance: object, handle: ExternalObject<Handle>): void;
137
+ declare function registerWrapper(handle: ExternalObject<Handle>, instance: object): void;
80
138
  declare function getVfuncRegistry(cls: object): VfuncRegistry | undefined;
81
139
  declare function getInterfaceVfuncRegistry(type: bigint): VfuncRegistry | undefined;
82
- export { getClassType, getInstanceType, registerClassType, registerWrapperClass, registerInterface, wrapHandle, getWrapperClass, resolveWrapperClass, getHandle, tryGetHandle, setHandle, getVfuncRegistry, getInterfaceVfuncRegistry, type StaticBase, type VfuncDescriptor, type VfuncRegistry, };
140
+ declare function getInterfaceProperties(type: bigint): Record<string, InterfaceProperty> | undefined;
141
+ export { getClassType, getInstanceType, markDerivedClass, registerClassType, registerWrapperClass, registerInterface, wrapHandle, getWrapperClass, resolveWrapperClass, getHandle, setHandle, getVfuncRegistry, getInterfaceMixin, getInterfaceProperties, getInterfaceVfuncRegistry, instanceClassName, registerWrapper, resolveWrapperType, wrapCallScopedObject, wrapObject, type InterfaceProperty, type StaticBase, type VfuncDescriptor, };
83
142
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACH,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,kBAAkB,IAAI,wBAAwB,EAEtD,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,KAAK,EAAiB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAgB,KAAK,UAAU,EAAiD,MAAM,WAAW,CAAC;AAEzG;;;GAGG;AACH,KAAK,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,GAAG,KAAK,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAC1D,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AAElF,gGAAgG;AAChG,KAAK,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,WAAW,IAAI;IACpD,0EAA0E;IAC1E,IAAI,EAAE,CAAC,CAAC;IACR,kGAAkG;IAClG,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAi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,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAG/E;AAMD,iBAAS,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAEhE;AAED,iBAAS,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE1E;AAED,iBAAS,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,SAAS,CAE3F;AAED,OAAO,EACH,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,eAAe,GACvB,CAAC"}
package/dist/registry.js CHANGED
@@ -1,21 +1,38 @@
1
1
  import { getType, getWrapper, setWrapper, } from "@gtkx/native";
2
+ import { walkClassChain } from "@gtkx/utils";
2
3
  import { TYPE_INVALID, typeInterfaces, typeIsA, typeName, typeParent } from "./type.js";
3
4
  const classRegistry = new Map();
4
5
  const interfaceMixinRegistry = new Map();
5
6
  const composedClassRegistry = new Map();
6
7
  const handleMap = new WeakMap();
7
8
  const vfuncRegistry = new WeakMap();
8
- const interfaceVfuncRegistry = new Map();
9
+ const interfaceLayoutRegistry = new Map();
10
+ const wrapperClasses = new WeakSet();
11
+ const derivedClasses = new WeakSet();
9
12
  function setClassType(cls, type) {
10
13
  cls.prototype.__type__ = type;
11
14
  }
15
+ /**
16
+ * Returns the GType a class was registered under, or the invalid type when it carries none. The tag is
17
+ * read off the class's own prototype, so a subclass that never went through `registerClass` reports the
18
+ * invalid type rather than inheriting the one its parent was registered with.
19
+ */
12
20
  function getClassType(cls) {
13
- const proto = cls.prototype;
14
- return Object.hasOwn(proto, "__type__") ? proto.__type__ : TYPE_INVALID;
21
+ const proto = cls?.prototype;
22
+ if (proto === undefined || !Object.hasOwn(proto, "__type__")) {
23
+ return TYPE_INVALID;
24
+ }
25
+ return proto.__type__;
15
26
  }
16
- /** Returns the GType tag of the given wrapper instance. */
27
+ /**
28
+ * Returns the GType the given instance's handle carries, or the invalid type when it has no handle.
29
+ * This is the object's own type rather than the type of the class it was wrapped as, and the two differ
30
+ * for an object GTK created itself, such as the row widget inside a `Gtk.ListView`, which GTKX wraps as
31
+ * the nearest registered ancestor.
32
+ */
17
33
  function getInstanceType(instance) {
18
- return getClassType(instance.constructor);
34
+ const handle = handleMap.get(instance);
35
+ return handle === undefined ? TYPE_INVALID : getType(handle);
19
36
  }
20
37
  function registerClassType(cls, type) {
21
38
  if (type === TYPE_INVALID) {
@@ -34,27 +51,46 @@ function registerClassType(cls, type) {
34
51
  */
35
52
  function registerWrapperClass(cls, type, vfuncs) {
36
53
  registerClassType(cls, type);
54
+ if (type !== TYPE_INVALID) {
55
+ wrapperClasses.add(cls);
56
+ }
37
57
  if (vfuncs) {
38
58
  registerVfuncRegistry(cls, vfuncs);
39
59
  }
40
60
  }
61
+ function markDerivedClass(cls) {
62
+ derivedClasses.add(cls);
63
+ }
64
+ function resolveAncestorType(ancestor) {
65
+ if (derivedClasses.has(ancestor) || !wrapperClasses.has(ancestor)) {
66
+ return undefined;
67
+ }
68
+ return getClassType(ancestor);
69
+ }
70
+ function resolveWrapperType(instance) {
71
+ const cls = instance.constructor;
72
+ if (cls === undefined) {
73
+ return TYPE_INVALID;
74
+ }
75
+ return walkClassChain(cls, (ancestor) => resolveAncestorType(ancestor)) ?? TYPE_INVALID;
76
+ }
41
77
  /**
42
78
  * Registers a GInterface, associating its GType with a mixin used to compose the
43
- * interface onto wrapper classes and an optional virtual function registry.
79
+ * interface onto wrapper classes and, when introspection describes its vtable, that layout.
44
80
  * @param cls Class carrying the interface's GType tag.
45
81
  * @param type GType of the interface.
46
82
  * @param mixin Mixin that applies the interface to a wrapper class.
47
- * @param vfuncs Vtable slots the interface exposes, so `registerClass` can bind the ones an
48
- * implementing class overrides.
83
+ * @param layout The interface's vtable struct, so `registerClass` can bind the slots an
84
+ * implementing class overrides and take over the ones it leaves alone.
49
85
  */
50
- function registerInterface(cls, type, mixin, vfuncs) {
86
+ function registerInterface(cls, type, mixin, layout) {
51
87
  if (type === TYPE_INVALID) {
52
88
  return;
53
89
  }
54
90
  setClassType(cls, type);
55
91
  interfaceMixinRegistry.set(type, mixin);
56
- if (vfuncs) {
57
- registerInterfaceVfuncRegistry(type, vfuncs);
92
+ if (layout) {
93
+ interfaceLayoutRegistry.set(type, layout);
58
94
  }
59
95
  }
60
96
  function wrapHandle(handle, cls) {
@@ -90,11 +126,14 @@ function resolveWrapperClass(type) {
90
126
  }
91
127
  return null;
92
128
  }
129
+ function getInterfaceMixin(type) {
130
+ return interfaceMixinRegistry.get(type);
131
+ }
93
132
  function applyInterfaceMixin(cls, type, baseType, applied) {
94
133
  if (applied.has(type) || typeIsA(baseType, type)) {
95
134
  return cls;
96
135
  }
97
- const mixin = interfaceMixinRegistry.get(type);
136
+ const mixin = getInterfaceMixin(type);
98
137
  if (mixin === undefined) {
99
138
  return cls;
100
139
  }
@@ -128,14 +167,20 @@ function resolveComposedClass(runtimeType) {
128
167
  return base;
129
168
  }
130
169
  setClassType(composed, runtimeType);
170
+ wrapperClasses.add(composed);
131
171
  composedClassRegistry.set(runtimeType, composed);
132
172
  return composed;
133
173
  }
134
- function getOrCreateWrapper(handle) {
135
- const existing = getWrapper(handle);
136
- if (existing) {
137
- return existing;
138
- }
174
+ function wrapObject(value) {
175
+ return value == null ? null : getOrCreateWrapper(value);
176
+ }
177
+ function wrapCallScopedObject(value) {
178
+ return value == null ? null : wrapperFor(value, bindCallScopedWrapper);
179
+ }
180
+ function existingWrapperFor(handle) {
181
+ return handleMap.has(handle) ? handle : getWrapper(handle);
182
+ }
183
+ function createWrapper(handle) {
139
184
  const runtimeType = getType(handle);
140
185
  if (runtimeType === TYPE_INVALID) {
141
186
  throw new Error("Cannot resolve runtime GLib type from handle");
@@ -144,27 +189,38 @@ function getOrCreateWrapper(handle) {
144
189
  if (!cls) {
145
190
  throw new Error(`Expected registered GLib type, got type ${String(runtimeType)}`);
146
191
  }
147
- const instance = Object.create(cls.prototype);
148
- registerWrapper(handle, instance);
192
+ return Object.create(cls.prototype);
193
+ }
194
+ function wrapperFor(handle, bind) {
195
+ const existing = existingWrapperFor(handle);
196
+ if (existing) {
197
+ return existing;
198
+ }
199
+ const instance = createWrapper(handle);
200
+ bind(handle, instance);
149
201
  return instance;
150
202
  }
203
+ function getOrCreateWrapper(handle) {
204
+ return wrapperFor(handle, registerWrapper);
205
+ }
206
+ function instanceClassName(instance) {
207
+ return instance.constructor?.name ?? "object";
208
+ }
151
209
  /** Returns the native handle bound to a wrapper instance, throwing if none is set. */
152
210
  function getHandle(instance) {
153
211
  const handle = handleMap.get(instance);
154
212
  if (handle === undefined) {
155
- const name = instance.constructor?.name ?? "object";
156
- throw new Error(`No native handle associated with ${name}`);
213
+ throw new Error(`No native handle associated with ${instanceClassName(instance)}`);
157
214
  }
158
215
  return handle;
159
216
  }
160
- /** Returns the native handle bound to an instance, or undefined when there is none or the instance is null. */
161
- function tryGetHandle(instance) {
162
- return instance == null ? undefined : handleMap.get(instance);
163
- }
164
217
  /** Associates a native handle with a wrapper instance. */
165
218
  function setHandle(instance, handle) {
166
219
  handleMap.set(instance, handle);
167
220
  }
221
+ function bindCallScopedWrapper(handle, instance) {
222
+ setHandle(instance, handle);
223
+ }
168
224
  function registerWrapper(handle, instance) {
169
225
  setHandle(instance, handle);
170
226
  setWrapper(handle, instance);
@@ -175,14 +231,11 @@ function registerVfuncRegistry(cls, registry) {
175
231
  function getVfuncRegistry(cls) {
176
232
  return vfuncRegistry.get(cls);
177
233
  }
178
- function registerInterfaceVfuncRegistry(type, registry) {
179
- if (type === TYPE_INVALID) {
180
- return;
181
- }
182
- interfaceVfuncRegistry.set(type, registry);
183
- }
184
234
  function getInterfaceVfuncRegistry(type) {
185
- return interfaceVfuncRegistry.get(type);
235
+ return interfaceLayoutRegistry.get(type)?.vfuncs;
236
+ }
237
+ function getInterfaceProperties(type) {
238
+ return interfaceLayoutRegistry.get(type)?.properties;
186
239
  }
187
- export { getClassType, getInstanceType, registerClassType, registerWrapperClass, registerInterface, wrapHandle, getWrapperClass, resolveWrapperClass, getHandle, tryGetHandle, setHandle, getVfuncRegistry, getInterfaceVfuncRegistry, };
240
+ export { getClassType, getInstanceType, markDerivedClass, registerClassType, registerWrapperClass, registerInterface, wrapHandle, getWrapperClass, resolveWrapperClass, getHandle, setHandle, getVfuncRegistry, getInterfaceMixin, getInterfaceProperties, getInterfaceVfuncRegistry, instanceClassName, registerWrapper, resolveWrapperType, wrapCallScopedObject, wrapObject, };
188
241
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAEH,OAAO,EACP,UAAU,EAGV,UAAU,GACb,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAmB,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAiCzG,MAAM,aAAa,GAA0B,IAAI,GAAG,EAAE,CAAC;AACvD,MAAM,sBAAsB,GAAuB,IAAI,GAAG,EAAE,CAAC;AAC7D,MAAM,qBAAqB,GAA0B,IAAI,GAAG,EAAE,CAAC;AAC/D,MAAM,SAAS,GAA4C,IAAI,OAAO,EAAE,CAAC;AACzE,MAAM,aAAa,GAAmC,IAAI,OAAO,EAAE,CAAC;AACpE,MAAM,sBAAsB,GAA+B,IAAI,GAAG,EAAE,CAAC;AAErE,SAAS,YAAY,CAAC,GAAa,EAAE,IAAY;IAC5C,GAAG,CAAC,SAAwD,CAAC,QAAQ,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AAC,QAAmC;IACrD,OAAO,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAClE,CAAC;AAED,0DAA0D;AAC1D,SAAS,SAAS,CAAC,QAAgB,EAAE,MAA8B;IAC/D,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,eAAe,CAAC,MAA8B,EAAE,QAAgB;IACrE,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC5B,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,qBAAqB,CAAC,GAAW,EAAE,QAAuB;IAC/D,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAW;IACjC,OAAO,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,8BAA8B,CAAC,IAAY,EAAE,QAAuB;IACzE,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;QACxB,OAAO;IACX,CAAC;IAED,sBAAsB,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,yBAAyB,CAAC,IAAY;IAC3C,OAAO,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,OAAO,EACH,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,yBAAyB,GAI5B,CAAC","sourcesContent":["import type { AnyClass } from \"@gtkx/utils\";\nimport {\n type ExternalObject,\n getType,\n getWrapper,\n type Handle,\n type RegisterClassVfunc as NativeRegisterClassVfunc,\n setWrapper,\n} from \"@gtkx/native\";\nimport type { Mixin, MixinReceiver } from \"./mixin.js\";\nimport { TYPE_INVALID, type TypedClass, typeInterfaces, typeIsA, typeName, typeParent } from \"./type.js\";\n\n/**\n * Static side of class `C` with its construct signature preserved but the member\n * named `K` (default `\"new\"`) removed.\n */\ntype StaticBase<C, K extends PropertyKey = \"new\"> = Omit<C, K> &\n (C extends new (...args: infer A) => infer R ? new (...args: A) => R : never);\n\n/** One overridable vtable slot: where it sits in the vtable struct and how it is marshalled. */\ntype VfuncDescriptor<K extends \"class\" | \"interface\"> = {\n /** Whether the slot lives in a class struct or in an interface vtable. */\n kind: K;\n /** GIR name of the type struct holding the slot, without its namespace, such as `WidgetClass`. */\n className: string;\n /** Name of the slot's field in that struct. */\n vfuncName: string;\n /** Byte offset of the slot within the struct. */\n byteOffset: number;\n /** Byte size of the struct, used to bounds-check `VfuncDescriptor.byteOffset`. */\n vtableSize: number;\n /** Descriptor for each argument the slot receives, starting with the instance. */\n argDescriptors: NativeRegisterClassVfunc[\"argDescriptors\"];\n /** Descriptor for the value the slot returns. */\n returnDescriptor: NativeRegisterClassVfunc[\"returnDescriptor\"];\n};\n\n/**\n * The vtable slots a wrapper class or interface exposes, keyed by the JavaScript method name that\n * overrides each one.\n */\ntype VfuncRegistry = Record<string, VfuncDescriptor<\"class\"> | VfuncDescriptor<\"interface\">>;\n\nconst classRegistry: Map<bigint, AnyClass> = new Map();\nconst interfaceMixinRegistry: Map<bigint, Mixin> = new Map();\nconst composedClassRegistry: Map<bigint, AnyClass> = new Map();\nconst handleMap: WeakMap<object, ExternalObject<Handle>> = new WeakMap();\nconst vfuncRegistry: WeakMap<object, VfuncRegistry> = new WeakMap();\nconst interfaceVfuncRegistry: Map<bigint, VfuncRegistry> = new Map();\n\nfunction setClassType(cls: AnyClass, type: bigint): void {\n (cls.prototype as { [K in keyof TypedClass]: TypedClass[K] }).__type__ = type;\n}\n\nfunction getClassType(cls: AnyClass): bigint {\n const proto: object = cls.prototype;\n\n return Object.hasOwn(proto, \"__type__\") ? (proto as TypedClass).__type__ : TYPE_INVALID;\n}\n\n/** Returns the GType tag of the given wrapper instance. */\nfunction getInstanceType(instance: object): bigint {\n return getClassType(instance.constructor as AnyClass);\n}\n\nfunction registerClassType(cls: AnyClass, type: bigint): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n classRegistry.set(type, cls);\n setClassType(cls, type);\n}\n\n/**\n * Registers a wrapper class as the JS representation of a GType, optionally\n * installing a registry of virtual functions.\n * @param cls Wrapper class to associate with the type.\n * @param type GType the class wraps.\n * @param vfuncs Vtable slots the class exposes, so `registerClass` can bind the ones a subclass\n * overrides.\n */\nfunction registerWrapperClass(cls: AnyClass, type: bigint, vfuncs?: VfuncRegistry): void {\n registerClassType(cls, type);\n\n if (vfuncs) {\n registerVfuncRegistry(cls, vfuncs);\n }\n}\n\n/**\n * Registers a GInterface, associating its GType with a mixin used to compose the\n * interface onto wrapper classes and an optional virtual function registry.\n * @param cls Class carrying the interface's GType tag.\n * @param type GType of the interface.\n * @param mixin Mixin that applies the interface to a wrapper class.\n * @param vfuncs Vtable slots the interface exposes, so `registerClass` can bind the ones an\n * implementing class overrides.\n */\nfunction registerInterface(cls: AnyClass, type: bigint, mixin: Mixin, vfuncs?: VfuncRegistry): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n setClassType(cls, type);\n interfaceMixinRegistry.set(type, mixin);\n\n if (vfuncs) {\n registerInterfaceVfuncRegistry(type, vfuncs);\n }\n}\n\n/**\n * Wraps a native handle in a JS wrapper instance. With no class, resolves and\n * reuses the wrapper for the handle's runtime GType (composing interface mixins);\n * with an explicit class, creates a bare instance backed by the handle. Returns\n * null for a null or undefined handle.\n * @param handle Native handle to wrap.\n * @param cls Wrapper class to instantiate, or omitted to resolve it from the runtime type.\n */\nfunction wrapHandle(handle: null | undefined, cls?: AnyClass): null;\nfunction wrapHandle<T extends object>(handle: ExternalObject<Handle>, cls: AnyClass<T>): T;\n\nfunction wrapHandle<T extends object>(\n handle: ExternalObject<Handle> | null | undefined,\n cls: AnyClass<T>,\n): T | null;\n\nfunction wrapHandle(handle: ExternalObject<Handle>, cls?: AnyClass): TypedClass;\nfunction wrapHandle(handle: ExternalObject<Handle> | null | undefined, cls?: AnyClass): TypedClass | null;\n\nfunction wrapHandle(handle: ExternalObject<Handle> | null | undefined, cls?: AnyClass): object | null {\n if (handle === null || handle === undefined) {\n return null;\n }\n\n if (cls === undefined) {\n return getOrCreateWrapper(handle);\n }\n\n const instance: object = Object.create(cls.prototype) as object;\n setHandle(instance, handle);\n\n return instance;\n}\n\n/**\n * Returns the wrapper class registered for a GType, walking up to ancestor types,\n * and throws if none is registered.\n */\nfunction getWrapperClass(type: bigint): AnyClass {\n const cls = resolveWrapperClass(type);\n\n if (!cls) {\n throw new Error(`No registered wrapper class for type '${typeName(type) ?? String(type)}'`);\n }\n\n return cls;\n}\n\nfunction resolveWrapperClass(type: bigint): AnyClass | null {\n let currentType = type;\n\n while (currentType !== TYPE_INVALID) {\n const cls = classRegistry.get(currentType);\n\n if (cls) {\n return cls;\n }\n\n currentType = typeParent(currentType);\n }\n\n return null;\n}\n\nfunction applyInterfaceMixin(cls: AnyClass, type: bigint, baseType: bigint, applied: Set<bigint>): AnyClass {\n if (applied.has(type) || typeIsA(baseType, type)) {\n return cls;\n }\n\n const mixin = interfaceMixinRegistry.get(type);\n\n if (mixin === undefined) {\n return cls;\n }\n\n applied.add(type);\n\n return mixin(cls as AnyClass<MixinReceiver>);\n}\n\nfunction createComposedClass(base: AnyClass, runtimeType: bigint): AnyClass {\n const baseType = getClassType(base);\n const applied: Set<bigint> = new Set();\n let cls: AnyClass = base;\n\n for (const type of typeInterfaces(runtimeType)) {\n cls = applyInterfaceMixin(cls, type, baseType, applied);\n }\n\n return applied.size === 0 ? base : cls;\n}\n\nfunction resolveComposedClass(runtimeType: bigint): AnyClass | null {\n const exact = classRegistry.get(runtimeType);\n\n if (exact) {\n return exact;\n }\n\n const cached = composedClassRegistry.get(runtimeType);\n\n if (cached) {\n return cached;\n }\n\n const base = resolveWrapperClass(runtimeType);\n\n if (base === null) {\n return null;\n }\n\n const composed = createComposedClass(base, runtimeType);\n\n if (composed === base) {\n return base;\n }\n\n setClassType(composed, runtimeType);\n composedClassRegistry.set(runtimeType, composed);\n\n return composed;\n}\n\nfunction getOrCreateWrapper(handle: ExternalObject<Handle>): object {\n const existing = getWrapper(handle);\n\n if (existing) {\n return existing;\n }\n\n const runtimeType: bigint = getType(handle);\n\n if (runtimeType === TYPE_INVALID) {\n throw new Error(\"Cannot resolve runtime GLib type from handle\");\n }\n\n const cls = resolveComposedClass(runtimeType);\n\n if (!cls) {\n throw new Error(`Expected registered GLib type, got type ${String(runtimeType)}`);\n }\n\n const instance: object = Object.create(cls.prototype) as object;\n registerWrapper(handle, instance);\n\n return instance;\n}\n\n/** Returns the native handle bound to a wrapper instance, throwing if none is set. */\nfunction getHandle(instance: object): ExternalObject<Handle> {\n const handle = handleMap.get(instance);\n\n if (handle === undefined) {\n const name = (instance as { constructor?: { name?: string } }).constructor?.name ?? \"object\";\n throw new Error(`No native handle associated with ${name}`);\n }\n\n return handle;\n}\n\n/** Returns the native handle bound to an instance, or undefined when there is none or the instance is null. */\nfunction tryGetHandle(instance: object | null | undefined): ExternalObject<Handle> | undefined {\n return instance == null ? undefined : handleMap.get(instance);\n}\n\n/** Associates a native handle with a wrapper instance. */\nfunction setHandle(instance: object, handle: ExternalObject<Handle>): void {\n handleMap.set(instance, handle);\n}\n\nfunction registerWrapper(handle: ExternalObject<Handle>, instance: object): void {\n setHandle(instance, handle);\n setWrapper(handle, instance);\n}\n\nfunction registerVfuncRegistry(cls: object, registry: VfuncRegistry): void {\n vfuncRegistry.set(cls, registry);\n}\n\nfunction getVfuncRegistry(cls: object): VfuncRegistry | undefined {\n return vfuncRegistry.get(cls);\n}\n\nfunction registerInterfaceVfuncRegistry(type: bigint, registry: VfuncRegistry): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n interfaceVfuncRegistry.set(type, registry);\n}\n\nfunction getInterfaceVfuncRegistry(type: bigint): VfuncRegistry | undefined {\n return interfaceVfuncRegistry.get(type);\n}\n\nexport {\n getClassType,\n getInstanceType,\n registerClassType,\n registerWrapperClass,\n registerInterface,\n wrapHandle,\n getWrapperClass,\n resolveWrapperClass,\n getHandle,\n tryGetHandle,\n setHandle,\n getVfuncRegistry,\n getInterfaceVfuncRegistry,\n type StaticBase,\n type VfuncDescriptor,\n type VfuncRegistry,\n};\n"]}
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,OAAO,EACP,UAAU,EAGV,UAAU,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAiB,cAAc,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAmB,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AA8EzG,MAAM,aAAa,GAA0B,IAAI,GAAG,EAAE,CAAC;AACvD,MAAM,sBAAsB,GAAuB,IAAI,GAAG,EAAE,CAAC;AAC7D,MAAM,qBAAqB,GAA0B,IAAI,GAAG,EAAE,CAAC;AAC/D,MAAM,SAAS,GAA4C,IAAI,OAAO,EAAE,CAAC;AACzE,MAAM,aAAa,GAAmC,IAAI,OAAO,EAAE,CAAC;AACpE,MAAM,uBAAuB,GAAiC,IAAI,GAAG,EAAE,CAAC;AACxE,MAAM,cAAc,GAAsB,IAAI,OAAO,EAAE,CAAC;AACxD,MAAM,cAAc,GAAsB,IAAI,OAAO,EAAE,CAAC;AAExD,SAAS,YAAY,CAAC,GAAa,EAAE,IAAY;IAC5C,GAAG,CAAC,SAAwD,CAAC,QAAQ,GAAG,IAAI,CAAC;AAClF,CAAC;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,GAAyB;IAC3C,MAAM,KAAK,GAAuB,GAAG,EAAE,SAAS,CAAC;IAEjD,IAAI,KAAK,KA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,EACZ,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,GAIb,CAAC","sourcesContent":["import {\n type ExternalObject,\n getType,\n getWrapper,\n type Handle,\n type RegisterClassVfunc as NativeRegisterClassVfunc,\n setWrapper,\n} from \"@gtkx/native\";\nimport { type AnyClass, walkClassChain } from \"@gtkx/utils\";\nimport type { Mixin, MixinReceiver } from \"./mixin.js\";\nimport { TYPE_INVALID, type TypedClass, typeInterfaces, typeIsA, typeName, typeParent } from \"./type.js\";\n\n/**\n * Static side of class `C` with its construct signature preserved but the member\n * named `K` (default `\"new\"`) removed. The signature is kept abstract so an abstract\n * `C` survives it: a subclass extends the result, and only the subclass's own\n * declaration decides whether `new` reaches it.\n */\ntype StaticBase<C, K extends PropertyKey = \"new\"> = Omit<C, K> &\n (C extends abstract new (...args: infer A) => infer R ? abstract new (...args: A) => R : never);\n\n/** One overridable vtable slot: where it sits in the vtable struct and how it is marshalled. */\ntype VfuncDescriptor = {\n /** GIR name of the type struct holding the slot, without its namespace, such as `WidgetClass`. */\n className: string;\n /** Name of the slot's field in that struct. */\n vfuncName: string;\n /** Byte offset of the slot within the struct. */\n byteOffset: number;\n /**\n * Byte size of an interface's vtable struct, used to bounds-check `VfuncDescriptor.byteOffset`.\n * A class struct is bounds-checked against the size `g_type_query` reports for it, so a slot in\n * one carries no size of its own.\n */\n vtableSize?: number;\n /** Descriptor for each argument the slot receives, starting with the instance. */\n argDescriptors: NativeRegisterClassVfunc[\"argDescriptors\"];\n /** Descriptor for the value the slot returns. */\n returnDescriptor: NativeRegisterClassVfunc[\"returnDescriptor\"];\n /**\n * GIR marks the slot's return value as one the bindings do not surface, so a call through the\n * slot drops it and an implementation of the slot reports success in its place, while\n * `VfuncDescriptor.returnDescriptor` keeps the C type the slot is called against either way.\n */\n isReturnSkipped?: boolean;\n /**\n * The slot takes a trailing `GError**` that `VfuncDescriptor.argDescriptors` leaves out, the\n * way GIR leaves it out of a callable's parameters. A call through the slot has to append it\n * or it passes one argument fewer than the implementation reads.\n */\n canThrow?: boolean;\n};\n\n/**\n * The vtable slots a wrapper class or interface exposes, keyed by the JavaScript method name that\n * overrides each one.\n */\ntype VfuncRegistry = Record<string, VfuncDescriptor>;\ntype WrapperBinding = (handle: ExternalObject<Handle>, instance: object) => void;\n\n/**\n * How one property an interface declares reaches the vtable, given as the interface's own accessor\n * members. A direction introspection does not route through a vtable slot is left out, and the\n * property owns that direction's state itself.\n */\ntype InterfaceProperty = {\n /** Member reading the slot the property's value comes from, such as `getEnabled`. */\n getter?: string;\n /** Member writing the slot the property's value goes to, such as `setActionName`. */\n setter?: string;\n};\n\n/**\n * What an interface's vtable struct looks like, for the classes that adopt the interface.\n * `g_type_query` reports no size for an interface, so each slot's generated metadata carries the\n * struct's byte size to bounds-check the slot's offset; an interface introspection describes no\n * vtable for simply contributes no slots.\n */\ntype InterfaceLayout = {\n /** The slots the struct declares, keyed by the JavaScript method name that fills each one. */\n vfuncs?: VfuncRegistry;\n /**\n * The properties a vtable slot backs, keyed by canonical property name, so a class adopting the\n * interface answers `g_object_get` and `g_object_set` with what the slot holds.\n */\n properties?: Record<string, InterfaceProperty>;\n};\n\nconst classRegistry: Map<bigint, AnyClass> = new Map();\nconst interfaceMixinRegistry: Map<bigint, Mixin> = new Map();\nconst composedClassRegistry: Map<bigint, AnyClass> = new Map();\nconst handleMap: WeakMap<object, ExternalObject<Handle>> = new WeakMap();\nconst vfuncRegistry: WeakMap<object, VfuncRegistry> = new WeakMap();\nconst interfaceLayoutRegistry: Map<bigint, InterfaceLayout> = new Map();\nconst wrapperClasses: WeakSet<AnyClass> = new WeakSet();\nconst derivedClasses: WeakSet<AnyClass> = new WeakSet();\n\nfunction setClassType(cls: AnyClass, type: bigint): void {\n (cls.prototype as { [K in keyof TypedClass]: TypedClass[K] }).__type__ = type;\n}\n\n/**\n * Returns the GType a class was registered under, or the invalid type when it carries none. The tag is\n * read off the class's own prototype, so a subclass that never went through `registerClass` reports the\n * invalid type rather than inheriting the one its parent was registered with.\n */\nfunction getClassType(cls: AnyClass | undefined): bigint {\n const proto: object | undefined = cls?.prototype;\n\n if (proto === undefined || !Object.hasOwn(proto, \"__type__\")) {\n return TYPE_INVALID;\n }\n\n return (proto as TypedClass).__type__;\n}\n\n/**\n * Returns the GType the given instance's handle carries, or the invalid type when it has no handle.\n * This is the object's own type rather than the type of the class it was wrapped as, and the two differ\n * for an object GTK created itself, such as the row widget inside a `Gtk.ListView`, which GTKX wraps as\n * the nearest registered ancestor.\n */\nfunction getInstanceType(instance: object): bigint {\n const handle = handleMap.get(instance);\n\n return handle === undefined ? TYPE_INVALID : getType(handle);\n}\n\nfunction registerClassType(cls: AnyClass, type: bigint): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n classRegistry.set(type, cls);\n setClassType(cls, type);\n}\n\n/**\n * Registers a wrapper class as the JS representation of a GType, optionally\n * installing a registry of virtual functions.\n * @param cls Wrapper class to associate with the type.\n * @param type GType the class wraps.\n * @param vfuncs Vtable slots the class exposes, so `registerClass` can bind the ones a subclass\n * overrides.\n */\nfunction registerWrapperClass(cls: AnyClass, type: bigint, vfuncs?: VfuncRegistry): void {\n registerClassType(cls, type);\n\n if (type !== TYPE_INVALID) {\n wrapperClasses.add(cls);\n }\n\n if (vfuncs) {\n registerVfuncRegistry(cls, vfuncs);\n }\n}\n\nfunction markDerivedClass(cls: AnyClass): void {\n derivedClasses.add(cls);\n}\n\nfunction resolveAncestorType(ancestor: AnyClass): bigint | undefined {\n if (derivedClasses.has(ancestor) || !wrapperClasses.has(ancestor)) {\n return undefined;\n }\n\n return getClassType(ancestor);\n}\n\nfunction resolveWrapperType(instance: object): bigint {\n const cls = instance.constructor as AnyClass | undefined;\n\n if (cls === undefined) {\n return TYPE_INVALID;\n }\n\n return walkClassChain(cls, (ancestor) => resolveAncestorType(ancestor)) ?? TYPE_INVALID;\n}\n\n/**\n * Registers a GInterface, associating its GType with a mixin used to compose the\n * interface onto wrapper classes and, when introspection describes its vtable, that layout.\n * @param cls Class carrying the interface's GType tag.\n * @param type GType of the interface.\n * @param mixin Mixin that applies the interface to a wrapper class.\n * @param layout The interface's vtable struct, so `registerClass` can bind the slots an\n * implementing class overrides and take over the ones it leaves alone.\n */\nfunction registerInterface(cls: AnyClass, type: bigint, mixin: Mixin, layout?: InterfaceLayout): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n setClassType(cls, type);\n interfaceMixinRegistry.set(type, mixin);\n\n if (layout) {\n interfaceLayoutRegistry.set(type, layout);\n }\n}\n\n/**\n * Wraps a native handle in a JS wrapper instance. With no class, resolves and\n * reuses the wrapper for the handle's runtime GType (composing interface mixins),\n * and hands back an instance that already carries a handle unchanged; with an\n * explicit class, creates a bare instance backed by the handle. Returns null for\n * a null or undefined handle.\n * @param handle Native handle to wrap.\n * @param cls Wrapper class to instantiate, or omitted to resolve it from the runtime type.\n */\nfunction wrapHandle(handle: null | undefined, cls?: AnyClass): null;\nfunction wrapHandle<T extends object>(handle: ExternalObject<Handle>, cls: AnyClass<T>): T;\n\nfunction wrapHandle<T extends object>(\n handle: ExternalObject<Handle> | null | undefined,\n cls: AnyClass<T>,\n): T | null;\n\nfunction wrapHandle(handle: ExternalObject<Handle>, cls?: AnyClass): TypedClass;\nfunction wrapHandle(handle: ExternalObject<Handle> | null | undefined, cls?: AnyClass): TypedClass | null;\n\nfunction wrapHandle(handle: ExternalObject<Handle> | null | undefined, cls?: AnyClass): object | null {\n if (handle === null || handle === undefined) {\n return null;\n }\n\n if (cls === undefined) {\n return getOrCreateWrapper(handle);\n }\n\n const instance: object = Object.create(cls.prototype) as object;\n setHandle(instance, handle);\n\n return instance;\n}\n\n/**\n * Returns the wrapper class registered for a GType, walking up to ancestor types,\n * and throws if none is registered.\n */\nfunction getWrapperClass(type: bigint): AnyClass {\n const cls = resolveWrapperClass(type);\n\n if (!cls) {\n throw new Error(`No registered wrapper class for type '${typeName(type) ?? String(type)}'`);\n }\n\n return cls;\n}\n\nfunction resolveWrapperClass(type: bigint): AnyClass | null {\n let currentType = type;\n\n while (currentType !== TYPE_INVALID) {\n const cls = classRegistry.get(currentType);\n\n if (cls) {\n return cls;\n }\n\n currentType = typeParent(currentType);\n }\n\n return null;\n}\n\nfunction getInterfaceMixin(type: bigint): Mixin | undefined {\n return interfaceMixinRegistry.get(type);\n}\n\nfunction applyInterfaceMixin(cls: AnyClass, type: bigint, baseType: bigint, applied: Set<bigint>): AnyClass {\n if (applied.has(type) || typeIsA(baseType, type)) {\n return cls;\n }\n\n const mixin = getInterfaceMixin(type);\n\n if (mixin === undefined) {\n return cls;\n }\n\n applied.add(type);\n\n return mixin(cls as AnyClass<MixinReceiver>);\n}\n\nfunction createComposedClass(base: AnyClass, runtimeType: bigint): AnyClass {\n const baseType = getClassType(base);\n const applied: Set<bigint> = new Set();\n let cls: AnyClass = base;\n\n for (const type of typeInterfaces(runtimeType)) {\n cls = applyInterfaceMixin(cls, type, baseType, applied);\n }\n\n return applied.size === 0 ? base : cls;\n}\n\nfunction resolveComposedClass(runtimeType: bigint): AnyClass | null {\n const exact = classRegistry.get(runtimeType);\n\n if (exact) {\n return exact;\n }\n\n const cached = composedClassRegistry.get(runtimeType);\n\n if (cached) {\n return cached;\n }\n\n const base = resolveWrapperClass(runtimeType);\n\n if (base === null) {\n return null;\n }\n\n const composed = createComposedClass(base, runtimeType);\n\n if (composed === base) {\n return base;\n }\n\n setClassType(composed, runtimeType);\n wrapperClasses.add(composed);\n composedClassRegistry.set(runtimeType, composed);\n\n return composed;\n}\n\nfunction wrapObject(value: unknown): object | null {\n return value == null ? null : getOrCreateWrapper(value as ExternalObject<Handle>);\n}\n\nfunction wrapCallScopedObject(value: unknown): object | null {\n return value == null ? null : wrapperFor(value as ExternalObject<Handle>, bindCallScopedWrapper);\n}\n\nfunction existingWrapperFor(handle: ExternalObject<Handle>): object | null {\n return handleMap.has(handle) ? handle : getWrapper(handle);\n}\n\nfunction createWrapper(handle: ExternalObject<Handle>): object {\n const runtimeType: bigint = getType(handle);\n\n if (runtimeType === TYPE_INVALID) {\n throw new Error(\"Cannot resolve runtime GLib type from handle\");\n }\n\n const cls = resolveComposedClass(runtimeType);\n\n if (!cls) {\n throw new Error(`Expected registered GLib type, got type ${String(runtimeType)}`);\n }\n\n return Object.create(cls.prototype) as object;\n}\n\nfunction wrapperFor(handle: ExternalObject<Handle>, bind: WrapperBinding): object {\n const existing = existingWrapperFor(handle);\n\n if (existing) {\n return existing;\n }\n\n const instance = createWrapper(handle);\n bind(handle, instance);\n\n return instance;\n}\n\nfunction getOrCreateWrapper(handle: ExternalObject<Handle>): object {\n return wrapperFor(handle, registerWrapper);\n}\n\nfunction instanceClassName(instance: object): string {\n return (instance as { constructor?: { name?: string } }).constructor?.name ?? \"object\";\n}\n\n/** Returns the native handle bound to a wrapper instance, throwing if none is set. */\nfunction getHandle(instance: object): ExternalObject<Handle> {\n const handle = handleMap.get(instance);\n\n if (handle === undefined) {\n throw new Error(`No native handle associated with ${instanceClassName(instance)}`);\n }\n\n return handle;\n}\n\n/** Associates a native handle with a wrapper instance. */\nfunction setHandle(instance: object, handle: ExternalObject<Handle>): void {\n handleMap.set(instance, handle);\n}\n\nfunction bindCallScopedWrapper(handle: ExternalObject<Handle>, instance: object): void {\n setHandle(instance, handle);\n}\n\nfunction registerWrapper(handle: ExternalObject<Handle>, instance: object): void {\n setHandle(instance, handle);\n setWrapper(handle, instance);\n}\n\nfunction registerVfuncRegistry(cls: object, registry: VfuncRegistry): void {\n vfuncRegistry.set(cls, registry);\n}\n\nfunction getVfuncRegistry(cls: object): VfuncRegistry | undefined {\n return vfuncRegistry.get(cls);\n}\n\nfunction getInterfaceVfuncRegistry(type: bigint): VfuncRegistry | undefined {\n return interfaceLayoutRegistry.get(type)?.vfuncs;\n}\n\nfunction getInterfaceProperties(type: bigint): Record<string, InterfaceProperty> | undefined {\n return interfaceLayoutRegistry.get(type)?.properties;\n}\n\nexport {\n getClassType,\n getInstanceType,\n markDerivedClass,\n registerClassType,\n registerWrapperClass,\n registerInterface,\n wrapHandle,\n getWrapperClass,\n resolveWrapperClass,\n getHandle,\n setHandle,\n getVfuncRegistry,\n getInterfaceMixin,\n getInterfaceProperties,\n getInterfaceVfuncRegistry,\n instanceClassName,\n registerWrapper,\n resolveWrapperType,\n wrapCallScopedObject,\n wrapObject,\n type InterfaceProperty,\n type StaticBase,\n type VfuncDescriptor,\n};\n"]}
package/dist/signal.d.ts CHANGED
@@ -26,6 +26,14 @@ type EmitArg = Arg & {
26
26
  /** Returns the signal name without its detail suffix (the part after `::`). */
27
27
  declare const getSignalBaseName: (signal: string) => string;
28
28
  declare const isSignalHandlerConnected: (instance: object, handlerId: number) => boolean;
29
+ declare const untrackConnection: (instance: object, handlerId: number) => void;
30
+ /**
31
+ * Disconnects the handler an instance connected under the given id, and forgets the connection.
32
+ * @param instance Emitter the handler was connected to.
33
+ * @param handlerId Id {@link connectSignal} returned for the handler.
34
+ */
35
+ declare const disconnectSignal: (instance: object, handlerId: number) => void;
36
+ declare function hasSignalListener(instance: object, signals?: string[]): boolean;
29
37
  /**
30
38
  * Connects a handler to a GObject signal on an instance and returns the handler id.
31
39
  * @param instance Emitter to connect to.
@@ -33,15 +41,14 @@ declare const isSignalHandlerConnected: (instance: object, handlerId: number) =>
33
41
  * @param spec Callback descriptor, handler function, and whether to run after the default handler.
34
42
  */
35
43
  declare function connectSignal(instance: object, signal: string, spec: SignalConnectSpec): number;
36
- declare function blockMatchedSignalHandlers(instance: object, signal: string): void;
37
44
  /**
38
45
  * Emits a signal on an instance with the given arguments and returns its result
39
46
  * combined with any output-argument values.
40
47
  * @param instance Emitter to emit the signal on.
41
48
  * @param signal Signal name, optionally including a `::detail` suffix.
42
49
  * @param args Arguments to pass, including output and inout arguments.
43
- * @param returnDescriptor Descriptor for the signal's return value, omitted when it returns void.
50
+ * @param returns Descriptor for the signal's return value, omitted when it returns void.
44
51
  */
45
- declare function emitSignal(instance: object, signal: string, args: EmitArg[], returnDescriptor?: Descriptor): unknown;
46
- export { getSignalBaseName, connectSignal, blockMatchedSignalHandlers, emitSignal, isSignalHandlerConnected, type SignalHandler, };
52
+ declare function emitSignal(instance: object, signal: string, args: EmitArg[], returns?: Descriptor): unknown;
53
+ export { getSignalBaseName, connectSignal, disconnectSignal, emitSignal, hasSignalListener, isSignalHandlerConnected, untrackConnection, type SignalHandler, };
47
54
  //# sourceMappingURL=signal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../src/signal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AAEvE,OAAO,EAAE,KAAK,GAAG,EAAiD,MAAM,UAAU,CAAC;AAGnF,OAAO,EAIH,KAAK,kBAAkB,EAM1B,MAAM,kBAAkB,CAAC;AAc1B,mEAAmE;AACnE,KAAK,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAErD,2EAA2E;AAC3E,KAAK,iBAAiB,GAAG;IACrB;;;OAGG;IACH,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,4FAA4F;IAC5F,OAAO,EAAE,aAAa,CAAC;IACvB,yFAAyF;IACzF,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,uFAAuF;AACvF,KAAK,OAAO,GAAG,GAAG,GAAG;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AA2BF,+EAA+E;AAC/E,QAAA,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,MAI3C,CAAC;AAYF,QAAA,MAAM,wBAAwB,GAAI,UAAU,MAAM,EAAE,WAAW,MAAM,KAAG,OACA,C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