@gtkx/runtime 1.5.0 → 2.0.0-beta.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.
Files changed (101) hide show
  1. package/README.md +5 -5
  2. package/dist/application-class.d.ts +1 -1
  3. package/dist/application-class.d.ts.map +1 -1
  4. package/dist/application-class.js +1 -2
  5. package/dist/application-class.js.map +1 -1
  6. package/dist/arg.d.ts +4 -1
  7. package/dist/arg.d.ts.map +1 -1
  8. package/dist/arg.js.map +1 -1
  9. package/dist/bind.d.ts.map +1 -1
  10. package/dist/bind.js +1 -9
  11. package/dist/bind.js.map +1 -1
  12. package/dist/callback.d.ts +6 -1
  13. package/dist/callback.d.ts.map +1 -1
  14. package/dist/callback.js +33 -21
  15. package/dist/callback.js.map +1 -1
  16. package/dist/closure.d.ts +3 -1
  17. package/dist/closure.d.ts.map +1 -1
  18. package/dist/closure.js +17 -6
  19. package/dist/closure.js.map +1 -1
  20. package/dist/descriptors.d.ts +36 -36
  21. package/dist/descriptors.d.ts.map +1 -1
  22. package/dist/descriptors.js +65 -26
  23. package/dist/descriptors.js.map +1 -1
  24. package/dist/element-metadata.d.ts +9 -0
  25. package/dist/element-metadata.d.ts.map +1 -0
  26. package/dist/element-metadata.js +14 -0
  27. package/dist/element-metadata.js.map +1 -0
  28. package/dist/fn.d.ts +8 -2
  29. package/dist/fn.d.ts.map +1 -1
  30. package/dist/fn.js +43 -13
  31. package/dist/fn.js.map +1 -1
  32. package/dist/folded-lengths.d.ts +2 -1
  33. package/dist/folded-lengths.d.ts.map +1 -1
  34. package/dist/folded-lengths.js +17 -7
  35. package/dist/folded-lengths.js.map +1 -1
  36. package/dist/index.d.ts +4 -26
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +4 -26
  39. package/dist/index.js.map +1 -1
  40. package/dist/internal.d.ts +5 -2
  41. package/dist/internal.d.ts.map +1 -1
  42. package/dist/internal.js +5 -2
  43. package/dist/internal.js.map +1 -1
  44. package/dist/native-value.d.ts +9 -1
  45. package/dist/native-value.d.ts.map +1 -1
  46. package/dist/native-value.js +41 -5
  47. package/dist/native-value.js.map +1 -1
  48. package/dist/properties.d.ts +1 -1
  49. package/dist/properties.d.ts.map +1 -1
  50. package/dist/properties.js +2 -11
  51. package/dist/properties.js.map +1 -1
  52. package/dist/register-class.d.ts +45 -249
  53. package/dist/register-class.d.ts.map +1 -1
  54. package/dist/register-class.js +38 -1
  55. package/dist/register-class.js.map +1 -1
  56. package/dist/registry.d.ts +26 -3
  57. package/dist/registry.d.ts.map +1 -1
  58. package/dist/registry.js +75 -20
  59. package/dist/registry.js.map +1 -1
  60. package/dist/signal.d.ts.map +1 -1
  61. package/dist/signal.js +9 -22
  62. package/dist/signal.js.map +1 -1
  63. package/dist/t.d.ts +5 -21
  64. package/dist/t.d.ts.map +1 -1
  65. package/dist/t.js +1 -5
  66. package/dist/t.js.map +1 -1
  67. package/dist/type.d.ts +10 -1
  68. package/dist/type.d.ts.map +1 -1
  69. package/dist/type.js +21 -2
  70. package/dist/type.js.map +1 -1
  71. package/dist/value.d.ts.map +1 -1
  72. package/dist/value.js +26 -4
  73. package/dist/value.js.map +1 -1
  74. package/dist/variant.d.ts +2 -6
  75. package/dist/variant.d.ts.map +1 -1
  76. package/dist/variant.js.map +1 -1
  77. package/dist/vfunc-call.d.ts.map +1 -1
  78. package/dist/vfunc-call.js +2 -11
  79. package/dist/vfunc-call.js.map +1 -1
  80. package/package.json +15 -6
  81. package/src/application-class.ts +2 -2
  82. package/src/arg.ts +4 -1
  83. package/src/bind.ts +1 -12
  84. package/src/callback.ts +53 -29
  85. package/src/closure.ts +31 -6
  86. package/src/descriptors.ts +126 -44
  87. package/src/element-metadata.ts +24 -0
  88. package/src/fn.ts +64 -15
  89. package/src/folded-lengths.ts +23 -10
  90. package/src/index.ts +5 -24
  91. package/src/internal.ts +9 -2
  92. package/src/native-value.ts +54 -5
  93. package/src/properties.ts +3 -16
  94. package/src/register-class.ts +104 -249
  95. package/src/registry.ts +110 -19
  96. package/src/signal.ts +9 -34
  97. package/src/t.ts +5 -21
  98. package/src/type.ts +34 -1
  99. package/src/value.ts +37 -5
  100. package/src/variant.ts +2 -6
  101. package/src/vfunc-call.ts +3 -16
