@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.
- package/README.md +5 -5
- package/dist/application-class.d.ts +37 -0
- package/dist/application-class.d.ts.map +1 -0
- package/dist/application-class.js +78 -0
- package/dist/application-class.js.map +1 -0
- package/dist/arg.d.ts +2 -1
- package/dist/arg.d.ts.map +1 -1
- package/dist/arg.js +2 -1
- package/dist/arg.js.map +1 -1
- package/dist/bind.d.ts +11 -0
- package/dist/bind.d.ts.map +1 -1
- package/dist/bind.js +11 -0
- package/dist/bind.js.map +1 -1
- package/dist/callback.d.ts +4 -3
- package/dist/callback.d.ts.map +1 -1
- package/dist/callback.js +124 -29
- package/dist/callback.js.map +1 -1
- package/dist/closure.d.ts +26 -0
- package/dist/closure.d.ts.map +1 -0
- package/dist/closure.js +99 -0
- package/dist/closure.js.map +1 -0
- package/dist/default-application.d.ts +4 -0
- package/dist/default-application.d.ts.map +1 -0
- package/dist/default-application.js +17 -0
- package/dist/default-application.js.map +1 -0
- package/dist/descriptors.d.ts +98 -4
- package/dist/descriptors.d.ts.map +1 -1
- package/dist/descriptors.js +72 -6
- package/dist/descriptors.js.map +1 -1
- package/dist/error.d.ts +1 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js.map +1 -1
- package/dist/exit-hook.js +13 -0
- package/dist/exit-hook.js.map +1 -1
- package/dist/fn.d.ts +24 -2
- package/dist/fn.d.ts.map +1 -1
- package/dist/fn.js +67 -32
- package/dist/fn.js.map +1 -1
- package/dist/folded-lengths.d.ts +16 -0
- package/dist/folded-lengths.d.ts.map +1 -0
- package/dist/folded-lengths.js +38 -0
- package/dist/folded-lengths.js.map +1 -0
- package/dist/index.d.ts +14 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +2 -0
- package/dist/internal.js.map +1 -1
- package/dist/library.d.ts +3 -1
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +3 -1
- package/dist/library.js.map +1 -1
- package/dist/lifecycle.d.ts +58 -11
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +95 -22
- package/dist/lifecycle.js.map +1 -1
- package/dist/listeners.d.ts.map +1 -1
- package/dist/listeners.js +19 -5
- package/dist/listeners.js.map +1 -1
- package/dist/mixin.d.ts +3 -2
- package/dist/mixin.d.ts.map +1 -1
- package/dist/mixin.js +13 -1
- package/dist/mixin.js.map +1 -1
- package/dist/native-value.d.ts.map +1 -1
- package/dist/native-value.js +4 -3
- package/dist/native-value.js.map +1 -1
- package/dist/object.d.ts +40 -7
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +95 -26
- package/dist/object.js.map +1 -1
- package/dist/param-spec.d.ts +11 -0
- package/dist/param-spec.d.ts.map +1 -0
- package/dist/param-spec.js +147 -0
- package/dist/param-spec.js.map +1 -0
- package/dist/promisify.d.ts.map +1 -1
- package/dist/promisify.js +3 -2
- package/dist/promisify.js.map +1 -1
- package/dist/properties.d.ts +39 -7
- package/dist/properties.d.ts.map +1 -1
- package/dist/properties.js +310 -43
- package/dist/properties.js.map +1 -1
- package/dist/register-class.d.ts +147 -12
- package/dist/register-class.d.ts.map +1 -1
- package/dist/register-class.js +129 -83
- package/dist/register-class.js.map +1 -1
- package/dist/registry.d.ts +80 -21
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +86 -33
- package/dist/registry.js.map +1 -1
- package/dist/signal.d.ts +11 -4
- package/dist/signal.d.ts.map +1 -1
- package/dist/signal.js +85 -25
- package/dist/signal.js.map +1 -1
- package/dist/t.d.ts +2 -0
- package/dist/t.d.ts.map +1 -1
- package/dist/t.js +1 -0
- package/dist/t.js.map +1 -1
- package/dist/tuple.d.ts +6 -3
- package/dist/tuple.d.ts.map +1 -1
- package/dist/tuple.js +9 -7
- package/dist/tuple.js.map +1 -1
- package/dist/type.d.ts +2 -1
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js +2 -0
- package/dist/type.js.map +1 -1
- package/dist/value.d.ts +10 -1
- package/dist/value.d.ts.map +1 -1
- package/dist/value.js +99 -24
- package/dist/value.js.map +1 -1
- package/dist/vfunc-call.d.ts +37 -0
- package/dist/vfunc-call.d.ts.map +1 -0
- package/dist/vfunc-call.js +172 -0
- package/dist/vfunc-call.js.map +1 -0
- package/dist/vfunc-seeds.d.ts +12 -0
- package/dist/vfunc-seeds.d.ts.map +1 -0
- package/dist/vfunc-seeds.js +19 -0
- package/dist/vfunc-seeds.js.map +1 -0
- package/dist/vfunc.d.ts +8 -0
- package/dist/vfunc.d.ts.map +1 -0
- package/dist/vfunc.js +29 -0
- package/dist/vfunc.js.map +1 -0
- package/package.json +14 -4
- package/src/application-class.ts +126 -0
- package/src/arg.ts +2 -1
- package/src/bind.ts +11 -0
- package/src/callback.ts +178 -34
- package/src/closure.ts +136 -0
- package/src/default-application.ts +21 -0
- package/src/descriptors.ts +150 -34
- package/src/error.ts +1 -0
- package/src/exit-hook.ts +18 -0
- package/src/fn.ts +107 -36
- package/src/folded-lengths.ts +64 -0
- package/src/index.ts +21 -6
- package/src/internal.ts +2 -0
- package/src/library.ts +3 -1
- package/src/lifecycle.ts +138 -25
- package/src/listeners.ts +25 -6
- package/src/mixin.ts +15 -2
- package/src/native-value.ts +5 -3
- package/src/object.ts +134 -35
- package/src/param-spec.ts +234 -0
- package/src/promisify.ts +4 -2
- package/src/properties.ts +473 -46
- package/src/register-class.ts +386 -114
- package/src/registry.ts +169 -49
- package/src/signal.ts +116 -42
- package/src/t.ts +3 -0
- package/src/tuple.ts +18 -12
- package/src/type.ts +3 -1
- package/src/value.ts +143 -23
- package/src/vfunc-call.ts +247 -0
- package/src/vfunc-seeds.ts +36 -0
- package/src/vfunc.ts +38 -0
package/dist/register-class.d.ts
CHANGED
|
@@ -1,25 +1,160 @@
|
|
|
1
1
|
import { type AnyClass } from "@gtkx/utils";
|
|
2
2
|
import { type PropertySpec } from "./properties.js";
|
|
3
|
+
/**
|
|
4
|
+
* A generated interface value, such as `Gio.ListModel`, in the form {@link registerClass} takes it.
|
|
5
|
+
* `__impl__` exists only in the type system: it carries the interface's `Impl` type, of which a class
|
|
6
|
+
* has to match every member it declares itself, which rejects a class value and a member whose
|
|
7
|
+
* signature does not fit the slot it fills. Leaving a slot to the interface is not rejected,
|
|
8
|
+
* because `registerClass` does not reject it either: every member of an `Impl` type is optional,
|
|
9
|
+
* and the `Partial` holds that open whatever the type declares. The `object` beside it keeps
|
|
10
|
+
* TypeScript from also demanding one member in common. An interface that introspection describes
|
|
11
|
+
* no vtable for carries `unknown`, since it has no slot a class could fill.
|
|
12
|
+
*/
|
|
13
|
+
type Interface<TImpl> = AnyClass & {
|
|
14
|
+
/** Type-level slot holding the interface's `Impl` type; no value ever carries it. */
|
|
15
|
+
__impl__: (impl: Partial<TImpl> & object) => void;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* One key of `RegisterClassOptions.properties` with every underscore turned into the dash a canonical
|
|
19
|
+
* GObject property name separates its words with.
|
|
20
|
+
*/
|
|
21
|
+
type Dashed<TName extends string> = TName extends `${infer THead}_${infer TTail}` ? Dashed<`${THead}-${TTail}`> : TName;
|
|
22
|
+
/**
|
|
23
|
+
* One dashed key in the camelCase spelling the accessors {@link registerClass} installs carry, which is
|
|
24
|
+
* the spelling the hooks that address a property by name take.
|
|
25
|
+
*/
|
|
26
|
+
type Camelized<TName extends string> = TName extends `${infer THead}-${infer TTail}` ? `${THead}${Capitalize<Camelized<TTail>>}` : TName;
|
|
27
|
+
/**
|
|
28
|
+
* The names a registered class carries in its property map: every key of
|
|
29
|
+
* `RegisterClassOptions.properties` in camelCase, whichever of the three spellings it was written in.
|
|
30
|
+
* A `properties` object given a type of its own rather than left to inference has `string` for its key
|
|
31
|
+
* type and names nothing, because a name only known as `string` addresses no member in particular.
|
|
32
|
+
*/
|
|
33
|
+
type InstalledNames<TProperties> = string extends keyof TProperties ? never : Camelized<Dashed<keyof TProperties & string>>;
|
|
34
|
+
/**
|
|
35
|
+
* An instance of a registered class: everything the class itself declares, plus the property map the
|
|
36
|
+
* hooks that address a property by name, such as `useProperty` from `@gtkx/react`, read the installed
|
|
37
|
+
* names off. Each name is typed with the value type the class declares for the member of that name,
|
|
38
|
+
* so a property the class does not `declare` contributes nothing.
|
|
39
|
+
*/
|
|
40
|
+
type RegisteredInstance<TInstance, TProperties> = TInstance & {
|
|
41
|
+
/** Type-level map from installed property name to value type; no value ever carries it. */
|
|
42
|
+
__properties__: Pick<TInstance, InstalledNames<TProperties> & keyof TInstance>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The construct signature and prototype a registered class carries, both giving
|
|
46
|
+
* {@link RegisteredInstance}. The signature stays abstract for as long as the class itself is, so
|
|
47
|
+
* registering an abstract base leaves it as impossible to construct as it was.
|
|
48
|
+
*/
|
|
49
|
+
type RegisteredConstructor<TClass, TArgs extends unknown[], TInstance> = {
|
|
50
|
+
/** Object the class's instances inherit from. */
|
|
51
|
+
prototype: TInstance;
|
|
52
|
+
} & (TClass extends new (...args: never) => unknown ? new (...args: TArgs) => TInstance : abstract new (...args: TArgs) => TInstance);
|
|
53
|
+
/**
|
|
54
|
+
* The class {@link registerClass} hands back: the same class, with the same statics, whose instances
|
|
55
|
+
* carry the properties `RegisterClassOptions.properties` installed. Binding the call to a name, rather
|
|
56
|
+
* than discarding it, is what carries those names into the type system.
|
|
57
|
+
*/
|
|
58
|
+
type RegisteredClass<TClass extends AnyClass, TProperties> = TClass extends abstract new (...args: infer TArgs) => infer TInstance ? Omit<TClass, "prototype"> & RegisteredConstructor<TClass, TArgs, RegisteredInstance<TInstance, TProperties>> : never;
|
|
3
59
|
/** What {@link registerClass} adds to the new GType beyond the vtable slots it discovers on the class. */
|
|
4
|
-
type RegisterClassOptions = {
|
|
60
|
+
type RegisterClassOptions<TInstance extends object, TProperties extends Record<string, PropertySpec>> = {
|
|
5
61
|
/** Name to register the new GType under, defaulting to the class's own name. */
|
|
6
62
|
typeName?: string;
|
|
7
63
|
/**
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
10
|
-
* prototype
|
|
64
|
+
* Interfaces the new type implements on top of the ones it inherits, given as the interface values
|
|
65
|
+
* themselves, such as `Gio.ListModel`. Their vtable slots are filled from the `vfunc`-prefixed methods on
|
|
66
|
+
* the class's prototype chain, each of which has to match the interface's `Impl` type, such as
|
|
67
|
+
* `Gio.ListModelImpl`.
|
|
11
68
|
*/
|
|
12
|
-
|
|
69
|
+
implements?: Interface<TInstance>[];
|
|
70
|
+
/**
|
|
71
|
+
* Properties to install on the new type, keyed by the name JavaScript addresses each one by and
|
|
72
|
+
* valued with the `GObject.ParamSpec` describing it. A key is read in camelCase however it is
|
|
73
|
+
* written, so `dewPoint`, `dew_point` and `dew-point` all name the same member, and the ParamSpec
|
|
74
|
+
* has to carry the canonical spelling of that name, `dew-point`, or registration throws: the
|
|
75
|
+
* ParamSpec's name is the one GObject emits `notify` with, and a name the key does not spell
|
|
76
|
+
* reaches nothing that listens for it. Every property gains prototype accessors, one for the key
|
|
77
|
+
* as written, one for it with dashes turned into underscores and one for it in camelCase, each
|
|
78
|
+
* unless the class already defines that name. They serve the value from storage of their own on
|
|
79
|
+
* the instance, which is also what the type's `get_property` and `set_property` slots read and
|
|
80
|
+
* write, so a value set from JavaScript, from `g_object_set_property` and at construction all
|
|
81
|
+
* land in the same place.
|
|
82
|
+
*
|
|
83
|
+
* A write the ParamSpec would refuse throws rather than reaching GObject, which reports such a
|
|
84
|
+
* write as a GLib critical and drops it: a `TypeError` for a read-only or construct-only
|
|
85
|
+
* property and for a value of a type the property cannot hold, and a `RangeError` for a value
|
|
86
|
+
* the ParamSpec rejects. The same two checks run over a value handed to the constructor, where
|
|
87
|
+
* a construct-only property is the one that is writable. An accepted write emits one `notify`,
|
|
88
|
+
* which a `freeze_notify` batch collects; a write of the value the property already holds is
|
|
89
|
+
* dropped and emits none.
|
|
90
|
+
*
|
|
91
|
+
* `null` and `undefined` both mean NULL, and mean it only where the ParamSpec's own type holds
|
|
92
|
+
* NULL, which is a string, string-array, boxed, object, interface, param, variant or pointer
|
|
93
|
+
* property. Such a property holds the `null` either spelling wrote, so the member, the type's
|
|
94
|
+
* `get_property` slot and `g_object_get_property` serve the same thing, and writing the other
|
|
95
|
+
* spelling over it emits no `notify`. Every other property, so every integer, floating-point,
|
|
96
|
+
* boolean, enum, flags and GType one, refuses both with the same `TypeError` it refuses a
|
|
97
|
+
* string with, and keeps the value it already holds. It refuses them for what it holds rather
|
|
98
|
+
* than for its range, whatever that range is: the type is checked before the range, so a
|
|
99
|
+
* `gint` whose range excludes 0 answers a nullish with that same `TypeError` and never with
|
|
100
|
+
* the `RangeError` that names the value GObject would put in its place. The one place
|
|
101
|
+
* `undefined` means something else is the constructor, which reads it as the property not
|
|
102
|
+
* being given at all and leaves it at the ParamSpec's default, so a property is never handed a
|
|
103
|
+
* value it cannot serve back.
|
|
104
|
+
*
|
|
105
|
+
* A floating-point property takes every JavaScript number, `NaN` and both infinities
|
|
106
|
+
* included, and its ParamSpec alone rules on which of them the range admits: a `gdouble`
|
|
107
|
+
* bounded by `-Infinity` and `Infinity` holds either infinity, and a magnitude a bounded
|
|
108
|
+
* one excludes, like any `NaN`, comes back as the `RangeError` that names what GObject
|
|
109
|
+
* would put in its place rather than as the `TypeError` a type the property cannot hold
|
|
110
|
+
* earns. A `gfloat` property holds what GObject narrows the double to, so it serves `0.1`
|
|
111
|
+
* back as `0.10000000149011612` and a finite magnitude no `gfloat` reaches as an infinity,
|
|
112
|
+
* which the range then rules on in turn. That narrowing belongs to the property alone: the
|
|
113
|
+
* same magnitude written to a `gfloat` through a generated binding, a signal argument or a
|
|
114
|
+
* closure return is refused outright rather than narrowed.
|
|
115
|
+
*
|
|
116
|
+
* A generated property of a wrapped type answers a nullish differently, and the two halves of
|
|
117
|
+
* the API disagree here: that property marshals what it is written through its descriptor
|
|
118
|
+
* rather than through the checks above, so `new Gtk.Label({ widthRequest: null })` and a later
|
|
119
|
+
* write of `null` to that member both land 0, where a `gint` installed here refuses both.
|
|
120
|
+
*
|
|
121
|
+
* A class that defines the camelCase member itself owns the property: its own accessor decides
|
|
122
|
+
* what a write means, the other two spellings forward to it, and the type's property slots read
|
|
123
|
+
* and write it rather than the generated storage.
|
|
124
|
+
*/
|
|
125
|
+
properties?: TProperties;
|
|
13
126
|
};
|
|
14
127
|
/**
|
|
15
|
-
* Registers a subclass of a wrapper class as a new GType, wiring up any class and
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
128
|
+
* Registers a subclass of a wrapper class as a new GType, wiring up any class and interface
|
|
129
|
+
* virtual functions it overrides, both for the interfaces it inherits and for the ones
|
|
130
|
+
* `RegisterClassOptions.implements` names.
|
|
131
|
+
*
|
|
132
|
+
* Throws when the class does not extend a registered wrapper class, when it has no derivable type
|
|
133
|
+
* name, when an entry in `RegisterClassOptions.implements` is not a registered interface, when a
|
|
134
|
+
* listed interface has a prerequisite that neither the parent type nor another listed interface meets,
|
|
135
|
+
* and when an entry in `RegisterClassOptions.properties` names its `GObject.ParamSpec` something other
|
|
136
|
+
* than the canonical spelling of the key it sits under.
|
|
137
|
+
*
|
|
138
|
+
* A slot is filled from the `vfunc`-prefixed methods on the class's prototype chain, up to but not
|
|
139
|
+
* including the registered ancestor the class extends, so a method an intermediate base class
|
|
140
|
+
* declares fills a slot the same way one the class itself declares does. A slot nothing on that
|
|
141
|
+
* chain fills is left untouched.
|
|
142
|
+
*
|
|
143
|
+
* Declare every slot as a method: a class field holding a function, such as `vfuncGetNItems = () => 1`,
|
|
144
|
+
* is assigned to each instance after registration and never reaches the vtable.
|
|
145
|
+
*
|
|
146
|
+
* An override of `vfuncConstructed` runs from inside the base constructor, before JavaScript
|
|
147
|
+
* installs the subclass's field initializers and runs its constructor body, so a field still
|
|
148
|
+
* reads `undefined` there and reading a `#private` field throws. Declare state the override
|
|
149
|
+
* touches without an initializer, and assign private state from the constructor body after
|
|
150
|
+
* `super()`. An instance a native caller creates, through `GObject.newv` or `Gtk.Builder`,
|
|
151
|
+
* never runs the subclass constructor at all, so its declared fields stay uninitialized for
|
|
152
|
+
* the object's whole life.
|
|
19
153
|
*
|
|
20
154
|
* @param klass The subclass to register.
|
|
21
|
-
* @
|
|
155
|
+
* @param options What the new GType gains beyond the vtable slots the class overrides.
|
|
156
|
+
* @returns The same class, now registered, with every name in `options.properties` in its property map.
|
|
22
157
|
*/
|
|
23
|
-
declare function registerClass<T extends AnyClass>(klass: T, options?: RegisterClassOptions): T
|
|
24
|
-
export { registerClass };
|
|
158
|
+
declare function registerClass<T extends AnyClass, TProperties extends Record<string, PropertySpec> = Record<never, PropertySpec>>(klass: T, options?: RegisterClassOptions<T["prototype"], TProperties>): RegisteredClass<T, TProperties>;
|
|
159
|
+
export { type Interface, registerClass };
|
|
25
160
|
//# sourceMappingURL=register-class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-class.d.ts","sourceRoot":"","sources":["../src/register-class.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"register-class.d.ts","sourceRoot":"","sources":["../src/register-class.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,QAAQ,EAAkC,MAAM,aAAa,CAAC;AAG5E,OAAO,EAMH,KAAK,YAAY,EAGpB,MAAM,iBAAiB,CAAC;AAWzB;;;;;;;;;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,IAAI,CAAC;CACrD,CAAC;AAEF;;;GAGG;AACH,KAAK,MAAM,CAAC,KAAK,SAAS,MAAM,IAAI,KAAK,SAAS,GAAG,MAAM,KAAK,IAAI,MAAM,KAAK,EAAE,GAC3E,MAAM,CAAC,GAAG,KAAK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5G,KAAK,CAAC;AAEhB,0GAA0G;AAC1G,KAAK,oBAAoB,CAAC,SAAS,SAAS,MAAM,EAAE,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,IAAI;IACpG,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;IACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsDG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC;CAC5B,CAAC;AAwCF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,iBAAS,aAAa,CAClB,CAAC,SAAS,QAAQ,EAClB,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,EAChF,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;AAyU1G,OAAO,EAAE,KAAK,SAAS,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/register-class.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { registerClass as nativeRegisterClass, } from "@gtkx/native";
|
|
2
2
|
import { getParentClass, walkClassChain } from "@gtkx/utils";
|
|
3
3
|
import { wrapCallback } from "./callback.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
4
|
+
import { insertMixinLayer } from "./mixin.js";
|
|
5
|
+
import { buildPropertyDispatch, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, SET_PROPERTY_VFUNC, toNativeProperties, } from "./properties.js";
|
|
6
|
+
import { getClassType, getInterfaceMixin, markDerivedClass, registerClassType, } from "./registry.js";
|
|
7
|
+
import { TYPE_INTERFACE, TYPE_INVALID, typeFundamental, typeInterfaces, typeIsA } from "./type.js";
|
|
8
|
+
import { findClassVfuncDescriptor, findInterfaceVfuncDescriptor } from "./vfunc.js";
|
|
9
|
+
const INSTANCE_ARG_INDEX = 0;
|
|
8
10
|
const VALUE_ARG_INDEX = 2;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @param klass The subclass to register.
|
|
16
|
-
* @returns The same class, now registered.
|
|
17
|
-
*/
|
|
11
|
+
const TEARDOWN_VFUNC_NAMES = new Set(["dispose", "finalize"]);
|
|
12
|
+
const PROPERTY_VFUNC_SPECS = [
|
|
13
|
+
{ methodName: GET_PROPERTY_VFUNC, isValueOut: true, makeDispatch: makeGetProperty },
|
|
14
|
+
{ methodName: SET_PROPERTY_VFUNC, isValueOut: false, makeDispatch: makeSetProperty },
|
|
15
|
+
];
|
|
16
|
+
const PROPERTY_VFUNC_NAMES = new Set(PROPERTY_VFUNC_SPECS.map((spec) => spec.methodName));
|
|
18
17
|
function registerClass(klass, options = {}) {
|
|
19
18
|
const parentType = resolveParentType(klass);
|
|
20
19
|
if (parentType === TYPE_INVALID) {
|
|
@@ -24,35 +23,84 @@ function registerClass(klass, options = {}) {
|
|
|
24
23
|
if (!name) {
|
|
25
24
|
throw new Error("registerClass: cannot derive a GType name (anonymous class with no typeName option)");
|
|
26
25
|
}
|
|
26
|
+
const declaredTypes = resolveInterfaceTypes(klass, options.implements ?? []);
|
|
27
|
+
const adoptedTypes = declaredTypes.filter((gtype) => !typeIsA(parentType, gtype));
|
|
27
28
|
const properties = options.properties ?? {};
|
|
28
|
-
const
|
|
29
|
-
const
|
|
29
|
+
const { methods, inheritedNames } = collectInstanceMembers(klass);
|
|
30
|
+
const dispatch = buildPropertyDispatch({ klass, properties, adoptedTypes });
|
|
31
|
+
const classVfuncs = [
|
|
32
|
+
...discoverClassVfuncs(klass, methods),
|
|
33
|
+
...propertyVfuncs({ klass, methods, dispatch, adoptedTypes }),
|
|
34
|
+
];
|
|
30
35
|
const claimedMethodNames = new Set(classVfuncs.map((vfunc) => vfunc.methodName));
|
|
31
|
-
const interfaceBindings =
|
|
36
|
+
const interfaceBindings = discoverInterfaceBindings(methods, parentType, declaredTypes, claimedMethodNames);
|
|
32
37
|
const nativeOptions = toNativeOptions(classVfuncs, interfaceBindings, properties);
|
|
33
38
|
const newType = nativeRegisterClass(name, parentType, nativeOptions);
|
|
34
39
|
registerClassType(klass, newType);
|
|
40
|
+
markDerivedClass(klass);
|
|
41
|
+
applyInterfaceMixins(klass, adoptedTypes, inheritedNames);
|
|
35
42
|
return klass;
|
|
36
43
|
}
|
|
44
|
+
function resolveInterfaceType(klass, entry) {
|
|
45
|
+
const gtype = getClassType(entry);
|
|
46
|
+
if (typeFundamental(gtype) !== TYPE_INTERFACE) {
|
|
47
|
+
const label = typeof entry === "function" ? entry.name : String(entry);
|
|
48
|
+
throw new TypeError(`registerClass: ${klass.name} lists '${label}' in implements, which is not a registered interface`);
|
|
49
|
+
}
|
|
50
|
+
return gtype;
|
|
51
|
+
}
|
|
52
|
+
function resolveInterfaceTypes(klass, entries) {
|
|
53
|
+
return [...new Set(entries.map((entry) => resolveInterfaceType(klass, entry)))];
|
|
54
|
+
}
|
|
55
|
+
function applyInterfaceMixins(klass, adoptedTypes, inheritedNames) {
|
|
56
|
+
for (const gtype of adoptedTypes) {
|
|
57
|
+
const mixin = getInterfaceMixin(gtype);
|
|
58
|
+
if (mixin !== undefined) {
|
|
59
|
+
insertMixinLayer(klass, mixin, inheritedNames);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
37
63
|
function resolveParentType(klass) {
|
|
38
64
|
return (walkClassChain(getParentClass(klass), (cls) => {
|
|
39
65
|
const gtype = getClassType(cls);
|
|
40
66
|
return gtype === TYPE_INVALID ? undefined : gtype;
|
|
41
67
|
}) ?? TYPE_INVALID);
|
|
42
68
|
}
|
|
43
|
-
function
|
|
69
|
+
function addOwnMember(members, proto, name, isInherited) {
|
|
70
|
+
if (name === "constructor") {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (isInherited) {
|
|
74
|
+
members.inheritedNames.add(name);
|
|
75
|
+
}
|
|
76
|
+
if (members.names.has(name)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
members.names.add(name);
|
|
80
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
|
81
|
+
if (typeof descriptor?.value === "function") {
|
|
82
|
+
members.methods.set(name, descriptor.value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function addOwnMembers(members, klass, isInherited) {
|
|
44
86
|
const proto = klass.prototype;
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
87
|
+
if (proto === undefined) {
|
|
88
|
+
return;
|
|
47
89
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
90
|
+
for (const name of Object.getOwnPropertyNames(proto)) {
|
|
91
|
+
addOwnMember(members, proto, name, isInherited);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function collectInstanceMembers(klass) {
|
|
95
|
+
const members = { methods: new Map(), names: new Set(), inheritedNames: new Set() };
|
|
96
|
+
let cls = klass;
|
|
97
|
+
while (cls !== null && getClassType(cls) === TYPE_INVALID) {
|
|
98
|
+
addOwnMembers(members, cls, cls !== klass);
|
|
99
|
+
cls = getParentClass(cls);
|
|
100
|
+
}
|
|
101
|
+
return members;
|
|
54
102
|
}
|
|
55
|
-
function buildDiscoveredVfunc(
|
|
103
|
+
function buildDiscoveredVfunc(fn, methodName, resolveDescriptor, skip) {
|
|
56
104
|
if (skip?.has(methodName)) {
|
|
57
105
|
return undefined;
|
|
58
106
|
}
|
|
@@ -60,78 +108,69 @@ function buildDiscoveredVfunc(proto, methodName, resolveDescriptor, skip) {
|
|
|
60
108
|
if (!descriptor) {
|
|
61
109
|
return undefined;
|
|
62
110
|
}
|
|
63
|
-
const
|
|
64
|
-
if (!fn) {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
111
|
+
const argDescriptors = slotArgDescriptors(descriptor);
|
|
67
112
|
return {
|
|
68
113
|
...descriptor,
|
|
69
114
|
methodName,
|
|
70
|
-
|
|
115
|
+
argDescriptors,
|
|
116
|
+
fn: wrapVfunc(fn, argDescriptors, descriptor),
|
|
71
117
|
};
|
|
72
118
|
}
|
|
73
|
-
function collectDiscoveredVfuncs(
|
|
74
|
-
const proto = klass.prototype;
|
|
119
|
+
function collectDiscoveredVfuncs(methods, resolveDescriptor, skip) {
|
|
75
120
|
const result = [];
|
|
76
|
-
for (const methodName of
|
|
77
|
-
const discovered = buildDiscoveredVfunc(
|
|
121
|
+
for (const [methodName, fn] of methods) {
|
|
122
|
+
const discovered = buildDiscoveredVfunc(fn, methodName, resolveDescriptor, skip);
|
|
78
123
|
if (discovered) {
|
|
79
124
|
result.push(discovered);
|
|
80
125
|
}
|
|
81
126
|
}
|
|
82
127
|
return result;
|
|
83
128
|
}
|
|
84
|
-
function discoverClassVfuncs(klass) {
|
|
85
|
-
return collectDiscoveredVfuncs(
|
|
86
|
-
const descriptor = findClassVfuncDescriptor(klass, methodName);
|
|
87
|
-
if (descriptor && UNSUPPORTED_CONSTRUCT_VFUNCS.has(methodName)) {
|
|
88
|
-
throw new Error(`registerClass: overriding the GObject construct-time vtable slot '${methodName}' is not ` +
|
|
89
|
-
"supported; run construct-time initialization in the subclass constructor, after " +
|
|
90
|
-
"super(...), instead");
|
|
91
|
-
}
|
|
92
|
-
return descriptor ?? undefined;
|
|
93
|
-
});
|
|
129
|
+
function discoverClassVfuncs(klass, methods) {
|
|
130
|
+
return collectDiscoveredVfuncs(methods, (methodName) => findClassVfuncDescriptor(klass, methodName) ?? undefined, PROPERTY_VFUNC_NAMES);
|
|
94
131
|
}
|
|
95
|
-
function wrapVfunc(fn, argDescriptors,
|
|
96
|
-
return wrapCallback(fn, { argDescriptors, returnDescriptor }, "
|
|
132
|
+
function wrapVfunc(fn, argDescriptors, descriptor) {
|
|
133
|
+
return wrapCallback(fn, { argDescriptors, returnDescriptor: descriptor.returnDescriptor }, "vfunc");
|
|
97
134
|
}
|
|
98
|
-
function
|
|
135
|
+
function discoverInterfaceBindings(methods, parentGtype, declaredTypes, claimedMethodNames) {
|
|
136
|
+
const declared = new Set(declaredTypes);
|
|
137
|
+
const gtypes = new Set([...typeInterfaces(parentGtype), ...declaredTypes]);
|
|
99
138
|
const bindings = [];
|
|
100
|
-
for (const
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
bindings.push({ gtype
|
|
139
|
+
for (const gtype of gtypes) {
|
|
140
|
+
const vfuncs = discoverInterfaceVfuncs(methods, gtype, claimedMethodNames);
|
|
141
|
+
if (vfuncs.length > 0 || declared.has(gtype)) {
|
|
142
|
+
bindings.push({ gtype, vfuncs });
|
|
104
143
|
}
|
|
105
144
|
}
|
|
106
145
|
return bindings;
|
|
107
146
|
}
|
|
108
|
-
function discoverInterfaceVfuncs(
|
|
109
|
-
|
|
110
|
-
if (!vfuncRegistry) {
|
|
111
|
-
return [];
|
|
112
|
-
}
|
|
113
|
-
return collectDiscoveredVfuncs(klass, (methodName) => {
|
|
114
|
-
const entry = vfuncRegistry[methodName];
|
|
115
|
-
return entry?.kind === "interface" ? entry : undefined;
|
|
116
|
-
}, claimedMethodNames);
|
|
147
|
+
function discoverInterfaceVfuncs(methods, interfaceGtype, claimedMethodNames) {
|
|
148
|
+
return collectDiscoveredVfuncs(methods, (methodName) => findInterfaceVfuncDescriptor(interfaceGtype, methodName), claimedMethodNames);
|
|
117
149
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
150
|
+
const hasDispatchedProperties = (dispatch, adoptedTypes) => dispatch.accessors.length > 0 || adoptedTypes.length > 0;
|
|
151
|
+
function propertyVfuncFor(source, spec) {
|
|
152
|
+
const { klass, methods, dispatch, adoptedTypes } = source;
|
|
153
|
+
const dispatched = hasDispatchedProperties(dispatch, adoptedTypes)
|
|
154
|
+
? spec.makeDispatch(dispatch)
|
|
155
|
+
: undefined;
|
|
156
|
+
const fn = methods.get(spec.methodName) ?? dispatched;
|
|
157
|
+
return fn === undefined ? undefined : buildPropertyVfunc(klass, spec.methodName, fn, spec.isValueOut);
|
|
123
158
|
}
|
|
124
|
-
function propertyVfuncs(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return
|
|
129
|
-
buildPropertyVfunc(klass, "getProperty", makeGetProperty(accessors), true),
|
|
130
|
-
buildPropertyVfunc(klass, "setProperty", makeSetProperty(accessors), false),
|
|
131
|
-
];
|
|
159
|
+
function propertyVfuncs(source) {
|
|
160
|
+
return PROPERTY_VFUNC_SPECS.map((spec) => propertyVfuncFor(source, spec)).filter((vfunc) => vfunc !== undefined);
|
|
161
|
+
}
|
|
162
|
+
function markArg(argDescriptors, index, patch) {
|
|
163
|
+
return argDescriptors.map((arg, at) => (at === index ? { ...arg, ...patch } : arg));
|
|
132
164
|
}
|
|
133
|
-
function
|
|
134
|
-
return
|
|
165
|
+
function isTeardownSlot(descriptor) {
|
|
166
|
+
return (TEARDOWN_VFUNC_NAMES.has(descriptor.vfuncName) &&
|
|
167
|
+
descriptor.argDescriptors[INSTANCE_ARG_INDEX]?.kind === "object");
|
|
168
|
+
}
|
|
169
|
+
function slotArgDescriptors(descriptor) {
|
|
170
|
+
if (!isTeardownSlot(descriptor)) {
|
|
171
|
+
return descriptor.argDescriptors;
|
|
172
|
+
}
|
|
173
|
+
return markArg(descriptor.argDescriptors, INSTANCE_ARG_INDEX, { isCallScoped: true });
|
|
135
174
|
}
|
|
136
175
|
function buildPropertyVfunc(klass, methodName, fn, isValueOut) {
|
|
137
176
|
const descriptor = findClassVfuncDescriptor(klass, methodName);
|
|
@@ -139,15 +178,26 @@ function buildPropertyVfunc(klass, methodName, fn, isValueOut) {
|
|
|
139
178
|
throw new Error(`registerClass: the parent class exposes no '${methodName}' vtable slot`);
|
|
140
179
|
}
|
|
141
180
|
const argDescriptors = isValueOut
|
|
142
|
-
?
|
|
181
|
+
? markArg(descriptor.argDescriptors, VALUE_ARG_INDEX, { isCallerAllocated: true })
|
|
143
182
|
: descriptor.argDescriptors;
|
|
144
183
|
return {
|
|
145
184
|
...descriptor,
|
|
146
185
|
methodName,
|
|
147
186
|
argDescriptors,
|
|
148
|
-
fn: wrapVfunc(fn, argDescriptors, descriptor
|
|
187
|
+
fn: wrapVfunc(fn, argDescriptors, descriptor),
|
|
149
188
|
};
|
|
150
189
|
}
|
|
190
|
+
function toNativeInterface(binding) {
|
|
191
|
+
const nativeInterface = {
|
|
192
|
+
type: binding.gtype,
|
|
193
|
+
vfuncs: [...binding.vfuncs],
|
|
194
|
+
};
|
|
195
|
+
const vtableSize = binding.vfuncs[0]?.vtableSize;
|
|
196
|
+
if (vtableSize !== undefined) {
|
|
197
|
+
nativeInterface.vtableSize = vtableSize;
|
|
198
|
+
}
|
|
199
|
+
return nativeInterface;
|
|
200
|
+
}
|
|
151
201
|
function toNativeOptions(classVfuncs, interfaceBindings, properties) {
|
|
152
202
|
const hasInterfaces = interfaceBindings.length > 0;
|
|
153
203
|
const hasClassVfuncs = classVfuncs.length > 0;
|
|
@@ -163,11 +213,7 @@ function toNativeOptions(classVfuncs, interfaceBindings, properties) {
|
|
|
163
213
|
options.vfuncs = [...classVfuncs];
|
|
164
214
|
}
|
|
165
215
|
if (hasInterfaces) {
|
|
166
|
-
options.interfaces = interfaceBindings.map((binding) => (
|
|
167
|
-
type: binding.gtype,
|
|
168
|
-
vtableSize: binding.vtableSize,
|
|
169
|
-
vfuncs: [...binding.vfuncs],
|
|
170
|
-
}));
|
|
216
|
+
options.interfaces = interfaceBindings.map((binding) => toNativeInterface(binding));
|
|
171
217
|
}
|
|
172
218
|
return options;
|
|
173
219
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register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,CAAC,UAAU;YAC9B,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;SAC9B,CAAC,CAAC,CAAC;IACR,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import type { Descriptor } from \"@gtkx/native\";\nimport {\n registerClass as nativeRegisterClass,\n type RegisterClassOptions as NativeRegisterClassOptions,\n type RegisterClassVfunc as NativeRegisterClassVfunc,\n} from \"@gtkx/native\";\nimport { type AnyClass, getParentClass, walkClassChain } from \"@gtkx/utils\";\nimport { wrapCallback } from \"./callback.js\";\nimport {\n buildAccessors,\n makeGetProperty,\n makeSetProperty,\n type PropertyAccessor,\n type PropertySpec,\n toNativeProperties,\n} from \"./properties.js\";\nimport {\n getClassType,\n getInterfaceVfuncRegistry,\n getVfuncRegistry,\n registerClassType,\n type VfuncDescriptor,\n} from \"./registry.js\";\nimport { TYPE_INVALID, typeInterfaces } from \"./type.js\";\n\n/** What {@link registerClass} adds to the new GType beyond the vtable slots it discovers on the class. */\ntype RegisterClassOptions = {\n /** Name to register the new GType under, defaulting to the class's own name. */\n typeName?: string;\n /**\n * Properties to install on the new type, keyed by canonical name and valued with the\n * `GObject.ParamSpec` describing each. Every property gains dashed, underscored and camelCased\n * prototype accessors that emit `notify` on write, unless the class already defines that name.\n */\n properties?: Record<string, PropertySpec>;\n};\n\ntype VfuncFn = NativeRegisterClassVfunc[\"fn\"];\ntype DiscoveredVfunc<K extends \"class\" | \"interface\"> = VfuncDescriptor<K> & { methodName: string; fn: VfuncFn };\ntype DiscoveredClassVfunc = DiscoveredVfunc<\"class\">;\ntype DiscoveredInterfaceVfunc = DiscoveredVfunc<\"interface\">;\ntype InterfaceVfuncBinding = { gtype: bigint; vtableSize: number; vfuncs: DiscoveredInterfaceVfunc[] };\n\nconst UNSUPPORTED_CONSTRUCT_VFUNCS: Set<string> = new Set([\"constructed\", \"setProperty\", \"getProperty\"]);\nconst VALUE_ARG_INDEX = 2;\n\n/**\n * Registers a subclass of a wrapper class as a new GType, wiring up any class and\n * inherited-interface virtual functions it overrides. Throws if the class does not\n * extend a registered wrapper class, has no derivable type name, or overrides an\n * unsupported construct-time vtable slot.\n *\n * @param klass The subclass to register.\n * @returns The same class, now registered.\n */\nfunction registerClass<T extends AnyClass>(klass: T, options: RegisterClassOptions = {}): T {\n const parentType = resolveParentType(klass);\n\n if (parentType === TYPE_INVALID) {\n throw new TypeError(`registerClass: ${klass.name} must extend a registered wrapper class`);\n }\n\n const name = options.typeName ?? klass.name;\n\n if (!name) {\n throw new Error(\"registerClass: cannot derive a GType name (anonymous class with no typeName option)\");\n }\n\n const properties = options.properties ?? {};\n const accessors = buildAccessors(klass, properties);\n const classVfuncs = [...discoverClassVfuncs(klass), ...propertyVfuncs(klass, accessors)];\n const claimedMethodNames = new Set(classVfuncs.map((vfunc) => vfunc.methodName));\n const interfaceBindings = discoverInheritedInterfaceVfuncs(klass, parentType, claimedMethodNames);\n const nativeOptions = toNativeOptions(classVfuncs, interfaceBindings, properties);\n const newType: bigint = nativeRegisterClass(name, parentType, nativeOptions);\n registerClassType(klass, newType);\n\n return klass;\n}\n\nfunction resolveParentType(klass: AnyClass): bigint {\n return (\n walkClassChain(getParentClass(klass), (cls) => {\n const gtype = getClassType(cls);\n\n return gtype === TYPE_INVALID ? undefined : gtype;\n }) ?? TYPE_INVALID\n );\n}\n\nfunction ownInstanceMethodNames(klass: AnyClass): string[] {\n const proto = (klass as { prototype?: object }).prototype;\n\n if (!proto) {\n return [];\n }\n\n return Object.getOwnPropertyNames(proto).filter((name) => {\n if (name === \"constructor\") {\n return false;\n }\n\n return typeof Object.getOwnPropertyDescriptor(proto, name)?.value === \"function\";\n });\n}\n\nfunction buildDiscoveredVfunc<K extends \"class\" | \"interface\">(\n proto: Record<string, VfuncFn>,\n methodName: string,\n resolveDescriptor: (methodName: string) => VfuncDescriptor<K> | undefined,\n skip: Set<string> | undefined,\n): DiscoveredVfunc<K> | undefined {\n if (skip?.has(methodName)) {\n return undefined;\n }\n\n const descriptor = resolveDescriptor(methodName);\n\n if (!descriptor) {\n return undefined;\n }\n\n const fn = proto[methodName];\n\n if (!fn) {\n return undefined;\n }\n\n return {\n ...descriptor,\n methodName,\n fn: wrapVfunc(fn, descriptor.argDescriptors, descriptor.returnDescriptor),\n };\n}\n\nfunction collectDiscoveredVfuncs<K extends \"class\" | \"interface\">(\n klass: AnyClass,\n resolveDescriptor: (methodName: string) => VfuncDescriptor<K> | undefined,\n skip?: Set<string>,\n): DiscoveredVfunc<K>[] {\n const proto = (klass as { prototype: Record<string, VfuncFn> }).prototype;\n const result: DiscoveredVfunc<K>[] = [];\n\n for (const methodName of ownInstanceMethodNames(klass)) {\n const discovered = buildDiscoveredVfunc(proto, methodName, resolveDescriptor, skip);\n\n if (discovered) {\n result.push(discovered);\n }\n }\n\n return result;\n}\n\nfunction discoverClassVfuncs(klass: AnyClass): DiscoveredClassVfunc[] {\n return collectDiscoveredVfuncs(klass, (methodName) => {\n const descriptor = findClassVfuncDescriptor(klass, methodName);\n\n if (descriptor && UNSUPPORTED_CONSTRUCT_VFUNCS.has(methodName)) {\n throw new Error(\n `registerClass: overriding the GObject construct-time vtable slot '${methodName}' is not ` +\n \"supported; run construct-time initialization in the subclass constructor, after \" +\n \"super(...), instead\",\n );\n }\n\n return descriptor ?? undefined;\n });\n}\n\nfunction wrapVfunc(\n fn: VfuncFn,\n argDescriptors: NativeRegisterClassVfunc[\"argDescriptors\"],\n returnDescriptor: NativeRegisterClassVfunc[\"returnDescriptor\"],\n): VfuncFn {\n return wrapCallback(fn as (...args: unknown[]) => unknown, { argDescriptors, returnDescriptor }, \"this\");\n}\n\nfunction discoverInheritedInterfaceVfuncs(\n klass: AnyClass,\n parentGtype: bigint,\n claimedMethodNames: Set<string>,\n): InterfaceVfuncBinding[] {\n const bindings: InterfaceVfuncBinding[] = [];\n\n for (const interfaceGtype of typeInterfaces(parentGtype)) {\n const [first, ...rest] = discoverInterfaceVfuncs(klass, interfaceGtype, claimedMethodNames);\n\n if (first !== undefined) {\n bindings.push({ gtype: interfaceGtype, vtableSize: first.vtableSize, vfuncs: [first, ...rest] });\n }\n }\n\n return bindings;\n}\n\nfunction discoverInterfaceVfuncs(\n klass: AnyClass,\n interfaceGtype: bigint,\n claimedMethodNames: Set<string>,\n): DiscoveredInterfaceVfunc[] {\n const vfuncRegistry = getInterfaceVfuncRegistry(interfaceGtype);\n\n if (!vfuncRegistry) {\n return [];\n }\n\n return collectDiscoveredVfuncs(\n klass,\n (methodName) => {\n const entry = vfuncRegistry[methodName];\n\n return entry?.kind === \"interface\" ? entry : undefined;\n },\n claimedMethodNames,\n );\n}\n\nfunction findClassVfuncDescriptor(klass: AnyClass, methodName: string): VfuncDescriptor<\"class\"> | null {\n return (\n walkClassChain(getParentClass(klass), (cls) => {\n const entry = getVfuncRegistry(cls)?.[methodName];\n\n return entry?.kind === \"class\" ? entry : undefined;\n }) ?? null\n );\n}\n\nfunction propertyVfuncs(klass: AnyClass, accessors: PropertyAccessor[]): DiscoveredClassVfunc[] {\n if (accessors.length === 0) {\n return [];\n }\n\n return [\n buildPropertyVfunc(klass, \"getProperty\", makeGetProperty(accessors), true),\n buildPropertyVfunc(klass, \"setProperty\", makeSetProperty(accessors), false),\n ];\n}\n\nfunction markValueCallerAllocated(argDescriptors: Descriptor[]): Descriptor[] {\n return argDescriptors.map((arg, index) =>\n index === VALUE_ARG_INDEX ? { ...arg, isCallerAllocated: true } : arg);\n}\n\nfunction buildPropertyVfunc(\n klass: AnyClass,\n methodName: string,\n fn: VfuncFn,\n isValueOut: boolean,\n): DiscoveredClassVfunc {\n const descriptor = findClassVfuncDescriptor(klass, methodName);\n\n if (!descriptor) {\n throw new Error(`registerClass: the parent class exposes no '${methodName}' vtable slot`);\n }\n\n const argDescriptors = isValueOut\n ? markValueCallerAllocated(descriptor.argDescriptors)\n : descriptor.argDescriptors;\n\n return {\n ...descriptor,\n methodName,\n argDescriptors,\n fn: wrapVfunc(fn, argDescriptors, descriptor.returnDescriptor),\n };\n}\n\nfunction toNativeOptions(\n classVfuncs: DiscoveredClassVfunc[],\n interfaceBindings: InterfaceVfuncBinding[],\n properties: Record<string, PropertySpec>,\n): NativeRegisterClassOptions | undefined {\n const hasInterfaces = interfaceBindings.length > 0;\n const hasClassVfuncs = classVfuncs.length > 0;\n const hasProperties = Object.keys(properties).length > 0;\n\n if (!hasClassVfuncs && !hasInterfaces && !hasProperties) {\n return undefined;\n }\n\n const options: NativeRegisterClassOptions = {};\n\n if (hasProperties) {\n options.properties = toNativeProperties(properties);\n }\n\n if (hasClassVfuncs) {\n options.vfuncs = [...classVfuncs];\n }\n\n if (hasInterfaces) {\n options.interfaces = interfaceBindings.map((binding) => ({\n type: binding.gtype,\n vtableSize: binding.vtableSize,\n vfuncs: [...binding.vfuncs],\n }));\n }\n\n return options;\n}\n\nexport { registerClass };\n"]}
|
|
1
|
+
{"version":3,"file":"register-class.js","sourceRoot":"","sources":["../src/register-class.ts"],"names":[],"mappings":"AACA,OAAO,EACH,aAAa,IAAI,mBAAmB,GAIvC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAiB,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACH,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,eAAe,EAGf,kBAAkB,EAClB,kBAAkB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACH,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAEpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnG,OAAO,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;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CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzD,IAAI,CAAC,cAAc,IAAI,CAAC,aAAa,IAAI,CAAC,aAAa,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,MAAM,OAAO,GAA+B,EAAE,CAAC;IAE/C,IAAI,aAAa,EAAE,CAAC;QAChB,OAAO,CAAC,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,cAAc,EAAE,CAAC;QACjB,OAAO,CAAC,MAAM,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAChB,OAAO,CAAC,UAAU,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxF,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,OAAO,EAAkB,aAAa,EAAE,CAAC","sourcesContent":["import type { Descriptor } from \"@gtkx/native\";\nimport {\n registerClass as nativeRegisterClass,\n type RegisterClassInterface as NativeRegisterClassInterface,\n type RegisterClassOptions as NativeRegisterClassOptions,\n type RegisterClassVfunc as NativeRegisterClassVfunc,\n} from \"@gtkx/native\";\nimport { type AnyClass, getParentClass, walkClassChain } from \"@gtkx/utils\";\nimport { wrapCallback } from \"./callback.js\";\nimport { insertMixinLayer } from \"./mixin.js\";\nimport {\n buildPropertyDispatch,\n GET_PROPERTY_VFUNC,\n makeGetProperty,\n makeSetProperty,\n type PropertyDispatch,\n type PropertySpec,\n SET_PROPERTY_VFUNC,\n toNativeProperties,\n} from \"./properties.js\";\nimport {\n getClassType,\n getInterfaceMixin,\n markDerivedClass,\n registerClassType,\n type VfuncDescriptor,\n} from \"./registry.js\";\nimport { TYPE_INTERFACE, TYPE_INVALID, typeFundamental, typeInterfaces, typeIsA } from \"./type.js\";\nimport { findClassVfuncDescriptor, findInterfaceVfuncDescriptor } from \"./vfunc.js\";\n\n/**\n * A generated interface value, such as `Gio.ListModel`, in the form {@link registerClass} takes it.\n * `__impl__` exists only in the type system: it carries the interface's `Impl` type, of which a class\n * has to match every member it declares itself, which rejects a class value and a member whose\n * signature does not fit the slot it fills. Leaving a slot to the interface is not rejected,\n * because `registerClass` does not reject it either: every member of an `Impl` type is optional,\n * and the `Partial` holds that open whatever the type declares. The `object` beside it keeps\n * TypeScript from also demanding one member in common. An interface that introspection describes\n * no vtable for carries `unknown`, since it has no slot a class could fill.\n */\ntype Interface<TImpl> = AnyClass & {\n /** Type-level slot holding the interface's `Impl` type; no value ever carries it. */\n __impl__: (impl: Partial<TImpl> & object) => void;\n};\n\n/**\n * One key of `RegisterClassOptions.properties` with every underscore turned into the dash a canonical\n * GObject property name separates its words with.\n */\ntype Dashed<TName extends string> = TName extends `${infer THead}_${infer TTail}`\n ? Dashed<`${THead}-${TTail}`>\n : TName;\n\n/**\n * One dashed key in the camelCase spelling the accessors {@link registerClass} installs carry, which is\n * the spelling the hooks that address a property by name take.\n */\ntype Camelized<TName extends string> = TName extends `${infer THead}-${infer TTail}`\n ? `${THead}${Capitalize<Camelized<TTail>>}`\n : TName;\n\n/**\n * The names a registered class carries in its property map: every key of\n * `RegisterClassOptions.properties` in camelCase, whichever of the three spellings it was written in.\n * A `properties` object given a type of its own rather than left to inference has `string` for its key\n * type and names nothing, because a name only known as `string` addresses no member in particular.\n */\ntype InstalledNames<TProperties> = string extends keyof TProperties\n ? never\n : Camelized<Dashed<keyof TProperties & string>>;\n\n/**\n * An instance of a registered class: everything the class itself declares, plus the property map the\n * hooks that address a property by name, such as `useProperty` from `@gtkx/react`, read the installed\n * names off. Each name is typed with the value type the class declares for the member of that name,\n * so a property the class does not `declare` contributes nothing.\n */\ntype RegisteredInstance<TInstance, TProperties> = TInstance & {\n /** Type-level map from installed property name to value type; no value ever carries it. */\n __properties__: Pick<TInstance, InstalledNames<TProperties> & keyof TInstance>;\n};\n\n/**\n * The construct signature and prototype a registered class carries, both giving\n * {@link RegisteredInstance}. The signature stays abstract for as long as the class itself is, so\n * registering an abstract base leaves it as impossible to construct as it was.\n */\ntype RegisteredConstructor<TClass, TArgs extends unknown[], TInstance> = {\n /** Object the class's instances inherit from. */\n prototype: TInstance;\n} & (TClass extends new (...args: never) => unknown\n ? new (...args: TArgs) => TInstance\n : abstract new (...args: TArgs) => TInstance);\n\n/**\n * The class {@link registerClass} hands back: the same class, with the same statics, whose instances\n * carry the properties `RegisterClassOptions.properties` installed. Binding the call to a name, rather\n * than discarding it, is what carries those names into the type system.\n */\ntype RegisteredClass<TClass extends AnyClass, TProperties> =\n TClass extends abstract new (...args: infer TArgs) => infer TInstance\n ? Omit<TClass, \"prototype\"> & RegisteredConstructor<TClass, TArgs, RegisteredInstance<TInstance, TProperties>>\n : never;\n\n/** What {@link registerClass} adds to the new GType beyond the vtable slots it discovers on the class. */\ntype RegisterClassOptions<TInstance extends object, TProperties extends Record<string, PropertySpec>> = {\n /** Name to register the new GType under, defaulting to the class's own name. */\n typeName?: string;\n /**\n * Interfaces the new type implements on top of the ones it inherits, given as the interface values\n * themselves, such as `Gio.ListModel`. Their vtable slots are filled from the `vfunc`-prefixed methods on\n * the class's prototype chain, each of which has to match the interface's `Impl` type, such as\n * `Gio.ListModelImpl`.\n */\n implements?: Interface<TInstance>[];\n /**\n * Properties to install on the new type, keyed by the name JavaScript addresses each one by and\n * valued with the `GObject.ParamSpec` describing it. A key is read in camelCase however it is\n * written, so `dewPoint`, `dew_point` and `dew-point` all name the same member, and the ParamSpec\n * has to carry the canonical spelling of that name, `dew-point`, or registration throws: the\n * ParamSpec's name is the one GObject emits `notify` with, and a name the key does not spell\n * reaches nothing that listens for it. Every property gains prototype accessors, one for the key\n * as written, one for it with dashes turned into underscores and one for it in camelCase, each\n * unless the class already defines that name. They serve the value from storage of their own on\n * the instance, which is also what the type's `get_property` and `set_property` slots read and\n * write, so a value set from JavaScript, from `g_object_set_property` and at construction all\n * land in the same place.\n *\n * A write the ParamSpec would refuse throws rather than reaching GObject, which reports such a\n * write as a GLib critical and drops it: a `TypeError` for a read-only or construct-only\n * property and for a value of a type the property cannot hold, and a `RangeError` for a value\n * the ParamSpec rejects. The same two checks run over a value handed to the constructor, where\n * a construct-only property is the one that is writable. An accepted write emits one `notify`,\n * which a `freeze_notify` batch collects; a write of the value the property already holds is\n * dropped and emits none.\n *\n * `null` and `undefined` both mean NULL, and mean it only where the ParamSpec's own type holds\n * NULL, which is a string, string-array, boxed, object, interface, param, variant or pointer\n * property. Such a property holds the `null` either spelling wrote, so the member, the type's\n * `get_property` slot and `g_object_get_property` serve the same thing, and writing the other\n * spelling over it emits no `notify`. Every other property, so every integer, floating-point,\n * boolean, enum, flags and GType one, refuses both with the same `TypeError` it refuses a\n * string with, and keeps the value it already holds. It refuses them for what it holds rather\n * than for its range, whatever that range is: the type is checked before the range, so a\n * `gint` whose range excludes 0 answers a nullish with that same `TypeError` and never with\n * the `RangeError` that names the value GObject would put in its place. The one place\n * `undefined` means something else is the constructor, which reads it as the property not\n * being given at all and leaves it at the ParamSpec's default, so a property is never handed a\n * value it cannot serve back.\n *\n * A floating-point property takes every JavaScript number, `NaN` and both infinities\n * included, and its ParamSpec alone rules on which of them the range admits: a `gdouble`\n * bounded by `-Infinity` and `Infinity` holds either infinity, and a magnitude a bounded\n * one excludes, like any `NaN`, comes back as the `RangeError` that names what GObject\n * would put in its place rather than as the `TypeError` a type the property cannot hold\n * earns. A `gfloat` property holds what GObject narrows the double to, so it serves `0.1`\n * back as `0.10000000149011612` and a finite magnitude no `gfloat` reaches as an infinity,\n * which the range then rules on in turn. That narrowing belongs to the property alone: the\n * same magnitude written to a `gfloat` through a generated binding, a signal argument or a\n * closure return is refused outright rather than narrowed.\n *\n * A generated property of a wrapped type answers a nullish differently, and the two halves of\n * the API disagree here: that property marshals what it is written through its descriptor\n * rather than through the checks above, so `new Gtk.Label({ widthRequest: null })` and a later\n * write of `null` to that member both land 0, where a `gint` installed here refuses both.\n *\n * A class that defines the camelCase member itself owns the property: its own accessor decides\n * what a write means, the other two spellings forward to it, and the type's property slots read\n * and write it rather than the generated storage.\n */\n properties?: TProperties;\n};\n\n/** {@link RegisterClassOptions} with the widest instance and property types {@link registerClass} accepts. */\ntype AnyRegisterClassOptions = RegisterClassOptions<object, Record<string, PropertySpec>>;\ntype VfuncFn = NativeRegisterClassVfunc[\"fn\"];\ntype DiscoveredVfunc = VfuncDescriptor & { methodName: string; fn: VfuncFn };\ntype MethodTable = Map<string, VfuncFn>;\ntype InstanceMembers = { methods: MethodTable; names: Set<string>; inheritedNames: Set<string> };\n\ntype InterfaceVfuncBinding = {\n gtype: bigint;\n vfuncs: DiscoveredVfunc[];\n};\n\ntype PropertyVfuncSource = {\n klass: AnyClass;\n methods: MethodTable;\n dispatch: PropertyDispatch;\n adoptedTypes: bigint[];\n};\n\ntype PropertyVfuncSpec = {\n methodName: string;\n isValueOut: boolean;\n makeDispatch: (dispatch: PropertyDispatch) => VfuncFn;\n};\n\ntype ArgPatch = { isCallerAllocated: true } | { isCallScoped: true };\n\nconst INSTANCE_ARG_INDEX = 0;\nconst VALUE_ARG_INDEX = 2;\nconst TEARDOWN_VFUNC_NAMES: Set<string> = new Set([\"dispose\", \"finalize\"]);\n\nconst PROPERTY_VFUNC_SPECS: PropertyVfuncSpec[] = [\n { methodName: GET_PROPERTY_VFUNC, isValueOut: true, makeDispatch: makeGetProperty },\n { methodName: SET_PROPERTY_VFUNC, isValueOut: false, makeDispatch: makeSetProperty },\n];\n\nconst PROPERTY_VFUNC_NAMES: Set<string> = new Set(PROPERTY_VFUNC_SPECS.map((spec) => spec.methodName));\n\n/**\n * Registers a subclass of a wrapper class as a new GType, wiring up any class and interface\n * virtual functions it overrides, both for the interfaces it inherits and for the ones\n * `RegisterClassOptions.implements` names.\n *\n * Throws when the class does not extend a registered wrapper class, when it has no derivable type\n * name, when an entry in `RegisterClassOptions.implements` is not a registered interface, when a\n * listed interface has a prerequisite that neither the parent type nor another listed interface meets,\n * and when an entry in `RegisterClassOptions.properties` names its `GObject.ParamSpec` something other\n * than the canonical spelling of the key it sits under.\n *\n * A slot is filled from the `vfunc`-prefixed methods on the class's prototype chain, up to but not\n * including the registered ancestor the class extends, so a method an intermediate base class\n * declares fills a slot the same way one the class itself declares does. A slot nothing on that\n * chain fills is left untouched.\n *\n * Declare every slot as a method: a class field holding a function, such as `vfuncGetNItems = () => 1`,\n * is assigned to each instance after registration and never reaches the vtable.\n *\n * An override of `vfuncConstructed` runs from inside the base constructor, before JavaScript\n * installs the subclass's field initializers and runs its constructor body, so a field still\n * reads `undefined` there and reading a `#private` field throws. Declare state the override\n * touches without an initializer, and assign private state from the constructor body after\n * `super()`. An instance a native caller creates, through `GObject.newv` or `Gtk.Builder`,\n * never runs the subclass constructor at all, so its declared fields stay uninitialized for\n * the object's whole life.\n *\n * @param klass The subclass to register.\n * @param options What the new GType gains beyond the vtable slots the class overrides.\n * @returns The same class, now registered, with every name in `options.properties` in its property map.\n */\nfunction registerClass<\n T extends AnyClass,\n TProperties extends Record<string, PropertySpec> = Record<never, PropertySpec>,\n>(klass: T, options?: RegisterClassOptions<T[\"prototype\"], TProperties>): RegisteredClass<T, TProperties>;\n\nfunction registerClass(klass: AnyClass, options: AnyRegisterClassOptions = {}): AnyClass {\n const parentType = resolveParentType(klass);\n\n if (parentType === TYPE_INVALID) {\n throw new TypeError(`registerClass: ${klass.name} must extend a registered wrapper class`);\n }\n\n const name = options.typeName ?? klass.name;\n\n if (!name) {\n throw new Error(\"registerClass: cannot derive a GType name (anonymous class with no typeName option)\");\n }\n\n const declaredTypes = resolveInterfaceTypes(klass, options.implements ?? []);\n const adoptedTypes = declaredTypes.filter((gtype) => !typeIsA(parentType, gtype));\n const properties = options.properties ?? {};\n const { methods, inheritedNames } = collectInstanceMembers(klass);\n const dispatch = buildPropertyDispatch({ klass, properties, adoptedTypes });\n\n const classVfuncs = [\n ...discoverClassVfuncs(klass, methods),\n ...propertyVfuncs({ klass, methods, dispatch, adoptedTypes }),\n ];\n\n const claimedMethodNames = new Set(classVfuncs.map((vfunc) => vfunc.methodName));\n const interfaceBindings = discoverInterfaceBindings(methods, parentType, declaredTypes, claimedMethodNames);\n const nativeOptions = toNativeOptions(classVfuncs, interfaceBindings, properties);\n const newType: bigint = nativeRegisterClass(name, parentType, nativeOptions);\n registerClassType(klass, newType);\n markDerivedClass(klass);\n applyInterfaceMixins(klass, adoptedTypes, inheritedNames);\n\n return klass;\n}\n\nfunction resolveInterfaceType(klass: AnyClass, entry: AnyClass): bigint {\n const gtype = getClassType(entry);\n\n if (typeFundamental(gtype) !== TYPE_INTERFACE) {\n const label = typeof entry === \"function\" ? entry.name : String(entry);\n\n throw new TypeError(\n `registerClass: ${klass.name} lists '${label}' in implements, which is not a registered interface`,\n );\n }\n\n return gtype;\n}\n\nfunction resolveInterfaceTypes(klass: AnyClass, entries: AnyClass[]): bigint[] {\n return [...new Set(entries.map((entry) => resolveInterfaceType(klass, entry)))];\n}\n\nfunction applyInterfaceMixins(klass: AnyClass, adoptedTypes: bigint[], inheritedNames: Set<string>): void {\n for (const gtype of adoptedTypes) {\n const mixin = getInterfaceMixin(gtype);\n\n if (mixin !== undefined) {\n insertMixinLayer(klass, mixin, inheritedNames);\n }\n }\n}\n\nfunction resolveParentType(klass: AnyClass): bigint {\n return (\n walkClassChain(getParentClass(klass), (cls) => {\n const gtype = getClassType(cls);\n\n return gtype === TYPE_INVALID ? undefined : gtype;\n }) ?? TYPE_INVALID\n );\n}\n\nfunction addOwnMember(members: InstanceMembers, proto: object, name: string, isInherited: boolean): void {\n if (name === \"constructor\") {\n return;\n }\n\n if (isInherited) {\n members.inheritedNames.add(name);\n }\n\n if (members.names.has(name)) {\n return;\n }\n\n members.names.add(name);\n const descriptor = Object.getOwnPropertyDescriptor(proto, name);\n\n if (typeof descriptor?.value === \"function\") {\n members.methods.set(name, descriptor.value as VfuncFn);\n }\n}\n\nfunction addOwnMembers(members: InstanceMembers, klass: AnyClass, isInherited: boolean): void {\n const proto = (klass as { prototype?: object }).prototype;\n\n if (proto === undefined) {\n return;\n }\n\n for (const name of Object.getOwnPropertyNames(proto)) {\n addOwnMember(members, proto, name, isInherited);\n }\n}\n\nfunction collectInstanceMembers(klass: AnyClass): InstanceMembers {\n const members: InstanceMembers = { methods: new Map(), names: new Set(), inheritedNames: new Set() };\n let cls: AnyClass | null = klass;\n\n while (cls !== null && getClassType(cls) === TYPE_INVALID) {\n addOwnMembers(members, cls, cls !== klass);\n cls = getParentClass(cls);\n }\n\n return members;\n}\n\nfunction buildDiscoveredVfunc(\n fn: VfuncFn,\n methodName: string,\n resolveDescriptor: (methodName: string) => VfuncDescriptor | undefined,\n skip: Set<string> | undefined,\n): DiscoveredVfunc | undefined {\n if (skip?.has(methodName)) {\n return undefined;\n }\n\n const descriptor = resolveDescriptor(methodName);\n\n if (!descriptor) {\n return undefined;\n }\n\n const argDescriptors = slotArgDescriptors(descriptor);\n\n return {\n ...descriptor,\n methodName,\n argDescriptors,\n fn: wrapVfunc(fn, argDescriptors, descriptor),\n };\n}\n\nfunction collectDiscoveredVfuncs(\n methods: MethodTable,\n resolveDescriptor: (methodName: string) => VfuncDescriptor | undefined,\n skip?: Set<string>,\n): DiscoveredVfunc[] {\n const result: DiscoveredVfunc[] = [];\n\n for (const [methodName, fn] of methods) {\n const discovered = buildDiscoveredVfunc(fn, methodName, resolveDescriptor, skip);\n\n if (discovered) {\n result.push(discovered);\n }\n }\n\n return result;\n}\n\nfunction discoverClassVfuncs(klass: AnyClass, methods: MethodTable): DiscoveredVfunc[] {\n return collectDiscoveredVfuncs(\n methods,\n (methodName) => findClassVfuncDescriptor(klass, methodName) ?? undefined,\n PROPERTY_VFUNC_NAMES,\n );\n}\n\nfunction wrapVfunc(\n fn: VfuncFn,\n argDescriptors: NativeRegisterClassVfunc[\"argDescriptors\"],\n descriptor: VfuncDescriptor,\n): VfuncFn {\n return wrapCallback(\n fn as (...args: unknown[]) => unknown,\n { argDescriptors, returnDescriptor: descriptor.returnDescriptor },\n \"vfunc\",\n );\n}\n\nfunction discoverInterfaceBindings(\n methods: MethodTable,\n parentGtype: bigint,\n declaredTypes: bigint[],\n claimedMethodNames: Set<string>,\n): InterfaceVfuncBinding[] {\n const declared: Set<bigint> = new Set(declaredTypes);\n const gtypes: Set<bigint> = new Set([...typeInterfaces(parentGtype), ...declaredTypes]);\n const bindings: InterfaceVfuncBinding[] = [];\n\n for (const gtype of gtypes) {\n const vfuncs = discoverInterfaceVfuncs(methods, gtype, claimedMethodNames);\n\n if (vfuncs.length > 0 || declared.has(gtype)) {\n bindings.push({ gtype, vfuncs });\n }\n }\n\n return bindings;\n}\n\nfunction discoverInterfaceVfuncs(\n methods: MethodTable,\n interfaceGtype: bigint,\n claimedMethodNames: Set<string>,\n): DiscoveredVfunc[] {\n return collectDiscoveredVfuncs(\n methods,\n (methodName) => findInterfaceVfuncDescriptor(interfaceGtype, methodName),\n claimedMethodNames,\n );\n}\n\nconst hasDispatchedProperties = (dispatch: PropertyDispatch, adoptedTypes: bigint[]): boolean =>\n dispatch.accessors.length > 0 || adoptedTypes.length > 0;\n\nfunction propertyVfuncFor(\n source: PropertyVfuncSource,\n spec: PropertyVfuncSpec,\n): DiscoveredVfunc | undefined {\n const { klass, methods, dispatch, adoptedTypes } = source;\n\n const dispatched = hasDispatchedProperties(dispatch, adoptedTypes)\n ? spec.makeDispatch(dispatch)\n : undefined;\n\n const fn = methods.get(spec.methodName) ?? dispatched;\n\n return fn === undefined ? undefined : buildPropertyVfunc(klass, spec.methodName, fn, spec.isValueOut);\n}\n\nfunction propertyVfuncs(source: PropertyVfuncSource): DiscoveredVfunc[] {\n return PROPERTY_VFUNC_SPECS.map((spec) => propertyVfuncFor(source, spec)).filter(\n (vfunc) => vfunc !== undefined,\n );\n}\n\nfunction markArg(argDescriptors: Descriptor[], index: number, patch: ArgPatch): Descriptor[] {\n return argDescriptors.map((arg, at) => (at === index ? { ...arg, ...patch } : arg));\n}\n\nfunction isTeardownSlot(descriptor: VfuncDescriptor): boolean {\n return (\n TEARDOWN_VFUNC_NAMES.has(descriptor.vfuncName) &&\n descriptor.argDescriptors[INSTANCE_ARG_INDEX]?.kind === \"object\"\n );\n}\n\nfunction slotArgDescriptors(descriptor: VfuncDescriptor): Descriptor[] {\n if (!isTeardownSlot(descriptor)) {\n return descriptor.argDescriptors;\n }\n\n return markArg(descriptor.argDescriptors, INSTANCE_ARG_INDEX, { isCallScoped: true });\n}\n\nfunction buildPropertyVfunc(\n klass: AnyClass,\n methodName: string,\n fn: VfuncFn,\n isValueOut: boolean,\n): DiscoveredVfunc {\n const descriptor = findClassVfuncDescriptor(klass, methodName);\n\n if (!descriptor) {\n throw new Error(`registerClass: the parent class exposes no '${methodName}' vtable slot`);\n }\n\n const argDescriptors = isValueOut\n ? markArg(descriptor.argDescriptors, VALUE_ARG_INDEX, { isCallerAllocated: true })\n : descriptor.argDescriptors;\n\n return {\n ...descriptor,\n methodName,\n argDescriptors,\n fn: wrapVfunc(fn, argDescriptors, descriptor),\n };\n}\n\nfunction toNativeInterface(binding: InterfaceVfuncBinding): NativeRegisterClassInterface {\n const nativeInterface: NativeRegisterClassInterface = {\n type: binding.gtype,\n vfuncs: [...binding.vfuncs],\n };\n\n const vtableSize = binding.vfuncs[0]?.vtableSize;\n\n if (vtableSize !== undefined) {\n nativeInterface.vtableSize = vtableSize;\n }\n\n return nativeInterface;\n}\n\nfunction toNativeOptions(\n classVfuncs: DiscoveredVfunc[],\n interfaceBindings: InterfaceVfuncBinding[],\n properties: Record<string, PropertySpec>,\n): NativeRegisterClassOptions | undefined {\n const hasInterfaces = interfaceBindings.length > 0;\n const hasClassVfuncs = classVfuncs.length > 0;\n const hasProperties = Object.keys(properties).length > 0;\n\n if (!hasClassVfuncs && !hasInterfaces && !hasProperties) {\n return undefined;\n }\n\n const options: NativeRegisterClassOptions = {};\n\n if (hasProperties) {\n options.properties = toNativeProperties(properties);\n }\n\n if (hasClassVfuncs) {\n options.vfuncs = [...classVfuncs];\n }\n\n if (hasInterfaces) {\n options.interfaces = interfaceBindings.map((binding) => toNativeInterface(binding));\n }\n\n return options;\n}\n\nexport { type Interface, registerClass };\n"]}
|