@gtkx/runtime 2.0.0-beta.1 → 2.0.0-beta.3
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/dist/descriptors.d.ts +2 -1
- package/dist/descriptors.d.ts.map +1 -1
- package/dist/descriptors.js +5 -1
- package/dist/descriptors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +17 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +13 -0
- package/dist/internal.js.map +1 -1
- package/dist/listeners.d.ts +3 -13
- package/dist/listeners.d.ts.map +1 -1
- package/dist/listeners.js +12 -12
- package/dist/listeners.js.map +1 -1
- package/dist/mixin.d.ts +5 -3
- package/dist/mixin.d.ts.map +1 -1
- package/dist/mixin.js +36 -9
- package/dist/mixin.js.map +1 -1
- package/dist/object.d.ts +14 -3
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +20 -27
- package/dist/object.js.map +1 -1
- package/dist/properties.d.ts +4 -2
- package/dist/properties.d.ts.map +1 -1
- package/dist/properties.js +69 -16
- package/dist/properties.js.map +1 -1
- package/dist/property-brand.d.ts +5 -0
- package/dist/property-brand.d.ts.map +1 -0
- package/dist/property-brand.js +5 -0
- package/dist/property-brand.js.map +1 -0
- package/dist/register-class.d.ts +102 -20
- package/dist/register-class.d.ts.map +1 -1
- package/dist/register-class.js +19 -37
- package/dist/register-class.js.map +1 -1
- package/dist/registry.d.ts +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +4 -4
- package/dist/registry.js.map +1 -1
- package/dist/signal-brand.d.ts +12 -0
- package/dist/signal-brand.d.ts.map +1 -0
- package/dist/signal-brand.js +6 -0
- package/dist/signal-brand.js.map +1 -0
- package/dist/signal.d.ts +39 -2
- package/dist/signal.d.ts.map +1 -1
- package/dist/signal.js +75 -5
- package/dist/signal.js.map +1 -1
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js +1 -1
- package/dist/type.js.map +1 -1
- package/dist/value.d.ts +2 -1
- package/dist/value.d.ts.map +1 -1
- package/dist/value.js +28 -7
- package/dist/value.js.map +1 -1
- package/package.json +4 -4
- package/src/descriptors.ts +7 -0
- package/src/index.ts +2 -2
- package/src/internal.ts +42 -0
- package/src/listeners.ts +21 -26
- package/src/mixin.ts +55 -9
- package/src/object.ts +57 -7
- package/src/properties.ts +94 -17
- package/src/property-brand.ts +5 -0
- package/src/register-class.ts +296 -95
- package/src/registry.ts +4 -4
- package/src/signal-brand.ts +29 -0
- package/src/signal.ts +177 -6
- package/src/type.ts +1 -1
- package/src/value.ts +40 -5
package/dist/mixin.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { getParentClass } from "@gtkx/utils";
|
|
2
|
+
const syntheticSignalMembers = new WeakMap();
|
|
3
|
+
function markSyntheticSignalMembers(klass, names) {
|
|
4
|
+
syntheticSignalMembers.set(klass.prototype, new Set(names));
|
|
5
|
+
}
|
|
2
6
|
function isDefinedInClassChain(prototype, key) {
|
|
3
7
|
let current = prototype;
|
|
4
8
|
while (current !== null && current !== Object.prototype) {
|
|
@@ -9,11 +13,22 @@ function isDefinedInClassChain(prototype, key) {
|
|
|
9
13
|
}
|
|
10
14
|
return false;
|
|
11
15
|
}
|
|
12
|
-
function
|
|
16
|
+
function isNaturalInClassChain(prototype, key) {
|
|
17
|
+
let current = prototype;
|
|
18
|
+
while (current !== null && current !== Object.prototype) {
|
|
19
|
+
if (Object.hasOwn(current, key)) {
|
|
20
|
+
return syntheticSignalMembers.get(current)?.has(key) !== true;
|
|
21
|
+
}
|
|
22
|
+
current = Reflect.getPrototypeOf(current);
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
function copyLayerMember(target, layer, key, inheritedOverrides) {
|
|
13
27
|
if (key === "constructor") {
|
|
14
28
|
return;
|
|
15
29
|
}
|
|
16
|
-
|
|
30
|
+
const isProtectedInherited = !inheritedOverrides.has(key) && isDefinedInClassChain(target.prototype, key);
|
|
31
|
+
if (isProtectedInherited || Object.hasOwn(target.prototype, key)) {
|
|
17
32
|
return;
|
|
18
33
|
}
|
|
19
34
|
const descriptor = Object.getOwnPropertyDescriptor(layer, key);
|
|
@@ -21,9 +36,9 @@ function copyLayerMember(target, layer, key) {
|
|
|
21
36
|
Object.defineProperty(target.prototype, key, descriptor);
|
|
22
37
|
}
|
|
23
38
|
}
|
|
24
|
-
function copyLayerMembers(target, layer) {
|
|
39
|
+
function copyLayerMembers(target, layer, inheritedOverrides = new Set()) {
|
|
25
40
|
for (const key of Object.getOwnPropertyNames(layer)) {
|
|
26
|
-
copyLayerMember(target, layer, key);
|
|
41
|
+
copyLayerMember(target, layer, key, inheritedOverrides);
|
|
27
42
|
}
|
|
28
43
|
}
|
|
29
44
|
/**
|
|
@@ -33,7 +48,8 @@ function copyLayerMembers(target, layer) {
|
|
|
33
48
|
* @param target The class whose prototype receives the mixin members.
|
|
34
49
|
* @param mixins The mixins to apply, in order.
|
|
35
50
|
*/
|
|
36
|
-
function installMixins(target, mixins) {
|
|
51
|
+
function installMixins(target, mixins, inheritedOverrideNames = []) {
|
|
52
|
+
const inheritedOverrides = new Set(inheritedOverrideNames);
|
|
37
53
|
const empty = class {
|
|
38
54
|
connect() {
|
|
39
55
|
return 0;
|
|
@@ -43,7 +59,7 @@ function installMixins(target, mixins) {
|
|
|
43
59
|
}
|
|
44
60
|
};
|
|
45
61
|
for (const mixin of mixins) {
|
|
46
|
-
copyLayerMembers(target, mixin(empty).prototype);
|
|
62
|
+
copyLayerMembers(target, mixin(empty).prototype, inheritedOverrides);
|
|
47
63
|
}
|
|
48
64
|
}
|
|
49
65
|
function dropLayerMembers(layer, names) {
|
|
@@ -51,11 +67,22 @@ function dropLayerMembers(layer, names) {
|
|
|
51
67
|
Reflect.deleteProperty(layer.prototype, name);
|
|
52
68
|
}
|
|
53
69
|
}
|
|
70
|
+
function createMixinLayer(parent, mixin, inheritedNames) {
|
|
71
|
+
const layer = mixin(parent);
|
|
72
|
+
const protectedNames = new Set(inheritedNames);
|
|
73
|
+
for (const key of Object.getOwnPropertyNames(layer.prototype)) {
|
|
74
|
+
if (key !== "constructor" && isNaturalInClassChain(parent.prototype, key)) {
|
|
75
|
+
protectedNames.add(key);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
dropLayerMembers(layer, protectedNames);
|
|
79
|
+
return layer;
|
|
80
|
+
}
|
|
54
81
|
function insertMixinLayer(target, mixin, inheritedNames) {
|
|
55
|
-
const
|
|
56
|
-
|
|
82
|
+
const parent = getParentClass(target);
|
|
83
|
+
const layer = createMixinLayer(parent, mixin, inheritedNames);
|
|
57
84
|
Object.setPrototypeOf(target.prototype, layer.prototype);
|
|
58
85
|
Object.setPrototypeOf(target, layer);
|
|
59
86
|
}
|
|
60
|
-
export { copyLayerMembers, insertMixinLayer, installMixins };
|
|
87
|
+
export { copyLayerMembers, createMixinLayer, insertMixinLayer, installMixins, markSyntheticSignalMembers, };
|
|
61
88
|
//# sourceMappingURL=mixin.js.map
|
package/dist/mixin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixin.js","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAAE,MAAM,aAAa,CAAC;AAmB5D,SAAS,qBAAqB,CAAC,SAAiB,EAAE,GAAW;IACzD,IAAI,OAAO,GAAkB,SAAS,CAAC;IAEvC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;QACtD,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC;A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B,CAAC","sourcesContent":["import { type AnyClass, getParentClass } from \"@gtkx/utils\";\n\n/**\n * The signal plumbing every base class passed to a {@link Mixin} provides, so mixed-in interface\n * members can connect and emit without knowing the concrete class.\n */\ntype MixinReceiver = {\n /** Connects a handler to a signal and returns its handler id. */\n connect(signal: string, handler: (...args: unknown[]) => unknown, isAfter?: boolean): number;\n /** Emits a signal with the given arguments and returns whatever the emission produced. */\n emit(signal: string, ...args: unknown[]): unknown;\n};\n\n/**\n * A factory that, given a base class, returns a subclass adding extra members to\n * be merged onto a target prototype.\n */\ntype Mixin = (base: AnyClass<MixinReceiver>) => AnyClass;\n\nconst syntheticSignalMembers: WeakMap<object, ReadonlySet<string>> = new WeakMap();\n\nfunction markSyntheticSignalMembers(klass: AnyClass, names: readonly string[]): void {\n syntheticSignalMembers.set(klass.prototype, new Set(names));\n}\n\nfunction isDefinedInClassChain(prototype: object, key: string): boolean {\n let current: object | null = prototype;\n\n while (current !== null && current !== Object.prototype) {\n if (Object.hasOwn(current, key)) {\n return true;\n }\n\n current = Reflect.getPrototypeOf(current);\n }\n\n return false;\n}\n\nfunction isNaturalInClassChain(prototype: object, key: string): boolean {\n let current: object | null = prototype;\n\n while (current !== null && current !== Object.prototype) {\n if (Object.hasOwn(current, key)) {\n return syntheticSignalMembers.get(current)?.has(key) !== true;\n }\n\n current = Reflect.getPrototypeOf(current);\n }\n\n return false;\n}\n\nfunction copyLayerMember(target: AnyClass, layer: object, key: string, inheritedOverrides: Set<string>): void {\n if (key === \"constructor\") {\n return;\n }\n\n const isProtectedInherited = !inheritedOverrides.has(key) && isDefinedInClassChain(target.prototype, key);\n\n if (isProtectedInherited || Object.hasOwn(target.prototype, key)) {\n return;\n }\n\n const descriptor = Object.getOwnPropertyDescriptor(layer, key);\n\n if (descriptor !== undefined) {\n Object.defineProperty(target.prototype, key, descriptor);\n }\n}\n\nfunction copyLayerMembers(target: AnyClass, layer: object, inheritedOverrides: Set<string> = new Set()): void {\n for (const key of Object.getOwnPropertyNames(layer)) {\n copyLayerMember(target, layer, key, inheritedOverrides);\n }\n}\n\n/**\n * Copies each mixin's prototype members onto the target class prototype, skipping\n * any member already defined anywhere in the target's class chain.\n *\n * @param target The class whose prototype receives the mixin members.\n * @param mixins The mixins to apply, in order.\n */\nfunction installMixins(target: AnyClass, mixins: Mixin[], inheritedOverrideNames: Iterable<string> = []): void {\n const inheritedOverrides = new Set(inheritedOverrideNames);\n const empty: AnyClass<MixinReceiver> = class {\n connect(): number {\n return 0;\n }\n\n emit(): unknown {\n return undefined;\n }\n };\n\n for (const mixin of mixins) {\n copyLayerMembers(target, mixin(empty).prototype, inheritedOverrides);\n }\n}\n\nfunction dropLayerMembers(layer: AnyClass, names: Set<string>): void {\n for (const name of names) {\n Reflect.deleteProperty(layer.prototype, name);\n }\n}\n\nfunction createMixinLayer(parent: AnyClass<MixinReceiver>, mixin: Mixin, inheritedNames: Set<string>): AnyClass {\n const layer = mixin(parent);\n const protectedNames = new Set(inheritedNames);\n\n for (const key of Object.getOwnPropertyNames(layer.prototype)) {\n if (key !== \"constructor\" && isNaturalInClassChain(parent.prototype, key)) {\n protectedNames.add(key);\n }\n }\n\n dropLayerMembers(layer, protectedNames);\n\n return layer;\n}\n\nfunction insertMixinLayer(target: AnyClass, mixin: Mixin, inheritedNames: Set<string>): void {\n const parent = getParentClass(target) as AnyClass<MixinReceiver>;\n const layer = createMixinLayer(parent, mixin, inheritedNames);\n Object.setPrototypeOf(target.prototype, layer.prototype);\n Object.setPrototypeOf(target, layer);\n}\n\nexport {\n copyLayerMembers,\n createMixinLayer,\n insertMixinLayer,\n installMixins,\n markSyntheticSignalMembers,\n type MixinReceiver,\n type Mixin,\n};\n"]}
|
package/dist/object.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Descriptor } from "@gtkx/native";
|
|
2
2
|
import { type AnyClass } from "@gtkx/utils";
|
|
3
|
+
import { propertyMapOverride, writablePropertyMapOverride } from "./property-brand.js";
|
|
3
4
|
/**
|
|
4
5
|
* One construct property a wrapper class accepts: the canonical `GObject` name it is set under,
|
|
5
6
|
* and the descriptor its value is marshalled through.
|
|
@@ -54,7 +55,12 @@ declare function newObjectWithProperties<T extends object>(gtype: bigint, props:
|
|
|
54
55
|
* @param propertyName The property name.
|
|
55
56
|
* @param descriptor Describes the property's type.
|
|
56
57
|
*/
|
|
57
|
-
declare function
|
|
58
|
+
declare function getProperty<TObject extends {
|
|
59
|
+
__properties__: object;
|
|
60
|
+
}, TPropertyMap extends object = TObject extends {
|
|
61
|
+
[propertyMapOverride]?: infer TResolver;
|
|
62
|
+
} ? TResolver extends () => infer TMap ? Extract<NonNullable<TMap>, object> : TObject["__properties__"] : TObject["__properties__"], TName extends Extract<keyof NoInfer<TPropertyMap>, string> = Extract<keyof NoInfer<TPropertyMap>, string>>(obj: TObject, propertyName: TName): NoInfer<TPropertyMap>[TName];
|
|
63
|
+
declare function getProperty(obj: object, propertyName: string, descriptor: Descriptor): unknown;
|
|
58
64
|
/**
|
|
59
65
|
* Writes a JavaScript value to a GObject property, converting it to native form
|
|
60
66
|
* using the descriptor. The descriptor converts what it is given rather than checking it against
|
|
@@ -68,6 +74,11 @@ declare function getObjectProperty(obj: object, propertyName: string, descriptor
|
|
|
68
74
|
* @param descriptor Describes the property's type.
|
|
69
75
|
* @param jsValue The value to set.
|
|
70
76
|
*/
|
|
71
|
-
declare function
|
|
72
|
-
|
|
77
|
+
declare function setProperty<TObject extends {
|
|
78
|
+
__writableProperties__: object;
|
|
79
|
+
}, TPropertyMap extends object = TObject extends {
|
|
80
|
+
[writablePropertyMapOverride]?: infer TResolver;
|
|
81
|
+
} ? TResolver extends () => infer TMap ? Extract<NonNullable<TMap>, object> : TObject["__writableProperties__"] : TObject["__writableProperties__"], TName extends Extract<keyof NoInfer<TPropertyMap>, string> = Extract<keyof NoInfer<TPropertyMap>, string>>(obj: TObject, propertyName: TName, jsValue: NoInfer<TPropertyMap>[TName]): void;
|
|
82
|
+
declare function setProperty(obj: object, propertyName: string, descriptor: Descriptor, jsValue: unknown): void;
|
|
83
|
+
export { newObjectWithProperties, getProperty, registerConstructProperties, setProperty, type ConstructBinding, type ConstructBindings, };
|
|
73
84
|
//# sourceMappingURL=object.d.ts.map
|
package/dist/object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAA+C,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,KAAK,QAAQ,EAAkB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAA+C,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,KAAK,QAAQ,EAAkB,MAAM,aAAa,CAAC;AAW5D,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAIvF;;;GAGG;AACH,KAAK,gBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAC/D,wGAAwG;AACxG,KAAK,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAmE1D;;;;;;;;;GASG;AACH,iBAAS,2BAA2B,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAGrF;AAoBD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,iBAAS,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAsB9F;AAED;;;;;;;GAOG;AACH,iBAAS,WAAW,CAChB,OAAO,SAAS;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,EAC1C,YAAY,SAAS,MA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AAG,IAAI,CAAC;AAClF,iBAAS,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;AAiBxG,OAAO,EACH,uBAAuB,EACvB,WAAW,EACX,2BAA2B,EAC3B,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACzB,CAAC"}
|
package/dist/object.js
CHANGED
|
@@ -3,9 +3,10 @@ import { getParentClass } from "@gtkx/utils";
|
|
|
3
3
|
import { bind } from "./bind.js";
|
|
4
4
|
import { objectT, stringT, voidT } from "./descriptors.js";
|
|
5
5
|
import { LIB, VALUE_T } from "./library.js";
|
|
6
|
-
import { coercePropertyValue, constructPropertyFor } from "./properties.js";
|
|
6
|
+
import { coercePropertyValue, constructPropertyFor, readableObjectPropertyFor, writableObjectPropertyFor, } from "./properties.js";
|
|
7
|
+
import { propertyMapOverride, writablePropertyMapOverride } from "./property-brand.js";
|
|
7
8
|
import { getHandle, registerWrapper } from "./registry.js";
|
|
8
|
-
import { fromValueForDescriptor, newValueForDescriptor, toValue } from "./value.js";
|
|
9
|
+
import { fromObjectPropertyValue, fromValueForDescriptor, newValueForDescriptor, toValue } from "./value.js";
|
|
9
10
|
const declaredBindings = new WeakMap();
|
|
10
11
|
const resolvedBindings = new WeakMap();
|
|
11
12
|
const declarations = { generation: 0 };
|
|
@@ -113,34 +114,26 @@ function newObjectWithProperties(gtype, props, wrapper) {
|
|
|
113
114
|
}
|
|
114
115
|
return wrapper;
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
117
|
+
function getProperty(obj, propertyName, descriptor) {
|
|
118
|
+
if (arguments.length === 2) {
|
|
119
|
+
const property = readableObjectPropertyFor(obj, propertyName);
|
|
120
|
+
gObjectGetProperty(getHandle(obj), property.name, property.value);
|
|
121
|
+
return fromObjectPropertyValue(property.value);
|
|
122
|
+
}
|
|
123
|
+
if (descriptor === undefined) {
|
|
124
|
+
throw new TypeError("getProperty requires a property descriptor when called with three arguments");
|
|
125
|
+
}
|
|
125
126
|
const value = newValueForDescriptor(descriptor);
|
|
126
127
|
gObjectGetProperty(getHandle(obj), propertyName, value);
|
|
127
128
|
return fromValueForDescriptor(descriptor, value);
|
|
128
129
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
*
|
|
137
|
-
* @param obj The object to write to.
|
|
138
|
-
* @param propertyName The property name.
|
|
139
|
-
* @param descriptor Describes the property's type.
|
|
140
|
-
* @param jsValue The value to set.
|
|
141
|
-
*/
|
|
142
|
-
function setObjectProperty(obj, propertyName, descriptor, jsValue) {
|
|
143
|
-
gObjectSetProperty(getHandle(obj), propertyName, toValue(descriptor, jsValue));
|
|
130
|
+
function setProperty(obj, propertyName, descriptorOrValue, jsValue) {
|
|
131
|
+
if (arguments.length === 3) {
|
|
132
|
+
const property = writableObjectPropertyFor(obj, propertyName, descriptorOrValue);
|
|
133
|
+
gObjectSetProperty(getHandle(obj), property.name, property.value);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
gObjectSetProperty(getHandle(obj), propertyName, toValue(descriptorOrValue, jsValue));
|
|
144
137
|
}
|
|
145
|
-
export { newObjectWithProperties,
|
|
138
|
+
export { newObjectWithProperties, getProperty, registerConstructProperties, setProperty, };
|
|
146
139
|
//# sourceMappingURL=object.js.map
|
package/dist/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAiB,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,IAA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,QAAQ,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;IACL,CAAC;IAED,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC;IAE3E,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,QAAa,CAAC;IACzB,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,iBAAiB,CAAC,GAAW,EAAE,YAAoB,EAAE,UAAsB;IAChF,MAAM,KAAK,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAChD,kBAAkB,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;IAExD,OAAO,sBAAsB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,iBAAiB,CAAC,GAAW,EAAE,YAAoB,EAAE,UAAsB,EAAE,OAAgB;IAClG,kBAAkB,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;AACnF,CAAC;AAED,OAAO,EACH,uBAAuB,EACvB,iBAAiB,EACjB,2BAA2B,EAC3B,iBAAiB,GAGpB,CAAC","sourcesContent":["import { type Descriptor, type ExternalObject, type Handle, newObject } from \"@gtkx/native\";\nimport { type AnyClass, getParentClass } from \"@gtkx/utils\";\nimport { bind } from \"./bind.js\";\nimport { objectT, stringT, voidT } from \"./descriptors.js\";\nimport { LIB, VALUE_T } from \"./library.js\";\nimport { coercePropertyValue, type ConstructProperty, constructPropertyFor } from \"./properties.js\";\nimport { getHandle, registerWrapper } from \"./registry.js\";\nimport { fromValueForDescriptor, newValueForDescriptor, toValue } from \"./value.js\";\n\n/**\n * One construct property a wrapper class accepts: the canonical `GObject` name it is set under,\n * and the descriptor its value is marshalled through.\n */\ntype ConstructBinding = [name: string, descriptor: Descriptor];\n/** The construct properties a wrapper class accepts, keyed by the camelCased name callers give them. */\ntype ConstructBindings = Record<string, ConstructBinding>;\ntype ResolvedBindings = { generation: number; bindings: ConstructBindings };\n\nconst declaredBindings: WeakMap<AnyClass, ConstructBindings> = new WeakMap();\nconst resolvedBindings: WeakMap<AnyClass, ResolvedBindings> = new WeakMap();\nconst declarations = { generation: 0 };\nconst NO_BINDINGS: ConstructBindings = Object.create(null) as ConstructBindings;\n\nconst gObjectGetProperty = bind(\n LIB,\n \"g_object_get_property\",\n [objectT(\"borrowed\"), stringT(\"borrowed\"), VALUE_T],\n voidT,\n);\n\nconst gObjectSetProperty = bind(\n LIB,\n \"g_object_set_property\",\n [objectT(\"borrowed\"), stringT(\"borrowed\"), VALUE_T],\n voidT,\n);\n\nfunction collectDeclaredBindings(cls: AnyClass): ConstructBindings[] {\n const declared: ConstructBindings[] = [];\n let current: AnyClass | null = cls;\n\n while (current !== null) {\n const own = declaredBindings.get(current);\n\n if (own !== undefined) {\n declared.push(own);\n }\n\n current = getParentClass(current);\n }\n\n return declared;\n}\n\nfunction mergeDeclaredBindings(cls: AnyClass): ConstructBindings {\n const declared = collectDeclaredBindings(cls);\n const merged: ConstructBindings = Object.create(null) as ConstructBindings;\n\n for (let index = declared.length - 1; index >= 0; index--) {\n Object.assign(merged, declared[index]);\n }\n\n return merged;\n}\n\nfunction constructBindingsFor(cls: AnyClass | undefined): ConstructBindings {\n if (cls === undefined) {\n return NO_BINDINGS;\n }\n\n const cached = resolvedBindings.get(cls);\n\n if (cached?.generation === declarations.generation) {\n return cached.bindings;\n }\n\n const bindings = mergeDeclaredBindings(cls);\n resolvedBindings.set(cls, { generation: declarations.generation, bindings });\n\n return bindings;\n}\n\n/**\n * Declares the construct properties a wrapper class accepts, so `newObjectWithProperties`\n * marshals each one through its descriptor rather than resolving it from the\n * `GObject.ParamSpec` the type installs. A class inherits the declarations of its ancestors.\n * Registering takes effect immediately, including for classes already constructed from and for\n * subclasses that already inherited an earlier declaration.\n *\n * @param cls The wrapper class the properties are declared on.\n * @param bindings CamelCased property names mapped to their canonical name and descriptor.\n */\nfunction registerConstructProperties(cls: AnyClass, bindings: ConstructBindings): void {\n declaredBindings.set(cls, bindings);\n declarations.generation += 1;\n}\n\nfunction constructPropertyForEntry(\n source: { gtype: bigint; bindings: ConstructBindings; wrapper: object },\n name: string,\n value: unknown,\n): ConstructProperty | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n const binding = source.bindings[name];\n\n if (binding === undefined) {\n return constructPropertyFor(source.gtype, name, value, source.wrapper);\n }\n\n return { name: binding[0], value: toValue(binding[1], coercePropertyValue(source.gtype, binding[0], value)) };\n}\n\n/**\n * Constructs a new GObject of the given type, setting the supplied construct\n * properties, and binds `wrapper` to it. A property the wrapper's class declares\n * through `registerConstructProperties` is marshalled through its descriptor; any\n * other one is marshalled through the `GObject.ParamSpec` the type installs under\n * that name, dashed or camelCased, and is skipped when the type installs none.\n * A value that ParamSpec would refuse throws before GObject sees it: a `TypeError`\n * for a read-only property and for a value of a type the property cannot hold, and\n * a `RangeError` for a value the ParamSpec rejects. A value marshalled through a\n * declared descriptor is converted rather than checked, so a `null` handed to a\n * numeric one of those lands 0 rather than being refused, and a number is fitted to\n * the property first, as `coerceObjectProperty` does: truncated toward zero for a\n * whole-number property and clamped to the range its `GObject.ParamSpec` allows.\n * Properties whose value is `undefined` are skipped. A type registered with\n * `registerClass` binds the wrapper before its `constructed` slot runs, so an\n * override of that slot already sees a usable instance.\n * When construction returns an object that already has a wrapper — it reached\n * JavaScript and was wrapped before `g_object_new` returned, for example a\n * `Gtk.Window` observed through the toplevels list — that existing wrapper is\n * returned instead of binding `wrapper`, so both references stay one object.\n *\n * @param gtype The GType of the object to construct.\n * @param props Property names mapped to the values to set them to.\n * @param wrapper The wrapper instance to bind to the new object.\n * @returns The wrapper bound to the constructed object: `wrapper` itself, or\n * the wrapper the object already had.\n */\nfunction newObjectWithProperties<T extends object>(gtype: bigint, props: object, wrapper: T): T {\n const names: string[] = [];\n const values: ExternalObject<Handle>[] = [];\n const bindings = constructBindingsFor(wrapper.constructor as AnyClass | undefined);\n const source = { gtype, bindings, wrapper };\n\n for (const name of Object.keys(props)) {\n const property = constructPropertyForEntry(source, name, Reflect.get(props, name));\n\n if (property !== undefined) {\n names.push(property.name);\n values.push(property.value);\n }\n }\n\n const existing = newObject(gtype, names, values, wrapper, registerWrapper);\n\n if (existing !== null) {\n return existing as T;\n }\n\n return wrapper;\n}\n\n/**\n * Reads a GObject property and converts it to its JavaScript value using the\n * descriptor.\n *\n * @param obj The object to read from.\n * @param propertyName The property name.\n * @param descriptor Describes the property's type.\n */\nfunction getObjectProperty(obj: object, propertyName: string, descriptor: Descriptor): unknown {\n const value = newValueForDescriptor(descriptor);\n gObjectGetProperty(getHandle(obj), propertyName, value);\n\n return fromValueForDescriptor(descriptor, value);\n}\n\n/**\n * Writes a JavaScript value to a GObject property, converting it to native form\n * using the descriptor. The descriptor converts what it is given rather than checking it against\n * the property's `GObject.ParamSpec`, so `null` and `undefined` written to a numeric or enum\n * property land 0, and a fractional number written to a whole-number property is truncated toward\n * zero, where the same writes to a property installed through `registerClass` are refused with a\n * `TypeError`.\n *\n * @param obj The object to write to.\n * @param propertyName The property name.\n * @param descriptor Describes the property's type.\n * @param jsValue The value to set.\n */\nfunction setObjectProperty(obj: object, propertyName: string, descriptor: Descriptor, jsValue: unknown): void {\n gObjectSetProperty(getHandle(obj), propertyName, toValue(descriptor, jsValue));\n}\n\nexport {\n newObjectWithProperties,\n getObjectProperty,\n registerConstructProperties,\n setObjectProperty,\n type ConstructBinding,\n type ConstructBindings,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAiB,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,IAA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,YAAY,EAAE,iBAAiB,CAAC,CAAC;QACjF,kBAAkB,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;QAElE,OAAO;IACX,CAAC;IAED,kBAAkB,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,iBAA+B,EAAE,OAAO,CAAC,CAAC,CAAC;AACxG,CAAC;AAED,OAAO,EACH,uBAAuB,EACvB,WAAW,EACX,2BAA2B,EAC3B,WAAW,GAGd,CAAC","sourcesContent":["import { type Descriptor, type ExternalObject, type Handle, newObject } from \"@gtkx/native\";\nimport { type AnyClass, getParentClass } from \"@gtkx/utils\";\nimport { bind } from \"./bind.js\";\nimport { objectT, stringT, voidT } from \"./descriptors.js\";\nimport { LIB, VALUE_T } from \"./library.js\";\nimport {\n coercePropertyValue,\n type ConstructProperty,\n constructPropertyFor,\n readableObjectPropertyFor,\n writableObjectPropertyFor,\n} from \"./properties.js\";\nimport { propertyMapOverride, writablePropertyMapOverride } from \"./property-brand.js\";\nimport { getHandle, registerWrapper } from \"./registry.js\";\nimport { fromObjectPropertyValue, fromValueForDescriptor, newValueForDescriptor, toValue } from \"./value.js\";\n\n/**\n * One construct property a wrapper class accepts: the canonical `GObject` name it is set under,\n * and the descriptor its value is marshalled through.\n */\ntype ConstructBinding = [name: string, descriptor: Descriptor];\n/** The construct properties a wrapper class accepts, keyed by the camelCased name callers give them. */\ntype ConstructBindings = Record<string, ConstructBinding>;\ntype ResolvedBindings = { generation: number; bindings: ConstructBindings };\n\nconst declaredBindings: WeakMap<AnyClass, ConstructBindings> = new WeakMap();\nconst resolvedBindings: WeakMap<AnyClass, ResolvedBindings> = new WeakMap();\nconst declarations = { generation: 0 };\nconst NO_BINDINGS: ConstructBindings = Object.create(null) as ConstructBindings;\n\nconst gObjectGetProperty = bind(\n LIB,\n \"g_object_get_property\",\n [objectT(\"borrowed\"), stringT(\"borrowed\"), VALUE_T],\n voidT,\n);\n\nconst gObjectSetProperty = bind(\n LIB,\n \"g_object_set_property\",\n [objectT(\"borrowed\"), stringT(\"borrowed\"), VALUE_T],\n voidT,\n);\n\nfunction collectDeclaredBindings(cls: AnyClass): ConstructBindings[] {\n const declared: ConstructBindings[] = [];\n let current: AnyClass | null = cls;\n\n while (current !== null) {\n const own = declaredBindings.get(current);\n\n if (own !== undefined) {\n declared.push(own);\n }\n\n current = getParentClass(current);\n }\n\n return declared;\n}\n\nfunction mergeDeclaredBindings(cls: AnyClass): ConstructBindings {\n const declared = collectDeclaredBindings(cls);\n const merged: ConstructBindings = Object.create(null) as ConstructBindings;\n\n for (let index = declared.length - 1; index >= 0; index--) {\n Object.assign(merged, declared[index]);\n }\n\n return merged;\n}\n\nfunction constructBindingsFor(cls: AnyClass | undefined): ConstructBindings {\n if (cls === undefined) {\n return NO_BINDINGS;\n }\n\n const cached = resolvedBindings.get(cls);\n\n if (cached?.generation === declarations.generation) {\n return cached.bindings;\n }\n\n const bindings = mergeDeclaredBindings(cls);\n resolvedBindings.set(cls, { generation: declarations.generation, bindings });\n\n return bindings;\n}\n\n/**\n * Declares the construct properties a wrapper class accepts, so `newObjectWithProperties`\n * marshals each one through its descriptor rather than resolving it from the\n * `GObject.ParamSpec` the type installs. A class inherits the declarations of its ancestors.\n * Registering takes effect immediately, including for classes already constructed from and for\n * subclasses that already inherited an earlier declaration.\n *\n * @param cls The wrapper class the properties are declared on.\n * @param bindings CamelCased property names mapped to their canonical name and descriptor.\n */\nfunction registerConstructProperties(cls: AnyClass, bindings: ConstructBindings): void {\n declaredBindings.set(cls, bindings);\n declarations.generation += 1;\n}\n\nfunction constructPropertyForEntry(\n source: { gtype: bigint; bindings: ConstructBindings; wrapper: object },\n name: string,\n value: unknown,\n): ConstructProperty | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n const binding = source.bindings[name];\n\n if (binding === undefined) {\n return constructPropertyFor(source.gtype, name, value, source.wrapper);\n }\n\n return { name: binding[0], value: toValue(binding[1], coercePropertyValue(source.gtype, binding[0], value)) };\n}\n\n/**\n * Constructs a new GObject of the given type, setting the supplied construct\n * properties, and binds `wrapper` to it. A property the wrapper's class declares\n * through `registerConstructProperties` is marshalled through its descriptor; any\n * other one is marshalled through the `GObject.ParamSpec` the type installs under\n * that name, dashed or camelCased, and is skipped when the type installs none.\n * A value that ParamSpec would refuse throws before GObject sees it: a `TypeError`\n * for a read-only property and for a value of a type the property cannot hold, and\n * a `RangeError` for a value the ParamSpec rejects. A value marshalled through a\n * declared descriptor is converted rather than checked, so a `null` handed to a\n * numeric one of those lands 0 rather than being refused, and a number is fitted to\n * the property first, as `coerceObjectProperty` does: truncated toward zero for a\n * whole-number property and clamped to the range its `GObject.ParamSpec` allows.\n * Properties whose value is `undefined` are skipped. A type registered with\n * `registerClass` binds the wrapper before its `constructed` slot runs, so an\n * override of that slot already sees a usable instance.\n * When construction returns an object that already has a wrapper — it reached\n * JavaScript and was wrapped before `g_object_new` returned, for example a\n * `Gtk.Window` observed through the toplevels list — that existing wrapper is\n * returned instead of binding `wrapper`, so both references stay one object.\n *\n * @param gtype The GType of the object to construct.\n * @param props Property names mapped to the values to set them to.\n * @param wrapper The wrapper instance to bind to the new object.\n * @returns The wrapper bound to the constructed object: `wrapper` itself, or\n * the wrapper the object already had.\n */\nfunction newObjectWithProperties<T extends object>(gtype: bigint, props: object, wrapper: T): T {\n const names: string[] = [];\n const values: ExternalObject<Handle>[] = [];\n const bindings = constructBindingsFor(wrapper.constructor as AnyClass | undefined);\n const source = { gtype, bindings, wrapper };\n\n for (const name of Object.keys(props)) {\n const property = constructPropertyForEntry(source, name, Reflect.get(props, name));\n\n if (property !== undefined) {\n names.push(property.name);\n values.push(property.value);\n }\n }\n\n const existing = newObject(gtype, names, values, wrapper, registerWrapper);\n\n if (existing !== null) {\n return existing as T;\n }\n\n return wrapper;\n}\n\n/**\n * Reads a GObject property and converts it to its JavaScript value using the\n * descriptor.\n *\n * @param obj The object to read from.\n * @param propertyName The property name.\n * @param descriptor Describes the property's type.\n */\nfunction getProperty<\n TObject extends { __properties__: object },\n TPropertyMap extends object = TObject extends { [propertyMapOverride]?: infer TResolver }\n ? TResolver extends () => infer TMap\n ? Extract<NonNullable<TMap>, object>\n : TObject[\"__properties__\"]\n : TObject[\"__properties__\"],\n TName extends Extract<keyof NoInfer<TPropertyMap>, string> = Extract<keyof NoInfer<TPropertyMap>, string>,\n>(obj: TObject, propertyName: TName): NoInfer<TPropertyMap>[TName];\nfunction getProperty(obj: object, propertyName: string, descriptor: Descriptor): unknown;\nfunction getProperty(obj: object, propertyName: string, descriptor?: Descriptor): unknown {\n if (arguments.length === 2) {\n const property = readableObjectPropertyFor(obj, propertyName);\n gObjectGetProperty(getHandle(obj), property.name, property.value);\n\n return fromObjectPropertyValue(property.value);\n }\n\n if (descriptor === undefined) {\n throw new TypeError(\"getProperty requires a property descriptor when called with three arguments\");\n }\n\n const value = newValueForDescriptor(descriptor);\n gObjectGetProperty(getHandle(obj), propertyName, value);\n\n return fromValueForDescriptor(descriptor, value);\n}\n\n/**\n * Writes a JavaScript value to a GObject property, converting it to native form\n * using the descriptor. The descriptor converts what it is given rather than checking it against\n * the property's `GObject.ParamSpec`, so `null` and `undefined` written to a numeric or enum\n * property land 0, and a fractional number written to a whole-number property is truncated toward\n * zero, where the same writes to a property installed through `registerClass` are refused with a\n * `TypeError`.\n *\n * @param obj The object to write to.\n * @param propertyName The property name.\n * @param descriptor Describes the property's type.\n * @param jsValue The value to set.\n */\nfunction setProperty<\n TObject extends { __writableProperties__: object },\n TPropertyMap extends object = TObject extends { [writablePropertyMapOverride]?: infer TResolver }\n ? TResolver extends () => infer TMap\n ? Extract<NonNullable<TMap>, object>\n : TObject[\"__writableProperties__\"]\n : TObject[\"__writableProperties__\"],\n TName extends Extract<keyof NoInfer<TPropertyMap>, string> = Extract<keyof NoInfer<TPropertyMap>, string>,\n>(obj: TObject, propertyName: TName, jsValue: NoInfer<TPropertyMap>[TName]): void;\nfunction setProperty(obj: object, propertyName: string, descriptor: Descriptor, jsValue: unknown): void;\nfunction setProperty(\n obj: object,\n propertyName: string,\n descriptorOrValue: unknown,\n jsValue?: unknown,\n): void {\n if (arguments.length === 3) {\n const property = writableObjectPropertyFor(obj, propertyName, descriptorOrValue);\n gObjectSetProperty(getHandle(obj), property.name, property.value);\n\n return;\n }\n\n gObjectSetProperty(getHandle(obj), propertyName, toValue(descriptorOrValue as Descriptor, jsValue));\n}\n\nexport {\n newObjectWithProperties,\n getProperty,\n registerConstructProperties,\n setProperty,\n type ConstructBinding,\n type ConstructBindings,\n};\n"]}
|
package/dist/properties.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ type AccessorBase = PropertyCheck & {
|
|
|
21
21
|
type DeclaredAccessor = AccessorBase & {
|
|
22
22
|
isInterfaceProperty?: false;
|
|
23
23
|
memberName: string;
|
|
24
|
-
|
|
24
|
+
hasMemberAccessor: boolean;
|
|
25
25
|
};
|
|
26
26
|
type InterfaceAccessor = AccessorBase & {
|
|
27
27
|
isInterfaceProperty: true;
|
|
@@ -61,6 +61,8 @@ declare const newParamSpecOverride: (name: string, source: bigint | AnyClass) =>
|
|
|
61
61
|
* rather than looking for a generated accessor, which codegen omits when a method shares the name.
|
|
62
62
|
*/
|
|
63
63
|
declare function isReadableProperty(gtype: bigint, propertyName: string): boolean;
|
|
64
|
+
declare function readableObjectPropertyFor(instance: object, name: string): ConstructProperty;
|
|
65
|
+
declare function writableObjectPropertyFor(instance: object, name: string, value: unknown): ConstructProperty;
|
|
64
66
|
declare function coercePropertyValue(gtype: bigint, propertyName: string, value: unknown): unknown;
|
|
65
67
|
/**
|
|
66
68
|
* Fits a number to what a GObject property accepts, the way an animation writing a value on every
|
|
@@ -86,5 +88,5 @@ declare function buildPropertyDispatch(source: PropertyDispatchSource): Property
|
|
|
86
88
|
*/
|
|
87
89
|
declare function getDeclaredPropertyName(object: object, accessor: string): string | undefined;
|
|
88
90
|
declare function toNativeProperties(properties: Record<string, PropertySpec>): RegisterClassProperty[];
|
|
89
|
-
export { buildPropertyDispatch, coerceObjectProperty, getDeclaredPropertyName, isReadableProperty, coercePropertyValue, constructPropertyFor, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, newParamSpecOverride, SET_PROPERTY_VFUNC, toNativeProperties, type ConstructProperty, type PropertyDispatch, type PropertySpec, };
|
|
91
|
+
export { buildPropertyDispatch, coerceObjectProperty, getDeclaredPropertyName, isReadableProperty, coercePropertyValue, constructPropertyFor, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, newParamSpecOverride, readableObjectPropertyFor, SET_PROPERTY_VFUNC, toNativeProperties, writableObjectPropertyFor, type ConstructProperty, type PropertyDispatch, type PropertySpec, };
|
|
90
92
|
//# sourceMappingURL=properties.d.ts.map
|
package/dist/properties.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../src/properties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,KAAK,QAAQ,EAA2C,MAAM,aAAa,CAAC;AAIrF,OAAO,EAQH,KAAK,UAAU,EAIlB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAMH,KAAK,iBAAiB,EACzB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAIH,KAAK,aAAa,EAElB,KAAK,WAAW,EAEnB,MAAM,YAAY,CAAC;AAEpB,KAAK,aAAa,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,UAAU,CAAC;IACzB,WAAW,EAAE,aAAa,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB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,YAAY,GACpB,CAAC"}
|
package/dist/properties.js
CHANGED
|
@@ -23,7 +23,7 @@ const paramSpecDefaultValue = bind(LIB, "g_param_spec_get_default_value", [PARAM
|
|
|
23
23
|
const paramSpecName = bind(LIB, "g_param_spec_get_name", [PARAM_T], stringT("borrowed"));
|
|
24
24
|
const typeClassRef = bind(LIB, "g_type_class_ref", [biguint64T], CLASS_T);
|
|
25
25
|
const typeClassUnref = bind(LIB, "g_type_class_unref", [CLASS_T], voidT);
|
|
26
|
-
const
|
|
26
|
+
const propertyChecks = new Map();
|
|
27
27
|
const classFindProperty = bind(LIB, "g_object_class_find_property", [CLASS_T, stringT("borrowed")], PARAM_T);
|
|
28
28
|
const classListProperties = bind(LIB, "g_object_class_list_properties", [CLASS_T, refT(uint32T)], sizedArrayT(PARAM_T, 1, "full"));
|
|
29
29
|
const defaultInterfaceRef = bind(LIB, "g_type_default_interface_ref", [biguint64T], CLASS_T);
|
|
@@ -105,7 +105,10 @@ const findSourceSpec = (source, name) => {
|
|
|
105
105
|
* @param source The GType, wrapper class or interface declaring the property.
|
|
106
106
|
* @returns Handle of the override spec.
|
|
107
107
|
*/
|
|
108
|
-
const newParamSpecOverride = (name, source) =>
|
|
108
|
+
const newParamSpecOverride = (name, source) => {
|
|
109
|
+
const canonicalName = canonicalCase(name);
|
|
110
|
+
return paramSpecOverrideNew(canonicalName, findSourceSpec(source, canonicalName));
|
|
111
|
+
};
|
|
109
112
|
function describeValue(value) {
|
|
110
113
|
if (typeof value === "string") {
|
|
111
114
|
return JSON.stringify(value);
|
|
@@ -151,6 +154,18 @@ function assertWritable(instance, check, value) {
|
|
|
151
154
|
}
|
|
152
155
|
throw new TypeError(propertyMessage(instance, check, refusalTail(check, value, READ_ONLY_REASON)));
|
|
153
156
|
}
|
|
157
|
+
function assertReadable(instance, check) {
|
|
158
|
+
if (isParamReadable(check.flags)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
throw new TypeError(propertyMessage(instance, check, `cannot read property '${check.propertyName}'; the property is write-only`));
|
|
162
|
+
}
|
|
163
|
+
function assertMutable(instance, check, value) {
|
|
164
|
+
assertWritable(instance, check, value);
|
|
165
|
+
if (isParamConstructOnly(check.flags)) {
|
|
166
|
+
throw new TypeError(propertyMessage(instance, check, refusalTail(check, value, CONSTRUCT_ONLY_REASON)));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
154
169
|
function writeHeld(check, gValue, value) {
|
|
155
170
|
check.write ??= valueWriterFor(check.valueType);
|
|
156
171
|
check.write(gValue, check.narrowValue(value));
|
|
@@ -187,7 +202,7 @@ function isReadableProperty(gtype, propertyName) {
|
|
|
187
202
|
typeClassUnref(klass);
|
|
188
203
|
}
|
|
189
204
|
}
|
|
190
|
-
function
|
|
205
|
+
function lookupPropertyCheck(gtype, name) {
|
|
191
206
|
const klass = typeClassRef(gtype);
|
|
192
207
|
try {
|
|
193
208
|
const pspec = findPropertySpec(klass, name);
|
|
@@ -197,9 +212,27 @@ function lookupCoercionCheck(gtype, name) {
|
|
|
197
212
|
typeClassUnref(klass);
|
|
198
213
|
}
|
|
199
214
|
}
|
|
200
|
-
function
|
|
201
|
-
const checks =
|
|
202
|
-
return checks.getOrInsertComputed(name, () =>
|
|
215
|
+
function propertyCheckFor(gtype, name) {
|
|
216
|
+
const checks = propertyChecks.getOrInsertComputed(gtype, () => new Map());
|
|
217
|
+
return checks.getOrInsertComputed(name, () => lookupPropertyCheck(gtype, name));
|
|
218
|
+
}
|
|
219
|
+
function objectPropertyCheckFor(instance, name) {
|
|
220
|
+
const gtype = getInstanceType(instance);
|
|
221
|
+
const check = typeIsA(gtype, TYPE_OBJECT) ? propertyCheckFor(gtype, name) : null;
|
|
222
|
+
if (check === null) {
|
|
223
|
+
throw new TypeError(`${instanceClassName(instance)} has no GObject property named '${name}'`);
|
|
224
|
+
}
|
|
225
|
+
return check;
|
|
226
|
+
}
|
|
227
|
+
function readableObjectPropertyFor(instance, name) {
|
|
228
|
+
const check = objectPropertyCheckFor(instance, name);
|
|
229
|
+
assertReadable(instance, check);
|
|
230
|
+
return { name: check.propertyName, value: newValueForType(check.valueType) };
|
|
231
|
+
}
|
|
232
|
+
function writableObjectPropertyFor(instance, name, value) {
|
|
233
|
+
const check = objectPropertyCheckFor(instance, name);
|
|
234
|
+
assertMutable(instance, check, value);
|
|
235
|
+
return { name: check.propertyName, value: checkedValueFor(instance, check, value) };
|
|
203
236
|
}
|
|
204
237
|
function truncateToWhole(check, value) {
|
|
205
238
|
const range = WHOLE_NUMBER_RANGES.get(typeFundamental(check.valueType));
|
|
@@ -226,7 +259,7 @@ function coercePropertyValue(gtype, propertyName, value) {
|
|
|
226
259
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
227
260
|
return value;
|
|
228
261
|
}
|
|
229
|
-
const check =
|
|
262
|
+
const check = propertyCheckFor(gtype, propertyName);
|
|
230
263
|
return check === null ? value : coerceNumber(check, value);
|
|
231
264
|
}
|
|
232
265
|
/**
|
|
@@ -314,23 +347,39 @@ function checkedSetter(accessor) {
|
|
|
314
347
|
writeProperty(this, accessor, value);
|
|
315
348
|
};
|
|
316
349
|
}
|
|
317
|
-
function
|
|
318
|
-
|
|
350
|
+
function memberDescriptorFor(prototype, name) {
|
|
351
|
+
let current = prototype;
|
|
352
|
+
while (current !== null) {
|
|
353
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, name);
|
|
354
|
+
if (descriptor !== undefined) {
|
|
355
|
+
return descriptor;
|
|
356
|
+
}
|
|
357
|
+
current = Reflect.getPrototypeOf(current);
|
|
358
|
+
}
|
|
359
|
+
return undefined;
|
|
360
|
+
}
|
|
361
|
+
function isMemberAccessor(descriptor) {
|
|
362
|
+
return descriptor !== undefined && ("get" in descriptor || "set" in descriptor);
|
|
319
363
|
}
|
|
320
364
|
function defineAccessor(prototype, descriptor, alias) {
|
|
321
|
-
if (
|
|
365
|
+
if (Object.getOwnPropertyDescriptor(prototype, alias) !== undefined) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const parent = Reflect.getPrototypeOf(prototype);
|
|
369
|
+
const inherited = parent === null ? undefined : memberDescriptorFor(parent, alias);
|
|
370
|
+
if (inherited !== undefined && !isMemberAccessor(inherited)) {
|
|
322
371
|
return;
|
|
323
372
|
}
|
|
324
373
|
Object.defineProperty(prototype, alias, descriptor);
|
|
325
374
|
}
|
|
326
375
|
function installAccessors(klass, accessor) {
|
|
327
376
|
const prototype = klass.prototype;
|
|
328
|
-
accessor.
|
|
377
|
+
accessor.hasMemberAccessor = isMemberAccessor(Object.getOwnPropertyDescriptor(prototype, accessor.memberName));
|
|
329
378
|
const descriptor = {
|
|
330
379
|
configurable: true,
|
|
331
380
|
enumerable: true,
|
|
332
|
-
get: accessor.
|
|
333
|
-
set: accessor.
|
|
381
|
+
get: accessor.hasMemberAccessor ? memberGetter(accessor) : storedGetter(accessor),
|
|
382
|
+
set: accessor.hasMemberAccessor ? memberSetter(accessor) : checkedSetter(accessor),
|
|
334
383
|
};
|
|
335
384
|
for (const alias of accessorNames(accessor.name)) {
|
|
336
385
|
defineAccessor(prototype, descriptor, alias);
|
|
@@ -376,7 +425,11 @@ function callMember(instance, member, args) {
|
|
|
376
425
|
return fn.apply(instance, args);
|
|
377
426
|
}
|
|
378
427
|
function backingMemberFor(instance, accessor) {
|
|
379
|
-
if (accessor.
|
|
428
|
+
if (accessor.hasMemberAccessor) {
|
|
429
|
+
return accessor.memberName;
|
|
430
|
+
}
|
|
431
|
+
const descriptor = Object.getOwnPropertyDescriptor(instance, accessor.memberName);
|
|
432
|
+
if (descriptor === undefined || ("value" in descriptor && typeof descriptor.value === "function")) {
|
|
380
433
|
return undefined;
|
|
381
434
|
}
|
|
382
435
|
return accessor.memberName;
|
|
@@ -451,7 +504,7 @@ function buildAccessor(klass, name, pspec) {
|
|
|
451
504
|
...checkFor(getHandle(pspec), name),
|
|
452
505
|
memberName: camelCase(name),
|
|
453
506
|
storage: Symbol(`gtkx:property:${name}`),
|
|
454
|
-
|
|
507
|
+
hasMemberAccessor: false,
|
|
455
508
|
};
|
|
456
509
|
installAccessors(klass, accessor);
|
|
457
510
|
return accessor;
|
|
@@ -504,5 +557,5 @@ function toNativeProperties(properties) {
|
|
|
504
557
|
pspec: getHandle(pspec),
|
|
505
558
|
}));
|
|
506
559
|
}
|
|
507
|
-
export { buildPropertyDispatch, coerceObjectProperty, getDeclaredPropertyName, isReadableProperty, coercePropertyValue, constructPropertyFor, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, newParamSpecOverride, SET_PROPERTY_VFUNC, toNativeProperties, };
|
|
560
|
+
export { buildPropertyDispatch, coerceObjectProperty, getDeclaredPropertyName, isReadableProperty, coercePropertyValue, constructPropertyFor, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, newParamSpecOverride, readableObjectPropertyFor, SET_PROPERTY_VFUNC, toNativeProperties, writableObjectPropertyFor, };
|
|
508
561
|
//# sourceMappingURL=properties.js.map
|