@@ -1,309 +1,105 @@
1
1
  import { type AnyClass } from "@gtkx/utils";
2
2
  import { type PropertySpec } from "./properties.js";
3
3
  import { type TypedClass } from "./type.js";
4
- /**
5
- * A generated interface value, such as `Gio.ListModel`, in the form {@link registerClass} takes it.
6
- * `__impl__` exists only in the type system: it carries the interface's `Impl` type, of which a class
7
- * has to match every member it declares itself, which rejects a class value and a member whose
8
- * signature does not fit the slot it fills. Leaving a slot to the interface is not rejected,
9
- * because `registerClass` does not reject it either: every member of an `Impl` type is optional,
10
- * and the `Partial` holds that open whatever the type declares. The `object` beside it keeps
11
- * TypeScript from also demanding one member in common. An interface that introspection describes
12
- * no vtable for carries `unknown`, since it has no slot a class could fill.
13
- */
4
+ /** A generated interface value, such as `Gio.ListModel`, accepted by {@link registerClass}. */
14
5
  type Interface<TImpl> = AnyClass & {
15
6
  /** Type-level slot holding the interface's `Impl` type; no value ever carries it. */
16
7
  __impl__: (impl: Partial<TImpl> & object) => void;
17
8
  };
18
- /**
19
- * One key of `RegisterClassOptions.properties` with every underscore turned into the dash a canonical
20
- * GObject property name separates its words with.
21
- */
9
+ /** Converts underscores in a property name to canonical dashes. */
22
10
  type Dashed<TName extends string> = TName extends `${infer THead}_${infer TTail}` ? Dashed<`${THead}-${TTail}`> : TName;
23
- /**
24
- * One dashed key in the camelCase spelling the accessors {@link registerClass} installs carry, which is
25
- * the spelling the hooks that address a property by name take.
26
- */
11
+ /** Converts a dashed property name to its JavaScript spelling. */
27
12
  type Camelized<TName extends string> = TName extends `${infer THead}-${infer TTail}` ? `${THead}${Capitalize<Camelized<TTail>>}` : TName;
28
- /**
29
- * The names a registered class carries in its property map: every key of
30
- * `RegisterClassOptions.properties` in camelCase, whichever spelling it was written in.
31
- * A `properties` object given a type of its own rather than left to inference has `string` for its key
32
- * type and names nothing, because a name only known as `string` addresses no member in particular.
33
- */
13
+ /** Property-map keys in the camelCase spelling hooks use. */
34
14
  type InstalledNames<TProperties> = string extends keyof TProperties ? never : Camelized<Dashed<keyof TProperties & string>>;
35
- /**
36
- * The base names the signal surface takes for the signals `RegisterClassOptions.signals` declares:
37
- * each name as written, plus its canonical spelling with underscores turned into dashes, which
38
- * GObject knows the signal by too.
39
- */
15
+ /** Declared signal names in their original and canonical spellings. */
40
16
  type DeclaredSignalBase<TSignals> = (keyof TSignals & string) | Dashed<keyof TSignals & string>;
41
- /**
42
- * The names `connect` and `emit` take for one of the signals `RegisterClassOptions.signals`
43
- * declares: each spelling of each name, plus its detailed form for a signal emitted with a
44
- * `::detail` suffix.
45
- */
17
+ /** Declared signal names, including detailed forms. */
46
18
  type DeclaredSignalName<TSignals> = DeclaredSignalBase<TSignals> | `${DeclaredSignalBase<TSignals>}::${string}`;
47
- /**
48
- * The `connect` and `emit` signatures instances gain for the signals
49
- * `RegisterClassOptions.signals` declares, widening the inherited ones, which take only the names
50
- * introspection knows. A class declaring no signals gains nothing, since no name reaches the
51
- * added signatures.
52
- */
19
+ /** Signal methods added for declared names. */
53
20
  type DeclaredSignalMethods<TSignals> = {
54
- /**
55
- * Type-level map from declared signal name to handler signature, feeding the hooks that
56
- * address a signal by name, such as `useSignal` from `@gtkx/react`; no value ever carries it.
57
- */
21
+ /** Type-level map used by signal hooks. */
58
22
  __signals__?: Record<DeclaredSignalBase<TSignals>, (...args: never[]) => unknown>;
59
- /** Connects a handler to a signal `RegisterClassOptions.signals` declared. */
23
+ /** Connects a handler. */
60
24
  connect(signal: DeclaredSignalName<TSignals>, handler: (...args: never[]) => unknown, isAfter?: boolean): number;
61
- /** Emits a signal `RegisterClassOptions.signals` declared. */
25
+ /** Emits a signal. */
62
26
  emit(sigName: DeclaredSignalName<TSignals>, ...args: unknown[]): unknown;
63
- /** Connects a handler to a signal `RegisterClassOptions.signals` declared, for `off` to take off. */
27
+ /** Connects a removable handler. */
64
28
  on(sigName: DeclaredSignalName<TSignals>, callback: (...args: unknown[]) => unknown, isAfter?: boolean): unknown;
65
- /** Connects a handler to a signal `RegisterClassOptions.signals` declared for one emission. */
29
+ /** Connects a one-shot handler. */
66
30
  once(sigName: DeclaredSignalName<TSignals>, callback: (...args: unknown[]) => unknown, isAfter?: boolean): unknown;
67
- /** Disconnects a handler `on` or `once` connected to a signal `RegisterClassOptions.signals` declared. */
31
+ /** Disconnects a handler. */
68
32
  off(sigName: DeclaredSignalName<TSignals>, callback: (...args: unknown[]) => unknown): unknown;
69
33
  };
70
- /**
71
- * An instance of a registered class: everything the class itself declares, plus the property map the
72
- * hooks that address a property by name, such as `useProperty` from `@gtkx/react`, read the installed
73
- * names off. Each name is typed with the value type the class declares for the member of that name,
74
- * so a property the class does not `declare` contributes nothing.
75
- */
34
+ /** A registered instance with declared signal methods and property metadata. */
76
35
  type RegisteredInstance<TInstance, TProperties, TSignals> = TInstance & DeclaredSignalMethods<TSignals> & {
77
36
  /** Type-level map from installed property name to value type; no value ever carries it. */
78
37
  __properties__: Pick<TInstance, InstalledNames<TProperties> & keyof TInstance>;
79
38
  };
80
- /**
81
- * The construct signature and prototype a registered class carries, both giving
82
- * {@link RegisteredInstance}. The signature stays abstract for as long as the class itself is, so
83
- * registering an abstract base leaves it as impossible to construct as it was.
84
- */
39
+ /** A registered class's construct signature and prototype. */
85
40
  type RegisteredConstructor<TClass, TArgs extends unknown[], TInstance> = {
86
41
  /** Object the class's instances inherit from. */
87
42
  prototype: TInstance;
88
43
  } & (TClass extends new (...args: never) => unknown ? new (...args: TArgs) => TInstance : abstract new (...args: TArgs) => TInstance);
89
44
  /** The statics a registered class keeps from the class it was, joined with {@link RegisteredConstructor}. */
90
45
  type RegisteredParts<TClass, TArgs extends unknown[], TInstance> = Omit<TClass, "prototype"> & RegisteredConstructor<TClass, TArgs, TInstance>;
91
- /**
92
- * The class {@link registerClass} hands back: the same class, with the same statics, whose instances
93
- * carry the properties `RegisterClassOptions.properties` installed and take the signals
94
- * `RegisterClassOptions.signals` declares by name. Binding the call to a name, rather than
95
- * discarding it, is what carries those names into the type system.
96
- */
46
+ /** The registered class with its declared properties and signals. */
97
47
  type RegisteredClass<TClass extends AnyClass, TProperties, TSignals> = TClass extends abstract new (...args: infer TArgs) => infer TInstance ? RegisteredParts<TClass, TArgs, RegisteredInstance<TInstance, TProperties, TSignals>> : never;
98
- /**
99
- * A GType in the form `RegisterClassOptions.signals` takes one: the numeric GType itself, such as
100
- * `TYPE_STRING` from `@gtkx/gi/gobject`, or a class carrying one, which is any generated wrapper
101
- * class and any class an earlier {@link registerClass} call registered.
102
- */
48
+ /** A numeric GType or a generated or registered wrapper class. */
103
49
  type SignalGType = bigint | AnyClass<TypedClass>;
104
- /**
105
- * One signal `RegisterClassOptions.signals` creates on the new type, sitting under the signal's
106
- * name. Every part is optional: `{}` declares a signal with no arguments and no return value that
107
- * runs its handlers in the default `RUN_FIRST` stage.
108
- */
50
+ /** A signal installed by {@link registerClass}. */
109
51
  type SignalSpec = {
110
- /**
111
- * `GObject.SignalFlags` bit mask for the signal, defaulting to `RUN_FIRST`. `DETAILED` lets
112
- * handlers connect to and emissions name a `::detail` suffix.
113
- */
52
+ /** `GObject.SignalFlags` bit mask, defaulting to `RUN_FIRST`. */
114
53
  flags?: number;
115
- /** GType of each argument an emission carries, defaulting to none. */
54
+ /** Argument GTypes, defaulting to none. */
116
55
  paramTypes?: SignalGType[];
117
- /** GType of the value an emission returns, defaulting to none. */
56
+ /** Return GType, defaulting to none. */
118
57
  returnType?: SignalGType;
119
- /**
120
- * How the emission combines what its handlers return, limited to the two accumulators GObject
121
- * ships: `"first-wins"` stops the emission at the first handler and keeps its result, and
122
- * `"true-handled"` runs handlers until one returns `true`, which requires a boolean
123
- * `returnType`. Without one, every handler runs and the last result stands.
124
- */
58
+ /** Combines handler results; omitted means the last result wins. */
125
59
  accumulator?: "first-wins" | "true-handled";
126
60
  };
127
61
  /** What {@link registerClass} adds to the new GType beyond the vtable slots it discovers on the class. */
128
62
  type RegisterClassOptions<TInstance extends object, TProperties extends Record<string, PropertySpec>, TSignals extends Record<string, SignalSpec>> = {
129
- /**
130
- * Name to register the new GType under, defaulting to the class's own name. Either way the
131
- * name has to be a valid GType name: at least three characters, starting with a letter or
132
- * underscore, the rest letters, digits, `-`, `_` or `+`. Any other name throws a `TypeError`.
133
- */
63
+ /** Registered GType name, defaulting to the class name. */
134
64
  typeName?: string;
135
- /**
136
- * Registers the new GType abstract, the way `G_TYPE_FLAG_ABSTRACT` marks a C type: the class
137
- * still serves as a parent for further registered subclasses, which instantiate as usual, but
138
- * constructing it directly throws, whether from JavaScript or from a native caller.
139
- */
65
+ /** Prevents direct construction while allowing registered subclasses. */
140
66
  abstract?: boolean;
141
- /**
142
- * Name instances of the new type carry in CSS, applied through `gtk_widget_class_set_css_name`
143
- * from inside the type's `class_init`, so every instance is born with it, wherever it is
144
- * created from. Requires the class to extend `Gtk.Widget`; registering a non-widget with a
145
- * `cssName` throws.
146
- */
67
+ /** CSS node name for a `Gtk.Widget` subclass. */
147
68
  cssName?: string;
148
69
  /**
149
- * Hook run once, synchronously, while `registerClass` registers the type, after its
150
- * `class_init` has installed the vfuncs, properties and signals declared here. It receives the
151
- * new type's class struct wrapped in its generated GTypeStruct wrapper, so class-level setup
152
- * calls such as `Gtk.WidgetClass.installAction`, `Gtk.WidgetClass.addShortcut` and
153
- * `Gtk.WidgetClass.setLayoutManagerType` have somewhere to land. The wrapper serves the
154
- * members of every struct in the parent chain on one object: a widget subclass sees
155
- * `Gtk.WidgetClass` and `GObject.ObjectClass` members alike, so the parameter can be declared
156
- * as whichever of those types the hook needs. The class struct belongs to the type system for
157
- * the life of the process, so keeping the wrapper around past the hook is safe, if rarely
158
- * useful. An exception the hook throws propagates out of `registerClass`, with the type
159
- * already registered: GObject offers no way to unregister a static type.
70
+ * Runs once after registration with the wrapped class struct. An exception propagates after
71
+ * the static GType has already been registered and cannot be undone.
160
72
  */
161
73
  classInit?(typeStruct: object): void;
162
- /**
163
- * Interfaces the new type implements on top of the ones it inherits, given as the interface values
164
- * themselves, such as `Gio.ListModel`. Their vtable slots are filled from the `vfunc`-prefixed methods on
165
- * the class's prototype chain, each of which has to match the interface's `Impl` type, such as
166
- * `Gio.ListModelImpl`.
167
- */
74
+ /** Interfaces implemented through matching `vfunc` methods. */
168
75
  implements?: Interface<TInstance>[];
169
76
  /**
170
- * Properties to install on the new type, keyed by the name JavaScript addresses each one by and
171
- * valued with the `GObject.ParamSpec` describing it. A key is read in camelCase however it is
172
- * written, so `dewPoint`, `dew_point` and `dew-point` all name the same member, and the ParamSpec
173
- * has to carry a name that reads back as that same member, such as `dew-point`, or registration
174
- * throws: the ParamSpec's name is the one GObject emits `notify` with, and a name the key does
175
- * not spell reaches nothing that listens for it. A word starting with a digit is a word of its
176
- * own on either side of that reading, so `level2Depth` takes a ParamSpec named `level-2-depth`
177
- * as readily as one named `level2-depth`, the way `WebKit.Settings` names
178
- * `enable-2d-canvas-acceleration` for its `enable2dCanvasAcceleration` member. An uppercase
179
- * letter in the ParamSpec's own name is refused, since GObject notifies under that spelling
180
- * and nothing else reads it back. Every property gains prototype accessors, one for the key as
181
- * written, one for it with dashes turned into underscores and one for it in camelCase, each
182
- * unless the class already defines that name. They serve the value from storage of their own on
183
- * the instance, which is also what the type's `get_property` and `set_property` slots read and
184
- * write, so a value set from JavaScript, from `g_object_set_property` and at construction all
185
- * land in the same place.
186
- *
187
- * A write the ParamSpec would refuse throws rather than reaching GObject, which reports such a
188
- * write as a GLib critical and drops it: a `TypeError` for a read-only or construct-only
189
- * property and for a value of a type the property cannot hold, and a `RangeError` for a value
190
- * the ParamSpec rejects. The same checks run over a value handed to the constructor, where
191
- * a construct-only property is the one that is writable. An accepted write emits one `notify`,
192
- * which a `freeze_notify` batch collects; a write of the value the property already holds is
193
- * dropped and emits none.
194
- *
195
- * `null` and `undefined` both mean NULL, and mean it only where the ParamSpec's own type holds
196
- * NULL, which is a string, string-array, boxed, object, interface, param, variant or pointer
197
- * property. Such a property holds the `null` either spelling wrote, so the member, the type's
198
- * `get_property` slot and `g_object_get_property` serve the same thing, and writing the other
199
- * spelling over it emits no `notify`. Every other property, so every integer, floating-point,
200
- * boolean, enum, flags and GType one, refuses both with the same `TypeError` it refuses a
201
- * string with, and keeps the value it already holds. It refuses them for what it holds rather
202
- * than for its range, whatever that range is: the type is checked before the range, so a
203
- * `gint` whose range excludes 0 answers a nullish with that same `TypeError` and never with
204
- * the `RangeError` that names the value GObject would put in its place. The one place
205
- * `undefined` means something else is the constructor, which reads it as the property not
206
- * being given at all and leaves it at the ParamSpec's default, so a property is never handed a
207
- * value it cannot serve back.
208
- *
209
- * A floating-point property takes every JavaScript number, `NaN` and both infinities
210
- * included, and its ParamSpec alone rules on which of them the range admits: a `gdouble`
211
- * bounded by `-Infinity` and `Infinity` holds either infinity, and a magnitude a bounded
212
- * one excludes, like any `NaN`, comes back as the `RangeError` that names what GObject
213
- * would put in its place rather than as the `TypeError` a type the property cannot hold
214
- * earns. A `gfloat` property holds what GObject narrows the double to, so it serves `0.1`
215
- * back as `0.10000000149011612` and a finite magnitude no `gfloat` reaches as an infinity,
216
- * which the range then rules on in turn. That narrowing belongs to the property alone: the
217
- * same magnitude written to a `gfloat` through a generated binding, a signal argument or a
218
- * closure return is refused outright rather than narrowed.
219
- *
220
- * A generated property of a wrapped type answers a nullish differently, and the two halves of
221
- * the API disagree here: that property marshals what it is written through its descriptor
222
- * rather than through the checks above, so `new Gtk.Label({ widthRequest: null })` and a later
223
- * write of `null` to that member both land 0, where a `gint` installed here refuses both.
224
- *
225
- * A class that defines the camelCase member itself owns the property: its own accessor decides
226
- * what a write means, the other spellings forward to it, and the type's property slots read
227
- * and write it rather than the generated storage.
77
+ * ParamSpecs keyed by their JavaScript property names. Keys and ParamSpec names must canonicalize
78
+ * to the same member. Writes validate flags, types, and ranges and notify only on changes.
79
+ * Nullish values require a nullable GType; constructor `undefined` means omitted. An existing
80
+ * camelCase accessor remains authoritative.
228
81
  */
229
82
  properties?: TProperties;
230
83
  /**
231
- * Signals to create on the new type, keyed by signal name and valued with the
232
- * {@link SignalSpec} describing each one. A name has to start with a lowercase letter, continue
233
- * in lowercase letters, digits, `-` and `_`, and be new to the type: one an ancestor type or a
234
- * listed interface already carries throws, and so does one carrying an uppercase letter, which
235
- * GObject would carry under that exact spelling, out of reach of both its dashed spelling and
236
- * its `on<SignalName>` default handler. The two word separators spell the same signal, so a
237
- * signal declared as `data_changed` is connected to and emitted as `data-changed` too.
238
- *
239
- * Instances connect and emit by name through the same `connect`, `on`, `once`, `off` and
240
- * `emit` surface inherited signals use: `registerClass` wraps `connect` and `emit` on the
241
- * class's prototype to serve the declared names, unless the class defines the member itself,
242
- * and hands every other name to the inherited implementation. A handler receives the
243
- * emission's arguments without the leading emitter, matching a generated signal, and what it
244
- * returns becomes the emission's return value when the signal declares one.
245
- *
246
- * The declared parameter GTypes rule the emission: `emit` takes exactly one argument per
247
- * declared parameter, throwing a `TypeError` for any other count, and converts each argument
248
- * into a `GValue` of the declared type, throwing for a value that type cannot hold. The signals
249
- * are created with no class closure of their own, but a method named `on<SignalName>`
250
- * becomes the signal's default handler, the way every `on`-prefixed method that names a
251
- * signal the type carries does; see {@link registerClass}.
84
+ * New canonical signal names and specs. Declared GTypes validate emissions, and a matching
85
+ * `on<SignalName>` method becomes the default handler.
252
86
  */
253
87
  signals?: TSignals;
254
88
  };
255
89
  /**
256
- * Registers a subclass of a wrapper class as a new GType, wiring up any class and interface
257
- * virtual functions it overrides, both for the interfaces it inherits and for the ones
258
- * `RegisterClassOptions.implements` names.
259
- *
260
- * Throws when the class does not extend a registered wrapper class, when it has no derivable type
261
- * name or the name is not a valid GType name, when an entry in
262
- * `RegisterClassOptions.implements` is not a registered interface, when a
263
- * listed interface has a prerequisite that neither the parent type nor another listed interface meets,
264
- * when the list names `Gio.AsyncInitable` as an interface the parent type does not already
265
- * implement and no method on the chain fills `vfuncInitAsync`, since the default `init_async`
266
- * would run `vfuncInit` on a worker thread, when an entry in
267
- * `RegisterClassOptions.properties` names its `GObject.ParamSpec` something the key it sits under
268
- * does not spell, when an entry in `RegisterClassOptions.signals` carries an invalid name, a name
269
- * spelled with an uppercase letter rather than dashed, a name the type already knows, a GType
270
- * that cannot hold a value, or an accumulator the spec does not admit, and when
271
- * `RegisterClassOptions.cssName` is
272
- * given for a class that does not extend `Gtk.Widget`. An exception thrown by
273
- * `RegisterClassOptions.classInit` also propagates, after the type has already been registered.
274
- *
275
- * A slot is filled from the `vfunc`-prefixed methods on the class's prototype chain, up to but not
276
- * including the registered ancestor the class extends, so a method an intermediate base class
277
- * declares fills a slot the same way one the class itself declares does. A slot nothing on that
278
- * chain fills is left untouched.
279
- *
280
- * Declare every slot as a method: a class field holding a function, such as `vfuncGetNItems = () => 1`,
281
- * is assigned to each instance after registration and never reaches the vtable.
282
- *
283
- * A method named `on<SignalName>` — the signal's name in camelCase after the `on`, so `onClicked`
284
- * for `clicked` and `onItemsChanged` for `items-changed` — becomes that signal's default handler
285
- * when the type carries the signal, whether an ancestor type or an implemented interface brings it
286
- * or `RegisterClassOptions.signals` declares it. The method is installed as a class-closure
287
- * override, so it runs on every emission, on the instances a native caller creates included, in
288
- * the stage the signal's flags name rather than alongside connected handlers. It receives the
289
- * emission's arguments without the leading emitter, with `this` bound to the emitter, and what it
290
- * returns becomes the emission's result when the signal declares one. The same discovery walks the
291
- * prototype chain vfunc discovery walks, and a subclass registering its own `on<SignalName>`
292
- * replaces the handler for its instances, where `super.on<SignalName>()` reaches the replaced one.
293
- * An `on`-prefixed method naming no signal the type carries is left alone as the ordinary method
294
- * it is.
90
+ * Registers a wrapper subclass as a GType with discovered vfuncs, properties, signals, and interfaces.
91
+ * Vfuncs must be prototype methods; function-valued fields never reach the vtable. A matching
92
+ * `on<SignalName>` method becomes the signal's default handler.
295
93
  *
296
- * An override of `vfuncConstructed` runs from inside the base constructor, before JavaScript
297
- * installs the subclass's field initializers and runs its constructor body, so a field still
298
- * reads `undefined` there and reading a `#private` field throws. Declare state the override
299
- * touches without an initializer, and assign private state from the constructor body after
300
- * `super()`. An instance a native caller creates, through `GObject.newv` or `Gtk.Builder`,
301
- * never runs the subclass constructor at all, so its declared fields stay uninitialized for
302
- * the object's whole life.
94
+ * `vfuncConstructed` runs before field initializers and the constructor body. Native-created
95
+ * instances never run the JavaScript constructor, so native-required state belongs in properties
96
+ * or `vfuncConstructed`. A new `Gio.AsyncInitable` must implement `vfuncInitAsync`.
303
97
  *
304
- * @param klass The subclass to register.
305
- * @param options What the new GType gains beyond the vtable slots the class overrides.
306
- * @returns The same class, now registered, with every name in `options.properties` in its property map.
98
+ * @param klass The wrapper subclass to register.
99
+ * @param options Additional GType configuration.
100
+ * @returns The registered class with declared properties and signals in its type.
101
+ * @throws For invalid parents, names, interfaces, vfuncs, properties, signals, or widget options.
102
+ * A `classInit` exception propagates after the static type has been registered and cannot be undone.
307
103
  */
308
104
  declare function registerClass<T extends AnyClass, TProperties extends Record<string, PropertySpec> = Record<never, PropertySpec>, TSignals extends Record<string, SignalSpec> = Record<never, SignalSpec>>(klass: T, options?: RegisterClassOptions<T["prototype"], TProperties, TSignals>): RegisteredClass<T, TProperties, TSignals>;
309
105
  export { type Interface, registerClass, type SignalGType, type SignalSpec };
@@ -1 +1 @@
1
- {"version":3,"file":"register-class.d.ts","sourceRoot":"","sources":["../src/register-class.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,QAAQ,EAA6C,MAAM,aAAa,CAAC;AAGvF,OAAO,EAMH,KAAK,YAAY,EAGpB,MAAM,iBAAiB,CAAC;AAqBzB,OAAO,EAIH,KAAK,UAAU,EAKlB,MAAM,WAAW,CAAC;AAGnB;;;;;;;;;GASG;AACH,KAAK,SAAS,CAAC,KAAK,IAAI,QAAQ,GAAG;IAC/B,qFAAqF;IACrF,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,KAAK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yEAAyE;IACzE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,+DAA+D;IAC/D,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;IACpC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB;;;OAGG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC;CACtB,CAAC;AAoDF;;;;;;;;;;;;;;GAcG;AACH,iBAAS,aAAa,CAClB,CAAC,SAAS,QAAQ,EAClB,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,EAC9E,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,EAEvE,KAAK,EAAE,CAAC,EACR,OAAO,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,GACtE,eAAe,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;AAmnB7C,OAAO,EAAE,KAAK,SAAS,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,CAAC"}
@@ -5,7 +5,7 @@ import { insertMixinLayer } from "./mixin.js";
5
5
  import { buildPropertyDispatch, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, SET_PROPERTY_VFUNC, toNativeProperties, } from "./properties.js";
6
6
  import { getClassStructClass, getClassType, getInterfaceMixin, getTypeClassHandle, markDerivedClass, registerClassType, wrapHandle, } from "./registry.js";
7
7
  import { connectClosureSignal, emitDeclaredSignal, getSignalBaseName, overrideSignalClassClosure, signalForHandlerName, signalIdFor, } from "./signal.js";
8
- import { TYPE_INTERFACE, TYPE_INVALID, TYPE_NONE, typeFundamental, typeInterfaces, typeIsA, typeName, } from "./type.js";
8
+ import { TYPE_INTERFACE, TYPE_INVALID, TYPE_NONE, typeFundamental, typeInterfacePrerequisites, typeInterfaces, typeIsA, typeName, } from "./type.js";
9
9
  import { findClassVfuncDescriptor, findInterfaceVfuncDescriptor } from "./vfunc.js";
10
10
  const INSTANCE_ARG_INDEX = 0;
11
11
  const VALUE_ARG_INDEX = 2;
@@ -17,6 +17,7 @@ const PROPERTY_VFUNC_SPECS = [
17
17
  { methodName: SET_PROPERTY_VFUNC, isValueOut: false, makeDispatch: makeSetProperty },
18
18
  ];
19
19
  const PROPERTY_VFUNC_NAMES = new Set(PROPERTY_VFUNC_SPECS.map((spec) => spec.methodName));
20
+ const VFUNC_METHOD_PATTERN = /^vfunc[A-Z0-9]/;
20
21
  const TYPE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9\-_+]{2,}$/;
21
22
  const UPPER_CASE_PATTERN = /[A-Z]/;
22
23
  const SIGNAL_OVERRIDE_PATTERN = /^on[A-Z]/;
@@ -27,6 +28,7 @@ function registerClass(klass, options = {}) {
27
28
  }
28
29
  const name = resolveTypeName(klass, options);
29
30
  const declaredTypes = resolveInterfaceTypes(klass, options.implements ?? []);
31
+ assertInterfacePrerequisites(klass, parentType, declaredTypes);
30
32
  const adoptedTypes = declaredTypes.filter((gtype) => !typeIsA(parentType, gtype));
31
33
  const properties = options.properties ?? {};
32
34
  const signals = resolveDeclaredSignals(klass, options.signals ?? {});
@@ -40,6 +42,7 @@ function registerClass(klass, options = {}) {
40
42
  ];
41
43
  const claimedMethodNames = new Set(classVfuncs.map((vfunc) => vfunc.methodName));
42
44
  const interfaceBindings = discoverInterfaceBindings(methods, parentType, declaredTypes, claimedMethodNames);
45
+ assertClaimedVfuncs(klass, methods, claimedMethodNames, interfaceBindings);
43
46
  const nativeOptions = withNativeSignals(toNativeOptions(classVfuncs, interfaceBindings, properties, options), signals.native);
44
47
  const newType = nativeRegisterClass(name, parentType, nativeOptions);
45
48
  registerClassType(klass, newType);
@@ -169,6 +172,40 @@ function discoverClassVfuncs(klass, methods) {
169
172
  function wrapVfunc(fn, argDescriptors, descriptor) {
170
173
  return wrapCallback(fn, { argDescriptors, returnDescriptor: descriptor.returnDescriptor }, "vfunc");
171
174
  }
175
+ const claimedVfuncNames = (claimedMethodNames, interfaceBindings) => {
176
+ const claimed = new Set(claimedMethodNames);
177
+ for (const binding of interfaceBindings) {
178
+ for (const vfunc of binding.vfuncs) {
179
+ claimed.add(vfunc.methodName);
180
+ }
181
+ }
182
+ return claimed;
183
+ };
184
+ const isPrerequisiteMet = (parentType, declaredTypes, prerequisite) => typeIsA(parentType, prerequisite) || declaredTypes.includes(prerequisite);
185
+ function assertPrerequisitesFor(klass, parentType, declaredTypes, iface) {
186
+ for (const prerequisite of typeInterfacePrerequisites(iface)) {
187
+ if (!isPrerequisiteMet(parentType, declaredTypes, prerequisite)) {
188
+ throw new TypeError(`registerClass: ${klass.name} does not meet prerequisite ` +
189
+ `'${typeName(prerequisite) ?? String(prerequisite)}' of interface ` +
190
+ `'${typeName(iface) ?? String(iface)}'`);
191
+ }
192
+ }
193
+ }
194
+ function assertInterfacePrerequisites(klass, parentType, declaredTypes) {
195
+ for (const iface of declaredTypes) {
196
+ assertPrerequisitesFor(klass, parentType, declaredTypes, iface);
197
+ }
198
+ }
199
+ function assertClaimedVfuncs(klass, methods, claimedMethodNames, interfaceBindings) {
200
+ const claimed = claimedVfuncNames(claimedMethodNames, interfaceBindings);
201
+ for (const methodName of methods.keys()) {
202
+ if (VFUNC_METHOD_PATTERN.test(methodName) && !claimed.has(methodName)) {
203
+ throw new Error(`registerClass: ${klass.name}.${methodName} matches no vtable slot on any ancestor ` +
204
+ "or implemented interface, so the override would never be called; check the name against " +
205
+ "the parent class's virtual methods");
206
+ }
207
+ }
208
+ }
172
209
  function discoverInterfaceBindings(methods, parentGtype, declaredTypes, claimedMethodNames) {
173
210
  const declared = new Set(declaredTypes);
174
211
  const gtypes = new Set([...typeInterfaces(parentGtype), ...declaredTypes]);