@gtkx/runtime 1.0.0-rc.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/README.md +5 -5
  2. package/dist/application-class.d.ts +37 -0
  3. package/dist/application-class.d.ts.map +1 -0
  4. package/dist/application-class.js +78 -0
  5. package/dist/application-class.js.map +1 -0
  6. package/dist/arg.d.ts +2 -1
  7. package/dist/arg.d.ts.map +1 -1
  8. package/dist/arg.js +2 -1
  9. package/dist/arg.js.map +1 -1
  10. package/dist/bind.d.ts +11 -0
  11. package/dist/bind.d.ts.map +1 -1
  12. package/dist/bind.js +11 -0
  13. package/dist/bind.js.map +1 -1
  14. package/dist/callback.d.ts +4 -3
  15. package/dist/callback.d.ts.map +1 -1
  16. package/dist/callback.js +124 -29
  17. package/dist/callback.js.map +1 -1
  18. package/dist/closure.d.ts +26 -0
  19. package/dist/closure.d.ts.map +1 -0
  20. package/dist/closure.js +99 -0
  21. package/dist/closure.js.map +1 -0
  22. package/dist/default-application.d.ts +4 -0
  23. package/dist/default-application.d.ts.map +1 -0
  24. package/dist/default-application.js +17 -0
  25. package/dist/default-application.js.map +1 -0
  26. package/dist/descriptors.d.ts +98 -4
  27. package/dist/descriptors.d.ts.map +1 -1
  28. package/dist/descriptors.js +72 -6
  29. package/dist/descriptors.js.map +1 -1
  30. package/dist/error.d.ts +1 -0
  31. package/dist/error.d.ts.map +1 -1
  32. package/dist/error.js.map +1 -1
  33. package/dist/exit-hook.js +13 -0
  34. package/dist/exit-hook.js.map +1 -1
  35. package/dist/fn.d.ts +24 -2
  36. package/dist/fn.d.ts.map +1 -1
  37. package/dist/fn.js +67 -32
  38. package/dist/fn.js.map +1 -1
  39. package/dist/folded-lengths.d.ts +16 -0
  40. package/dist/folded-lengths.d.ts.map +1 -0
  41. package/dist/folded-lengths.js +38 -0
  42. package/dist/folded-lengths.js.map +1 -0
  43. package/dist/index.d.ts +14 -6
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +12 -4
  46. package/dist/index.js.map +1 -1
  47. package/dist/internal.d.ts +2 -0
  48. package/dist/internal.d.ts.map +1 -1
  49. package/dist/internal.js +2 -0
  50. package/dist/internal.js.map +1 -1
  51. package/dist/library.d.ts +3 -1
  52. package/dist/library.d.ts.map +1 -1
  53. package/dist/library.js +3 -1
  54. package/dist/library.js.map +1 -1
  55. package/dist/lifecycle.d.ts +58 -11
  56. package/dist/lifecycle.d.ts.map +1 -1
  57. package/dist/lifecycle.js +95 -22
  58. package/dist/lifecycle.js.map +1 -1
  59. package/dist/listeners.d.ts.map +1 -1
  60. package/dist/listeners.js +19 -5
  61. package/dist/listeners.js.map +1 -1
  62. package/dist/mixin.d.ts +3 -2
  63. package/dist/mixin.d.ts.map +1 -1
  64. package/dist/mixin.js +13 -1
  65. package/dist/mixin.js.map +1 -1
  66. package/dist/native-value.d.ts.map +1 -1
  67. package/dist/native-value.js +4 -3
  68. package/dist/native-value.js.map +1 -1
  69. package/dist/object.d.ts +40 -7
  70. package/dist/object.d.ts.map +1 -1
  71. package/dist/object.js +95 -26
  72. package/dist/object.js.map +1 -1
  73. package/dist/param-spec.d.ts +11 -0
  74. package/dist/param-spec.d.ts.map +1 -0
  75. package/dist/param-spec.js +147 -0
  76. package/dist/param-spec.js.map +1 -0
  77. package/dist/promisify.d.ts.map +1 -1
  78. package/dist/promisify.js +3 -2
  79. package/dist/promisify.js.map +1 -1
  80. package/dist/properties.d.ts +39 -7
  81. package/dist/properties.d.ts.map +1 -1
  82. package/dist/properties.js +310 -43
  83. package/dist/properties.js.map +1 -1
  84. package/dist/register-class.d.ts +147 -12
  85. package/dist/register-class.d.ts.map +1 -1
  86. package/dist/register-class.js +129 -83
  87. package/dist/register-class.js.map +1 -1
  88. package/dist/registry.d.ts +80 -21
  89. package/dist/registry.d.ts.map +1 -1
  90. package/dist/registry.js +86 -33
  91. package/dist/registry.js.map +1 -1
  92. package/dist/signal.d.ts +11 -4
  93. package/dist/signal.d.ts.map +1 -1
  94. package/dist/signal.js +85 -25
  95. package/dist/signal.js.map +1 -1
  96. package/dist/t.d.ts +2 -0
  97. package/dist/t.d.ts.map +1 -1
  98. package/dist/t.js +1 -0
  99. package/dist/t.js.map +1 -1
  100. package/dist/tuple.d.ts +6 -3
  101. package/dist/tuple.d.ts.map +1 -1
  102. package/dist/tuple.js +9 -7
  103. package/dist/tuple.js.map +1 -1
  104. package/dist/type.d.ts +2 -1
  105. package/dist/type.d.ts.map +1 -1
  106. package/dist/type.js +2 -0
  107. package/dist/type.js.map +1 -1
  108. package/dist/value.d.ts +10 -1
  109. package/dist/value.d.ts.map +1 -1
  110. package/dist/value.js +99 -24
  111. package/dist/value.js.map +1 -1
  112. package/dist/vfunc-call.d.ts +37 -0
  113. package/dist/vfunc-call.d.ts.map +1 -0
  114. package/dist/vfunc-call.js +172 -0
  115. package/dist/vfunc-call.js.map +1 -0
  116. package/dist/vfunc-seeds.d.ts +12 -0
  117. package/dist/vfunc-seeds.d.ts.map +1 -0
  118. package/dist/vfunc-seeds.js +19 -0
  119. package/dist/vfunc-seeds.js.map +1 -0
  120. package/dist/vfunc.d.ts +8 -0
  121. package/dist/vfunc.d.ts.map +1 -0
  122. package/dist/vfunc.js +29 -0
  123. package/dist/vfunc.js.map +1 -0
  124. package/package.json +14 -4
  125. package/src/application-class.ts +126 -0
  126. package/src/arg.ts +2 -1
  127. package/src/bind.ts +11 -0
  128. package/src/callback.ts +178 -34
  129. package/src/closure.ts +136 -0
  130. package/src/default-application.ts +21 -0
  131. package/src/descriptors.ts +150 -34
  132. package/src/error.ts +1 -0
  133. package/src/exit-hook.ts +18 -0
  134. package/src/fn.ts +107 -36
  135. package/src/folded-lengths.ts +64 -0
  136. package/src/index.ts +21 -6
  137. package/src/internal.ts +2 -0
  138. package/src/library.ts +3 -1
  139. package/src/lifecycle.ts +138 -25
  140. package/src/listeners.ts +25 -6
  141. package/src/mixin.ts +15 -2
  142. package/src/native-value.ts +5 -3
  143. package/src/object.ts +134 -35
  144. package/src/param-spec.ts +234 -0
  145. package/src/promisify.ts +4 -2
  146. package/src/properties.ts +473 -46
  147. package/src/register-class.ts +386 -114
  148. package/src/registry.ts +169 -49
  149. package/src/signal.ts +116 -42
  150. package/src/t.ts +3 -0
  151. package/src/tuple.ts +18 -12
  152. package/src/type.ts +3 -1
  153. package/src/value.ts +143 -23
  154. package/src/vfunc-call.ts +247 -0
  155. package/src/vfunc-seeds.ts +36 -0
  156. package/src/vfunc.ts +38 -0
@@ -1 +1 @@
1
- {"version":3,"file":"native-value.js","sourceRoot":"","sources":["../src/native-value.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAKlD,MAAM,gBAAgB,GAA4B,IAAI,GAAG,CAAiB;IACtE,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,aAAa;IACb,OAAO;IACP,WAAW;CACd,CAAC,CAAC;AAEH,SAAS,sBAAsB,CAAC,UAAsB;IAClD,OAAO,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,aAAa,CAClB,UAA2B,EAC3B,KAAc,EACd,OAA+D;IAE/D,OAAQ,KAAmB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC;AACxF,CAAC;AAED,SAAS,oBAAoB,CAAC,UAA2B,EAAE,KAAc;IACrE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,eAAe,CAAC,UAAsB,EAAE,KAAc;IAC3D,OAAO,KAAK,IAAI,IAAI;QAChB,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CAAC,CAAC;YACjB,OAAO,YAAY,CAAC,KAAkC,CAAC,IAAI,IAAI,CAAC;QACpE,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACX,OAAO,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;QACD,KAAK,WAAW,CAAC,CAAC,CAAC;YACf,OAAO,iBAAiB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAChD,CAAC;IACL,CAAC;AACL,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["import type { Descriptor, ExternalObject, Handle } from \"@gtkx/native\";\nimport type { ArrayDescriptor, FundamentalDescriptor, HashTableDescriptor, StructDescriptor } from \"./descriptors.js\";\nimport { getWrapperClass, tryGetHandle, wrapHandle } from \"./registry.js\";\nimport { resolveDescriptorType } from \"./type.js\";\n\ntype MarshalledKind = \"object\" | \"struct\" | \"boxed\" | \"fundamental\" | \"array\" | \"hashtable\";\ntype MarshalledDescriptor = Extract<Descriptor, { kind: MarshalledKind }>;\n\nconst MARSHALLED_KINDS: Set<Descriptor[\"kind\"]> = new Set<MarshalledKind>([\n \"object\",\n \"struct\",\n \"boxed\",\n \"fundamental\",\n \"array\",\n \"hashtable\",\n]);\n\nfunction isMarshalledDescriptor(descriptor: Descriptor): descriptor is MarshalledDescriptor {\n return MARSHALLED_KINDS.has(descriptor.kind);\n}\n\nfunction mapCollection(\n descriptor: ArrayDescriptor,\n value: unknown,\n convert: (itemDescriptor: Descriptor, item: unknown) => unknown,\n): unknown[] {\n return (value as unknown[]).map((item) => convert(descriptor.itemDescriptor, item));\n}\n\nfunction collectionFromNative(descriptor: ArrayDescriptor, value: unknown): unknown {\n return value === null ? null : mapCollection(descriptor, value, fromNative);\n}\n\nfunction boxedFromNative(descriptor: Descriptor, value: unknown): unknown {\n return value == null\n ? null\n : wrapHandle(value as ExternalObject<Handle>, getWrapperClass(resolveDescriptorType(descriptor)));\n}\n\nfunction fundamentalFromNative(descriptor: FundamentalDescriptor, value: unknown): unknown {\n return value == null\n ? null\n : wrapHandle(\n value as ExternalObject<Handle>,\n descriptor.wrapperClass ?? getWrapperClass(resolveDescriptorType(descriptor)),\n );\n}\n\nfunction hashTableFromNative(descriptor: HashTableDescriptor, value: unknown): unknown {\n if (value === null) {\n return null;\n }\n\n const entries = value as [unknown, unknown][];\n\n return new Map(\n entries.map(([key, val]): [unknown, unknown] => [\n fromNative(descriptor.keyDescriptor, key),\n fromNative(descriptor.valueDescriptor, val),\n ]),\n );\n}\n\n/**\n * Converts a raw value returned from native code into its JavaScript form,\n * wrapping object, struct, boxed, and fundamental handles and recursively\n * converting arrays and hash tables according to the descriptor.\n *\n * @param descriptor Describes the native type of the value.\n * @param value The raw native value to convert.\n */\nfunction fromNative(descriptor: Descriptor, value: unknown): unknown {\n if (!isMarshalledDescriptor(descriptor)) {\n return value;\n }\n\n switch (descriptor.kind) {\n case \"object\": {\n return wrapHandle(value as ExternalObject<Handle> | null);\n }\n case \"struct\": {\n return wrapHandle(value as ExternalObject<Handle> | null, (descriptor as StructDescriptor).wrapperClass);\n }\n case \"boxed\": {\n return boxedFromNative(descriptor, value);\n }\n case \"fundamental\": {\n return fundamentalFromNative(descriptor, value);\n }\n case \"array\": {\n return collectionFromNative(descriptor, value);\n }\n case \"hashtable\": {\n return hashTableFromNative(descriptor, value);\n }\n }\n}\n\nfunction collectionToNative(descriptor: ArrayDescriptor, value: unknown): unknown {\n return value == null ? null : mapCollection(descriptor, value, toNative);\n}\n\nfunction hashTableToNative(descriptor: HashTableDescriptor, value: unknown): unknown {\n if (value == null) {\n return null;\n }\n\n return [...(value as Map<unknown, unknown>)].map(([key, val]): [unknown, unknown] => [\n toNative(descriptor.keyDescriptor, key),\n toNative(descriptor.valueDescriptor, val),\n ]);\n}\n\n/**\n * Converts a JavaScript value into the raw form native code expects, unwrapping\n * object, struct, boxed, and fundamental wrappers back to their handles and\n * recursively converting arrays and maps according to the descriptor.\n *\n * @param descriptor Describes the native type to convert to.\n * @param value The JavaScript value to convert.\n */\nfunction toNative(descriptor: Descriptor, value: unknown): unknown {\n if (!isMarshalledDescriptor(descriptor)) {\n return value;\n }\n\n switch (descriptor.kind) {\n case \"object\":\n case \"struct\":\n case \"boxed\":\n case \"fundamental\": {\n return tryGetHandle(value as object | null | undefined) ?? null;\n }\n case \"array\": {\n return collectionToNative(descriptor, value);\n }\n case \"hashtable\": {\n return hashTableToNative(descriptor, value);\n }\n }\n}\n\nexport { fromNative, toNative };\n"]}
1
+ {"version":3,"file":"native-value.js","sourceRoot":"","sources":["../src/native-value.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,oBAAoB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAKlD,MAAM,gBAAgB,GAA4B,IAAI,GAAG,CAAiB;IACtE,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,aAAa;IACb,OAAO;IACP,WAAW;CACd,CAAC,CAAC;AAEH,SAAS,sBAAsB,CAAC,UAAsB;IAClD,OAAO,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,aAAa,CAClB,UAA2B,EAC3B,KAAc,EACd,OAA+D;IAE/D,OAAQ,KAAmB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC;AACxF,CAAC;AAED,SAAS,oBAAoB,CAAC,UAA2B,EAAE,KAAc;IACrE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,eAAe,CAAC,UAAsB,EAAE,KAAc;IAC3D,OAAO,KAAK,I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,EAAE,CAAC;QACtB,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,OAAO,CAAC;QACb,KAAK,aAAa,CAAC,CAAC,CAAC;YACjB,MAAM,QAAQ,GAAG,KAAkC,CAAC;YAEpD,OAAO,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACzD,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACX,OAAO,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;QACD,KAAK,WAAW,CAAC,CAAC,CAAC;YACf,OAAO,iBAAiB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAChD,CAAC;IACL,CAAC;AACL,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["import type { Descriptor, ExternalObject, Handle } from \"@gtkx/native\";\nimport type { ArrayDescriptor, FundamentalDescriptor, HashTableDescriptor, StructDescriptor } from \"./descriptors.js\";\nimport { getHandle, getWrapperClass, wrapCallScopedObject, wrapHandle, wrapObject } from \"./registry.js\";\nimport { resolveDescriptorType } from \"./type.js\";\n\ntype MarshalledKind = \"object\" | \"struct\" | \"boxed\" | \"fundamental\" | \"array\" | \"hashtable\";\ntype MarshalledDescriptor = Extract<Descriptor, { kind: MarshalledKind }>;\n\nconst MARSHALLED_KINDS: Set<Descriptor[\"kind\"]> = new Set<MarshalledKind>([\n \"object\",\n \"struct\",\n \"boxed\",\n \"fundamental\",\n \"array\",\n \"hashtable\",\n]);\n\nfunction isMarshalledDescriptor(descriptor: Descriptor): descriptor is MarshalledDescriptor {\n return MARSHALLED_KINDS.has(descriptor.kind);\n}\n\nfunction mapCollection(\n descriptor: ArrayDescriptor,\n value: unknown,\n convert: (itemDescriptor: Descriptor, item: unknown) => unknown,\n): unknown[] {\n return (value as unknown[]).map((item) => convert(descriptor.itemDescriptor, item));\n}\n\nfunction collectionFromNative(descriptor: ArrayDescriptor, value: unknown): unknown {\n return value === null ? null : mapCollection(descriptor, value, fromNative);\n}\n\nfunction boxedFromNative(descriptor: Descriptor, value: unknown): unknown {\n return value == null\n ? null\n : wrapHandle(value as ExternalObject<Handle>, getWrapperClass(resolveDescriptorType(descriptor)));\n}\n\nfunction fundamentalFromNative(descriptor: FundamentalDescriptor, value: unknown): unknown {\n return value == null\n ? null\n : wrapHandle(\n value as ExternalObject<Handle>,\n descriptor.wrapperClass ?? getWrapperClass(resolveDescriptorType(descriptor)),\n );\n}\n\nfunction hashTableFromNative(descriptor: HashTableDescriptor, value: unknown): unknown {\n if (value === null) {\n return null;\n }\n\n const entries = value as [unknown, unknown][];\n\n return new Map(\n entries.map(([key, val]): [unknown, unknown] => [\n fromNative(descriptor.keyDescriptor, key),\n fromNative(descriptor.valueDescriptor, val),\n ]),\n );\n}\n\n/**\n * Converts a raw value returned from native code into its JavaScript form,\n * wrapping object, struct, boxed, and fundamental handles and recursively\n * converting arrays and hash tables according to the descriptor.\n *\n * @param descriptor Describes the native type of the value.\n * @param value The raw native value to convert.\n */\nfunction fromNative(descriptor: Descriptor, value: unknown): unknown {\n if (!isMarshalledDescriptor(descriptor)) {\n return value;\n }\n\n switch (descriptor.kind) {\n case \"object\": {\n return descriptor.isCallScoped === true ? wrapCallScopedObject(value) : wrapObject(value);\n }\n case \"struct\": {\n return wrapHandle(value as ExternalObject<Handle> | null, (descriptor as StructDescriptor).wrapperClass);\n }\n case \"boxed\": {\n return boxedFromNative(descriptor, value);\n }\n case \"fundamental\": {\n return fundamentalFromNative(descriptor, value);\n }\n case \"array\": {\n return collectionFromNative(descriptor, value);\n }\n case \"hashtable\": {\n return hashTableFromNative(descriptor, value);\n }\n }\n}\n\nfunction collectionToNative(descriptor: ArrayDescriptor, value: unknown): unknown {\n return value == null ? null : mapCollection(descriptor, value, toNative);\n}\n\nfunction hashTableToNative(descriptor: HashTableDescriptor, value: unknown): unknown {\n if (value == null) {\n return null;\n }\n\n return [...(value as Map<unknown, unknown>)].map(([key, val]): [unknown, unknown] => [\n toNative(descriptor.keyDescriptor, key),\n toNative(descriptor.valueDescriptor, val),\n ]);\n}\n\n/**\n * Converts a JavaScript value into the raw form native code expects, unwrapping\n * object, struct, boxed, and fundamental wrappers back to their handles and\n * recursively converting arrays and maps according to the descriptor.\n *\n * @param descriptor Describes the native type to convert to.\n * @param value The JavaScript value to convert.\n */\nfunction toNative(descriptor: Descriptor, value: unknown): unknown {\n if (!isMarshalledDescriptor(descriptor)) {\n return value;\n }\n\n switch (descriptor.kind) {\n case \"object\":\n case \"struct\":\n case \"boxed\":\n case \"fundamental\": {\n const instance = value as object | null | undefined;\n\n return instance == null ? null : getHandle(instance);\n }\n case \"array\": {\n return collectionToNative(descriptor, value);\n }\n case \"hashtable\": {\n return hashTableToNative(descriptor, value);\n }\n }\n}\n\nexport { fromNative, toNative };\n"]}
package/dist/object.d.ts CHANGED
@@ -1,14 +1,44 @@
1
- import type { Descriptor, ExternalObject, Handle } from "@gtkx/native";
1
+ import { type Descriptor, type ExternalObject, type Handle } from "@gtkx/native";
2
+ import { type AnyClass } from "@gtkx/utils";
3
+ /**
4
+ * One construct property a wrapper class accepts: the canonical `GObject` name it is set under,
5
+ * and the descriptor its value is marshalled through.
6
+ */
7
+ type ConstructBinding = [name: string, descriptor: Descriptor];
8
+ /** The construct properties a wrapper class accepts, keyed by the camelCased name callers give them. */
9
+ type ConstructBindings = Record<string, ConstructBinding>;
10
+ /**
11
+ * Declares the construct properties a wrapper class accepts, so `newObjectWithProperties`
12
+ * marshals each one through its descriptor rather than resolving it from the
13
+ * `GObject.ParamSpec` the type installs. A class inherits the declarations of its ancestors.
14
+ * Registering takes effect immediately, including for classes already constructed from and for
15
+ * subclasses that already inherited an earlier declaration.
16
+ *
17
+ * @param cls The wrapper class the properties are declared on.
18
+ * @param bindings CamelCased property names mapped to their canonical name and descriptor.
19
+ */
20
+ declare function registerConstructProperties(cls: AnyClass, bindings: ConstructBindings): void;
2
21
  /**
3
22
  * Constructs a new GObject of the given type, setting the supplied construct
4
- * properties. Entries whose value is `undefined` or not a `[descriptor, value]`
5
- * pair are skipped.
23
+ * properties, and binds `wrapper` to it. A property the wrapper's class declares
24
+ * through `registerConstructProperties` is marshalled through its descriptor; any
25
+ * other one is marshalled through the `GObject.ParamSpec` the type installs under
26
+ * that name, dashed or camelCased, and is skipped when the type installs none.
27
+ * A value that ParamSpec would refuse throws before GObject sees it: a `TypeError`
28
+ * for a read-only property and for a value of a type the property cannot hold, and
29
+ * a `RangeError` for a value the ParamSpec rejects. A value marshalled through a
30
+ * declared descriptor is converted rather than checked, so a `null` handed to a
31
+ * numeric one of those lands 0 rather than being refused.
32
+ * Properties whose value is `undefined` are skipped. A type registered with
33
+ * `registerClass` binds the wrapper before its `constructed` slot runs, so an
34
+ * override of that slot already sees a usable instance.
6
35
  *
7
36
  * @param gtype The GType of the object to construct.
8
- * @param props Property names mapped to `[descriptor, value]` pairs.
37
+ * @param props Property names mapped to the values to set them to.
38
+ * @param wrapper The wrapper instance to bind to the new object.
9
39
  * @returns The handle of the newly created object.
10
40
  */
11
- declare function newObjectWithProperties(gtype: bigint, props: Record<string, unknown>): ExternalObject<Handle>;
41
+ declare function newObjectWithProperties(gtype: bigint, props: object, wrapper: object): ExternalObject<Handle>;
12
42
  /**
13
43
  * Reads a GObject property and converts it to its JavaScript value using the
14
44
  * descriptor.
@@ -20,7 +50,10 @@ declare function newObjectWithProperties(gtype: bigint, props: Record<string, un
20
50
  declare function getObjectProperty(obj: object, propertyName: string, descriptor: Descriptor): unknown;
21
51
  /**
22
52
  * Writes a JavaScript value to a GObject property, converting it to native form
23
- * using the descriptor.
53
+ * using the descriptor. The descriptor converts what it is given rather than checking it against
54
+ * the property's `GObject.ParamSpec`, so `null` and `undefined` written to a numeric or enum
55
+ * property land 0, where the same write to a property installed through `registerClass` is
56
+ * refused with a `TypeError`.
24
57
  *
25
58
  * @param obj The object to write to.
26
59
  * @param propertyName The property name.
@@ -28,5 +61,5 @@ declare function getObjectProperty(obj: object, propertyName: string, descriptor
28
61
  * @param jsValue The value to set.
29
62
  */
30
63
  declare function setObjectProperty(obj: object, propertyName: string, descriptor: Descriptor, jsValue: unknown): void;
31
- export { newObjectWithProperties, getObjectProperty, setObjectProperty };
64
+ export { newObjectWithProperties, getObjectProperty, registerConstructProperties, setObjectProperty, type ConstructBinding, type ConstructBindings, };
32
65
  //# sourceMappingURL=object.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiCvE;;;;;;;;GAQG;AACH,iBAAS,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAsBtG;AAED;;;;;;;GAOG;AACH,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAK7F;AAED;;;;;;;;GAQG;AACH,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAE5G;AAED,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAa,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,KAAK,QAAQ,EAAkB,MAAM,aAAa,CAAC;AAQ5D;;;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;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAkBtG;AAED;;;;;;;GAOG;AACH,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAK7F;AAED;;;;;;;;;;;GAWG;AACH,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAE5G;AAED,OAAO,EACH,uBAAuB,EACvB,iBAAiB,EACjB,2BAA2B,EAC3B,iBAAiB,EACjB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACzB,CAAC"}
package/dist/object.js CHANGED
@@ -1,41 +1,107 @@
1
+ import { newObject } from "@gtkx/native";
2
+ import { getParentClass } from "@gtkx/utils";
1
3
  import { bind } from "./bind.js";
2
- import { biguint64T, objectT, sizedArrayT, stringT, uint32T, voidT } from "./descriptors.js";
3
- import { LIB, VALUE_SIZE, VALUE_T } from "./library.js";
4
- import { getHandle } from "./registry.js";
4
+ import { objectT, stringT, voidT } from "./descriptors.js";
5
+ import { LIB, VALUE_T } from "./library.js";
6
+ import { constructPropertyFor } from "./properties.js";
7
+ import { getHandle, registerWrapper } from "./registry.js";
5
8
  import { fromValue, newValueForDescriptor, toValue } from "./value.js";
6
- const gObjectNewWithProperties = bind(LIB, "g_object_new_with_properties", [
7
- biguint64T,
8
- uint32T,
9
- sizedArrayT(stringT("borrowed"), 1, "borrowed"),
10
- sizedArrayT(VALUE_T, 1, "borrowed", VALUE_SIZE),
11
- ], objectT("full"));
9
+ const declaredBindings = new WeakMap();
10
+ const resolvedBindings = new WeakMap();
11
+ const declarations = { generation: 0 };
12
+ const NO_BINDINGS = Object.create(null);
12
13
  const gObjectGetProperty = bind(LIB, "g_object_get_property", [objectT("borrowed"), stringT("borrowed"), VALUE_T], voidT);
13
14
  const gObjectSetProperty = bind(LIB, "g_object_set_property", [objectT("borrowed"), stringT("borrowed"), VALUE_T], voidT);
15
+ function collectDeclaredBindings(cls) {
16
+ const declared = [];
17
+ let current = cls;
18
+ while (current !== null) {
19
+ const own = declaredBindings.get(current);
20
+ if (own !== undefined) {
21
+ declared.push(own);
22
+ }
23
+ current = getParentClass(current);
24
+ }
25
+ return declared;
26
+ }
27
+ function mergeDeclaredBindings(cls) {
28
+ const declared = collectDeclaredBindings(cls);
29
+ const merged = Object.create(null);
30
+ for (let index = declared.length - 1; index >= 0; index--) {
31
+ Object.assign(merged, declared[index]);
32
+ }
33
+ return merged;
34
+ }
35
+ function constructBindingsFor(cls) {
36
+ if (cls === undefined) {
37
+ return NO_BINDINGS;
38
+ }
39
+ const cached = resolvedBindings.get(cls);
40
+ if (cached?.generation === declarations.generation) {
41
+ return cached.bindings;
42
+ }
43
+ const bindings = mergeDeclaredBindings(cls);
44
+ resolvedBindings.set(cls, { generation: declarations.generation, bindings });
45
+ return bindings;
46
+ }
47
+ /**
48
+ * Declares the construct properties a wrapper class accepts, so `newObjectWithProperties`
49
+ * marshals each one through its descriptor rather than resolving it from the
50
+ * `GObject.ParamSpec` the type installs. A class inherits the declarations of its ancestors.
51
+ * Registering takes effect immediately, including for classes already constructed from and for
52
+ * subclasses that already inherited an earlier declaration.
53
+ *
54
+ * @param cls The wrapper class the properties are declared on.
55
+ * @param bindings CamelCased property names mapped to their canonical name and descriptor.
56
+ */
57
+ function registerConstructProperties(cls, bindings) {
58
+ declaredBindings.set(cls, bindings);
59
+ declarations.generation += 1;
60
+ }
61
+ function constructPropertyForEntry(source, name, value) {
62
+ if (value === undefined) {
63
+ return undefined;
64
+ }
65
+ const binding = source.bindings[name];
66
+ if (binding === undefined) {
67
+ return constructPropertyFor(source.gtype, name, value, source.wrapper);
68
+ }
69
+ return { name: binding[0], value: toValue(binding[1], value) };
70
+ }
14
71
  /**
15
72
  * Constructs a new GObject of the given type, setting the supplied construct
16
- * properties. Entries whose value is `undefined` or not a `[descriptor, value]`
17
- * pair are skipped.
73
+ * properties, and binds `wrapper` to it. A property the wrapper's class declares
74
+ * through `registerConstructProperties` is marshalled through its descriptor; any
75
+ * other one is marshalled through the `GObject.ParamSpec` the type installs under
76
+ * that name, dashed or camelCased, and is skipped when the type installs none.
77
+ * A value that ParamSpec would refuse throws before GObject sees it: a `TypeError`
78
+ * for a read-only property and for a value of a type the property cannot hold, and
79
+ * a `RangeError` for a value the ParamSpec rejects. A value marshalled through a
80
+ * declared descriptor is converted rather than checked, so a `null` handed to a
81
+ * numeric one of those lands 0 rather than being refused.
82
+ * Properties whose value is `undefined` are skipped. A type registered with
83
+ * `registerClass` binds the wrapper before its `constructed` slot runs, so an
84
+ * override of that slot already sees a usable instance.
18
85
  *
19
86
  * @param gtype The GType of the object to construct.
20
- * @param props Property names mapped to `[descriptor, value]` pairs.
87
+ * @param props Property names mapped to the values to set them to.
88
+ * @param wrapper The wrapper instance to bind to the new object.
21
89
  * @returns The handle of the newly created object.
22
90
  */
23
- function newObjectWithProperties(gtype, props) {
91
+ function newObjectWithProperties(gtype, props, wrapper) {
24
92
  const names = [];
25
93
  const values = [];
26
- for (const name in props) {
27
- const entry = props[name];
28
- if (!Array.isArray(entry)) {
29
- continue;
30
- }
31
- const [descriptor, value] = entry;
32
- if (value === undefined) {
33
- continue;
94
+ const bindings = constructBindingsFor(wrapper.constructor);
95
+ const source = { gtype, bindings, wrapper };
96
+ for (const name of Object.keys(props)) {
97
+ const property = constructPropertyForEntry(source, name, Reflect.get(props, name));
98
+ if (property !== undefined) {
99
+ names.push(property.name);
100
+ values.push(property.value);
34
101
  }
35
- names.push(name);
36
- values.push(toValue(descriptor, value));
37
102
  }
38
- return gObjectNewWithProperties(gtype, names.length, names, values);
103
+ newObject(gtype, names, values, wrapper, registerWrapper);
104
+ return getHandle(wrapper);
39
105
  }
40
106
  /**
41
107
  * Reads a GObject property and converts it to its JavaScript value using the
@@ -52,7 +118,10 @@ function getObjectProperty(obj, propertyName, descriptor) {
52
118
  }
53
119
  /**
54
120
  * Writes a JavaScript value to a GObject property, converting it to native form
55
- * using the descriptor.
121
+ * using the descriptor. The descriptor converts what it is given rather than checking it against
122
+ * the property's `GObject.ParamSpec`, so `null` and `undefined` written to a numeric or enum
123
+ * property land 0, where the same write to a property installed through `registerClass` is
124
+ * refused with a `TypeError`.
56
125
  *
57
126
  * @param obj The object to write to.
58
127
  * @param propertyName The property name.
@@ -62,5 +131,5 @@ function getObjectProperty(obj, propertyName, descriptor) {
62
131
  function setObjectProperty(obj, propertyName, descriptor, jsValue) {
63
132
  gObjectSetProperty(getHandle(obj), propertyName, toValue(descriptor, jsValue));
64
133
  }
65
- export { newObjectWithProperties, getObjectProperty, setObjectProperty };
134
+ export { newObjectWithProperties, getObjectProperty, registerConstructProperties, setObjectProperty, };
66
135
  //# sourceMappingURL=object.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAA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,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,wBAAwB,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAA2B,CAAC;AAClG,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,SAAS,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;GAQG;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,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import type { Descriptor, ExternalObject, Handle } from \"@gtkx/native\";\nimport { bind } from \"./bind.js\";\nimport { biguint64T, objectT, sizedArrayT, stringT, uint32T, voidT } from \"./descriptors.js\";\nimport { LIB, VALUE_SIZE, VALUE_T } from \"./library.js\";\nimport { getHandle } from \"./registry.js\";\nimport { fromValue, newValueForDescriptor, toValue } from \"./value.js\";\n\nconst gObjectNewWithProperties = bind(\n LIB,\n \"g_object_new_with_properties\",\n [\n biguint64T,\n uint32T,\n sizedArrayT(stringT(\"borrowed\"), 1, \"borrowed\"),\n sizedArrayT(VALUE_T, 1, \"borrowed\", VALUE_SIZE),\n ],\n objectT(\"full\"),\n);\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\n/**\n * Constructs a new GObject of the given type, setting the supplied construct\n * properties. Entries whose value is `undefined` or not a `[descriptor, value]`\n * pair are skipped.\n *\n * @param gtype The GType of the object to construct.\n * @param props Property names mapped to `[descriptor, value]` pairs.\n * @returns The handle of the newly created object.\n */\nfunction newObjectWithProperties(gtype: bigint, props: Record<string, unknown>): ExternalObject<Handle> {\n const names: string[] = [];\n const values: ExternalObject<Handle>[] = [];\n\n for (const name in props) {\n const entry: unknown = props[name];\n\n if (!Array.isArray(entry)) {\n continue;\n }\n\n const [descriptor, value] = entry as [Descriptor, unknown];\n\n if (value === undefined) {\n continue;\n }\n\n names.push(name);\n values.push(toValue(descriptor, value));\n }\n\n return gObjectNewWithProperties(gtype, names.length, names, values) as ExternalObject<Handle>;\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 fromValue(value);\n}\n\n/**\n * Writes a JavaScript value to a GObject property, converting it to native form\n * using the descriptor.\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 { newObjectWithProperties, getObjectProperty, setObjectProperty };\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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AS,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC;IAE1D,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;AAC9B,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,SAAS,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;GAWG;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 { type ConstructProperty, constructPropertyFor } from \"./properties.js\";\nimport { getHandle, registerWrapper } from \"./registry.js\";\nimport { fromValue, 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], 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.\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 *\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 handle of the newly created object.\n */\nfunction newObjectWithProperties(gtype: bigint, props: object, wrapper: object): ExternalObject<Handle> {\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 newObject(gtype, names, values, wrapper, registerWrapper);\n\n return getHandle(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 fromValue(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, where the same write to a property installed through `registerClass` is\n * refused with a `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"]}
@@ -0,0 +1,11 @@
1
+ import { type ExternalObject, type Handle } from "@gtkx/native";
2
+ type ValueGuard = (value: unknown) => boolean;
3
+ declare const getParamFlags: (pspec: ExternalObject<Handle>) => number;
4
+ declare const getParamValueType: (pspec: ExternalObject<Handle>) => bigint;
5
+ declare const isParamWritable: (flags: number) => boolean;
6
+ declare const isParamConstructOnly: (flags: number) => boolean;
7
+ declare const isParamLaxlyValidated: (flags: number) => boolean;
8
+ declare const wasParamValueModified: (pspec: ExternalObject<Handle>, value: ExternalObject<Handle>) => boolean;
9
+ declare function valueGuardFor(valueType: bigint): ValueGuard;
10
+ export { getParamFlags, getParamValueType, isParamConstructOnly, isParamLaxlyValidated, isParamWritable, type ValueGuard, valueGuardFor, wasParamValueModified, };
11
+ //# sourceMappingURL=param-spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"param-spec.d.ts","sourceRoot":"","sources":["../src/param-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAQ,MAAM,cAAc,CAAC;AAkCtE,KAAK,UAAU,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AA6D9C,QAAA,MAAM,aAAa,GAAI,OAAO,cAAc,CAAC,MAAM,CAAC,KAAG,MAA2D,CAAC;AAEnH,QAAA,MAAM,iBAAiB,GAAI,OAAO,cAAc,CAAC,MAAM,CAAC,KAAG,MACE,CAAC;AAE9D,QAAA,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,OAAyC,CAAC;AACnF,QAAA,MAAM,oBAAoB,GAAI,OAAO,MAAM,KAAG,OAA+C,CAAC;AAC9F,QAAA,MAAM,qBAAqB,GAAI,OAAO,MAAM,KAAG,OAA+C,CAAC;AAE/F,QAAA,MAAM,qBAAqB,GAAI,OAAO,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC,KAAG,OAC/C,CAAC;AAoEhD,iBAAS,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAepD;AAoCD,OAAO,EACH,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,KAAK,UAAU,EACf,aAAa,EACb,qBAAqB,GACxB,CAAC"}
@@ -0,0 +1,147 @@
1
+ import { read } from "@gtkx/native";
2
+ import { bind } from "./bind.js";
3
+ import { biguint64T, booleanT, stringT, uint32T, voidT } from "./descriptors.js";
4
+ import { LIB, PARAM_T, VALUE_T } from "./library.js";
5
+ import { getInstanceType } from "./registry.js";
6
+ import { getStrvType, isTypedClass, TYPE_BOOLEAN, TYPE_BOXED, TYPE_CHAR, TYPE_DOUBLE, TYPE_ENUM, TYPE_FLAGS, TYPE_FLOAT, TYPE_GTYPE, TYPE_INT, TYPE_INT64, TYPE_INTERFACE, TYPE_INVALID, TYPE_LONG, TYPE_OBJECT, TYPE_PARAM, TYPE_POINTER, TYPE_STRING, TYPE_UCHAR, TYPE_UINT, TYPE_UINT64, TYPE_ULONG, TYPE_VARIANT, typeFundamental, typeIsA, } from "./type.js";
7
+ const PARAM_READABLE = 1;
8
+ const PARAM_WRITABLE = 2;
9
+ const PARAM_CONSTRUCT_ONLY = 8;
10
+ const PARAM_LAX_VALIDATION = 16;
11
+ const READ_FLAGS = PARAM_READABLE | PARAM_WRITABLE | PARAM_CONSTRUCT_ONLY | PARAM_LAX_VALIDATION;
12
+ const FLAGS_BYTE_OFFSET = 16;
13
+ const VALUE_TYPE_BYTE_OFFSET = 24;
14
+ const LAYOUT_PROBE_NAME = "gtkx-param-layout";
15
+ const INT8_MINIMUM = -128;
16
+ const INT8_MAXIMUM = 127;
17
+ const UINT8_MAXIMUM = 255;
18
+ const INT32_MINIMUM = -2_147_483_648;
19
+ const INT32_MAXIMUM = 2_147_483_647;
20
+ const UINT32_MAXIMUM = 4_294_967_295;
21
+ const INT64_MINIMUM = -(2n ** 63n);
22
+ const INT64_MAXIMUM = 2n ** 63n - 1n;
23
+ const UINT64_MAXIMUM = 2n ** 64n - 1n;
24
+ const WRAPPED_FUNDAMENTALS = new Set([
25
+ TYPE_BOXED,
26
+ TYPE_INTERFACE,
27
+ TYPE_OBJECT,
28
+ TYPE_PARAM,
29
+ TYPE_VARIANT,
30
+ ]);
31
+ const isWideUnsignedValue = wideIntegerGuardFor(0n, UINT64_MAXIMUM);
32
+ const SCALAR_GUARDS = new Map([
33
+ [TYPE_BOOLEAN, isBooleanValue],
34
+ [TYPE_STRING, isStringValue],
35
+ [TYPE_CHAR, integerGuardFor(INT8_MINIMUM, INT8_MAXIMUM)],
36
+ [TYPE_UCHAR, integerGuardFor(0, UINT8_MAXIMUM)],
37
+ [TYPE_INT, integerGuardFor(INT32_MINIMUM, INT32_MAXIMUM)],
38
+ [TYPE_UINT, integerGuardFor(0, UINT32_MAXIMUM)],
39
+ [TYPE_ENUM, integerGuardFor(INT32_MINIMUM, INT32_MAXIMUM)],
40
+ [TYPE_FLAGS, integerGuardFor(0, UINT32_MAXIMUM)],
41
+ [TYPE_LONG, wideIntegerGuardFor(INT64_MINIMUM, INT64_MAXIMUM)],
42
+ [TYPE_ULONG, isWideUnsignedValue],
43
+ [TYPE_INT64, wideIntegerGuardFor(INT64_MINIMUM, INT64_MAXIMUM)],
44
+ [TYPE_UINT64, isWideUnsignedValue],
45
+ [TYPE_FLOAT, isNumberValue],
46
+ [TYPE_DOUBLE, isNumberValue],
47
+ [TYPE_POINTER, isNullValue],
48
+ ]);
49
+ const layout = { wasChecked: false };
50
+ const paramValueValidate = bind(LIB, "g_param_value_validate", [PARAM_T, VALUE_T], booleanT);
51
+ const paramSpecUnref = bind(LIB, "g_param_spec_unref", [PARAM_T], voidT);
52
+ const paramSpecRefSink = bind(LIB, "g_param_spec_ref_sink", [PARAM_T], PARAM_T);
53
+ const newParamSpecBoolean = bind(LIB, "g_param_spec_boolean", [stringT("borrowed"), stringT("borrowed"), stringT("borrowed"), booleanT, uint32T], PARAM_T);
54
+ const getParamFlags = (pspec) => read(pspec, uint32T, FLAGS_BYTE_OFFSET);
55
+ const getParamValueType = (pspec) => read(pspec, biguint64T, VALUE_TYPE_BYTE_OFFSET);
56
+ const isParamWritable = (flags) => (flags & PARAM_WRITABLE) !== 0;
57
+ const isParamConstructOnly = (flags) => (flags & PARAM_CONSTRUCT_ONLY) !== 0;
58
+ const isParamLaxlyValidated = (flags) => (flags & PARAM_LAX_VALIDATION) !== 0;
59
+ const wasParamValueModified = (pspec, value) => paramValueValidate(pspec, value);
60
+ function isBooleanValue(value) {
61
+ return typeof value === "boolean";
62
+ }
63
+ function isStringValue(value) {
64
+ return value == null || typeof value === "string";
65
+ }
66
+ function isStrvValue(value) {
67
+ return value == null || (Array.isArray(value) && value.every((item) => typeof item === "string"));
68
+ }
69
+ function isNumberValue(value) {
70
+ return typeof value === "number";
71
+ }
72
+ function isAnyValue() {
73
+ return true;
74
+ }
75
+ function isNullValue(value) {
76
+ return value == null;
77
+ }
78
+ function integerGuardFor(minimum, maximum) {
79
+ return (value) => Number.isSafeInteger(value) && value >= minimum && value <= maximum;
80
+ }
81
+ function toWideInteger(value) {
82
+ if (typeof value === "bigint") {
83
+ return value;
84
+ }
85
+ return Number.isSafeInteger(value) ? BigInt(value) : undefined;
86
+ }
87
+ function wideIntegerGuardFor(minimum, maximum) {
88
+ return (value) => {
89
+ const wide = toWideInteger(value);
90
+ return wide !== undefined && wide >= minimum && wide <= maximum;
91
+ };
92
+ }
93
+ function resolveGtype(value) {
94
+ const instanceType = getInstanceType(value);
95
+ if (instanceType !== TYPE_INVALID) {
96
+ return instanceType;
97
+ }
98
+ return isTypedClass(value) ? value.__type__ : TYPE_INVALID;
99
+ }
100
+ function wrappedGuardFor(valueType) {
101
+ return (value) => value == null || typeIsA(resolveGtype(value), valueType);
102
+ }
103
+ function exactGuardFor(valueType) {
104
+ if (valueType === TYPE_GTYPE) {
105
+ return isWideUnsignedValue;
106
+ }
107
+ return valueType === getStrvType() ? isStrvValue : undefined;
108
+ }
109
+ function valueGuardFor(valueType) {
110
+ assertParamLayout();
111
+ const exact = exactGuardFor(valueType);
112
+ if (exact !== undefined) {
113
+ return exact;
114
+ }
115
+ const fundamental = typeFundamental(valueType);
116
+ if (WRAPPED_FUNDAMENTALS.has(fundamental)) {
117
+ return wrappedGuardFor(valueType);
118
+ }
119
+ return SCALAR_GUARDS.get(fundamental) ?? isAnyValue;
120
+ }
121
+ function readProbeLayout(flags) {
122
+ const probe = newParamSpecBoolean(LAYOUT_PROBE_NAME, null, null, false, flags);
123
+ paramSpecRefSink(probe);
124
+ try {
125
+ return { flags: getParamFlags(probe), valueType: getParamValueType(probe) };
126
+ }
127
+ finally {
128
+ paramSpecUnref(probe);
129
+ }
130
+ }
131
+ function isLayoutIntact(flags) {
132
+ const layout = readProbeLayout(flags);
133
+ return (layout.flags & READ_FLAGS) === flags && layout.valueType === TYPE_BOOLEAN;
134
+ }
135
+ function assertParamLayout() {
136
+ if (layout.wasChecked) {
137
+ return;
138
+ }
139
+ layout.wasChecked = true;
140
+ const readWrite = PARAM_READABLE | PARAM_WRITABLE;
141
+ if (isLayoutIntact(readWrite) && isLayoutIntact(readWrite | PARAM_CONSTRUCT_ONLY | PARAM_LAX_VALIDATION)) {
142
+ return;
143
+ }
144
+ throw new Error("GParamSpec does not match the memory layout this build reads a property's flags and value type at");
145
+ }
146
+ export { getParamFlags, getParamValueType, isParamConstructOnly, isParamLaxlyValidated, isParamWritable, valueGuardFor, wasParamValueModified, };
147
+ //# sourceMappingURL=param-spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"param-spec.js","sourceRoot":"","sources":["../src/param-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,IAAI,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACH,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,cAAc,EACd,YAAY,EACZ,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,eAAe,EACf,OAAO,GACV,MAAM,WAAW,CAAC;AAKnB,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,UAAU,GAAG,cAAc,GAAG,cAAc,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;AACjG,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,sBAA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;AACN,CAAC;AAED,OAAO,EACH,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EAEf,aAAa,EACb,qBAAqB,GACxB,CAAC","sourcesContent":["import { type ExternalObject, type Handle, read } from \"@gtkx/native\";\nimport { bind } from \"./bind.js\";\nimport { biguint64T, booleanT, stringT, uint32T, voidT } from \"./descriptors.js\";\nimport { LIB, PARAM_T, VALUE_T } from \"./library.js\";\nimport { getInstanceType } from \"./registry.js\";\nimport {\n getStrvType,\n isTypedClass,\n TYPE_BOOLEAN,\n TYPE_BOXED,\n TYPE_CHAR,\n TYPE_DOUBLE,\n TYPE_ENUM,\n TYPE_FLAGS,\n TYPE_FLOAT,\n TYPE_GTYPE,\n TYPE_INT,\n TYPE_INT64,\n TYPE_INTERFACE,\n TYPE_INVALID,\n TYPE_LONG,\n TYPE_OBJECT,\n TYPE_PARAM,\n TYPE_POINTER,\n TYPE_STRING,\n TYPE_UCHAR,\n TYPE_UINT,\n TYPE_UINT64,\n TYPE_ULONG,\n TYPE_VARIANT,\n typeFundamental,\n typeIsA,\n} from \"./type.js\";\n\ntype ValueGuard = (value: unknown) => boolean;\ntype ParamLayout = { flags: number; valueType: bigint };\n\nconst PARAM_READABLE = 1;\nconst PARAM_WRITABLE = 2;\nconst PARAM_CONSTRUCT_ONLY = 8;\nconst PARAM_LAX_VALIDATION = 16;\nconst READ_FLAGS = PARAM_READABLE | PARAM_WRITABLE | PARAM_CONSTRUCT_ONLY | PARAM_LAX_VALIDATION;\nconst FLAGS_BYTE_OFFSET = 16;\nconst VALUE_TYPE_BYTE_OFFSET = 24;\nconst LAYOUT_PROBE_NAME = \"gtkx-param-layout\";\nconst INT8_MINIMUM = -128;\nconst INT8_MAXIMUM = 127;\nconst UINT8_MAXIMUM = 255;\nconst INT32_MINIMUM = -2_147_483_648;\nconst INT32_MAXIMUM = 2_147_483_647;\nconst UINT32_MAXIMUM = 4_294_967_295;\nconst INT64_MINIMUM = -(2n ** 63n);\nconst INT64_MAXIMUM = 2n ** 63n - 1n;\nconst UINT64_MAXIMUM = 2n ** 64n - 1n;\n\nconst WRAPPED_FUNDAMENTALS: Set<bigint> = new Set([\n TYPE_BOXED,\n TYPE_INTERFACE,\n TYPE_OBJECT,\n TYPE_PARAM,\n TYPE_VARIANT,\n]);\n\nconst isWideUnsignedValue: ValueGuard = wideIntegerGuardFor(0n, UINT64_MAXIMUM);\n\nconst SCALAR_GUARDS: Map<bigint, ValueGuard> = new Map([\n [TYPE_BOOLEAN, isBooleanValue],\n [TYPE_STRING, isStringValue],\n [TYPE_CHAR, integerGuardFor(INT8_MINIMUM, INT8_MAXIMUM)],\n [TYPE_UCHAR, integerGuardFor(0, UINT8_MAXIMUM)],\n [TYPE_INT, integerGuardFor(INT32_MINIMUM, INT32_MAXIMUM)],\n [TYPE_UINT, integerGuardFor(0, UINT32_MAXIMUM)],\n [TYPE_ENUM, integerGuardFor(INT32_MINIMUM, INT32_MAXIMUM)],\n [TYPE_FLAGS, integerGuardFor(0, UINT32_MAXIMUM)],\n [TYPE_LONG, wideIntegerGuardFor(INT64_MINIMUM, INT64_MAXIMUM)],\n [TYPE_ULONG, isWideUnsignedValue],\n [TYPE_INT64, wideIntegerGuardFor(INT64_MINIMUM, INT64_MAXIMUM)],\n [TYPE_UINT64, isWideUnsignedValue],\n [TYPE_FLOAT, isNumberValue],\n [TYPE_DOUBLE, isNumberValue],\n [TYPE_POINTER, isNullValue],\n]);\n\nconst layout = { wasChecked: false };\nconst paramValueValidate = bind(LIB, \"g_param_value_validate\", [PARAM_T, VALUE_T], booleanT);\nconst paramSpecUnref = bind(LIB, \"g_param_spec_unref\", [PARAM_T], voidT);\nconst paramSpecRefSink = bind(LIB, \"g_param_spec_ref_sink\", [PARAM_T], PARAM_T);\n\nconst newParamSpecBoolean = bind(\n LIB,\n \"g_param_spec_boolean\",\n [stringT(\"borrowed\"), stringT(\"borrowed\"), stringT(\"borrowed\"), booleanT, uint32T],\n PARAM_T,\n);\n\nconst getParamFlags = (pspec: ExternalObject<Handle>): number => read(pspec, uint32T, FLAGS_BYTE_OFFSET) as number;\n\nconst getParamValueType = (pspec: ExternalObject<Handle>): bigint =>\n read(pspec, biguint64T, VALUE_TYPE_BYTE_OFFSET) as bigint;\n\nconst isParamWritable = (flags: number): boolean => (flags & PARAM_WRITABLE) !== 0;\nconst isParamConstructOnly = (flags: number): boolean => (flags & PARAM_CONSTRUCT_ONLY) !== 0;\nconst isParamLaxlyValidated = (flags: number): boolean => (flags & PARAM_LAX_VALIDATION) !== 0;\n\nconst wasParamValueModified = (pspec: ExternalObject<Handle>, value: ExternalObject<Handle>): boolean =>\n paramValueValidate(pspec, value) as boolean;\n\nfunction isBooleanValue(value: unknown): boolean {\n return typeof value === \"boolean\";\n}\n\nfunction isStringValue(value: unknown): boolean {\n return value == null || typeof value === \"string\";\n}\n\nfunction isStrvValue(value: unknown): boolean {\n return value == null || (Array.isArray(value) && value.every((item) => typeof item === \"string\"));\n}\n\nfunction isNumberValue(value: unknown): boolean {\n return typeof value === \"number\";\n}\n\nfunction isAnyValue(): boolean {\n return true;\n}\n\nfunction isNullValue(value: unknown): boolean {\n return value == null;\n}\n\nfunction integerGuardFor(minimum: number, maximum: number): ValueGuard {\n return (value) => Number.isSafeInteger(value) && (value as number) >= minimum && (value as number) <= maximum;\n}\n\nfunction toWideInteger(value: unknown): bigint | undefined {\n if (typeof value === \"bigint\") {\n return value;\n }\n\n return Number.isSafeInteger(value) ? BigInt(value as number) : undefined;\n}\n\nfunction wideIntegerGuardFor(minimum: bigint, maximum: bigint): ValueGuard {\n return (value) => {\n const wide = toWideInteger(value);\n\n return wide !== undefined && wide >= minimum && wide <= maximum;\n };\n}\n\nfunction resolveGtype(value: unknown): bigint {\n const instanceType = getInstanceType(value as object);\n\n if (instanceType !== TYPE_INVALID) {\n return instanceType;\n }\n\n return isTypedClass(value) ? value.__type__ : TYPE_INVALID;\n}\n\nfunction wrappedGuardFor(valueType: bigint): ValueGuard {\n return (value) => value == null || typeIsA(resolveGtype(value), valueType);\n}\n\nfunction exactGuardFor(valueType: bigint): ValueGuard | undefined {\n if (valueType === TYPE_GTYPE) {\n return isWideUnsignedValue;\n }\n\n return valueType === getStrvType() ? isStrvValue : undefined;\n}\n\nfunction valueGuardFor(valueType: bigint): ValueGuard {\n assertParamLayout();\n const exact = exactGuardFor(valueType);\n\n if (exact !== undefined) {\n return exact;\n }\n\n const fundamental = typeFundamental(valueType);\n\n if (WRAPPED_FUNDAMENTALS.has(fundamental)) {\n return wrappedGuardFor(valueType);\n }\n\n return SCALAR_GUARDS.get(fundamental) ?? isAnyValue;\n}\n\nfunction readProbeLayout(flags: number): ParamLayout {\n const probe = newParamSpecBoolean(LAYOUT_PROBE_NAME, null, null, false, flags) as ExternalObject<Handle>;\n paramSpecRefSink(probe);\n\n try {\n return { flags: getParamFlags(probe), valueType: getParamValueType(probe) };\n } finally {\n paramSpecUnref(probe);\n }\n}\n\nfunction isLayoutIntact(flags: number): boolean {\n const layout = readProbeLayout(flags);\n\n return (layout.flags & READ_FLAGS) === flags && layout.valueType === TYPE_BOOLEAN;\n}\n\nfunction assertParamLayout(): void {\n if (layout.wasChecked) {\n return;\n }\n\n layout.wasChecked = true;\n const readWrite = PARAM_READABLE | PARAM_WRITABLE;\n\n if (isLayoutIntact(readWrite) && isLayoutIntact(readWrite | PARAM_CONSTRUCT_ONLY | PARAM_LAX_VALIDATION)) {\n return;\n }\n\n throw new Error(\n \"GParamSpec does not match the memory layout this build reads a property's flags and value type at\",\n );\n}\n\nexport {\n getParamFlags,\n getParamValueType,\n isParamConstructOnly,\n isParamLaxlyValidated,\n isParamWritable,\n type ValueGuard,\n valueGuardFor,\n wasParamValueModified,\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"promisify.d.ts","sourceRoot":"","sources":["../src/promisify.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;AAgC1D;;;;;;;;;;GAUG;AACH,QAAA,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,EAClC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EACrC,QAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,aAAa,MAAM,GAAG,IAAI,GAAG,SAAS,EACtC,GAAG,SAAS,OAAO,EAAE,KACtB,OAAO,CAAC,CAAC,CAQN,CAAC;AAEP,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"promisify.d.ts","sourceRoot":"","sources":["../src/promisify.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;AAgC1D;;;;;;;;;;GAUG;AACH,QAAA,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,EAClC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EACrC,QAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,aAAa,MAAM,GAAG,IAAI,GAAG,SAAS,EACtC,GAAG,SAAS,OAAO,EAAE,KACtB,OAAO,CAAC,CAAC,CAUN,CAAC;AAEP,OAAO,EAAE,SAAS,EAAE,CAAC"}
package/dist/promisify.js CHANGED
@@ -1,4 +1,4 @@
1
- import { tryGetHandle } from "./registry.js";
1
+ import { getHandle } from "./registry.js";
2
2
  const attachCreationStack = (error, creationStack) => {
3
3
  if (creationStack === undefined || !(error instanceof Error)) {
4
4
  return;
@@ -31,7 +31,8 @@ const settle = (settlement, asyncResult) => {
31
31
  */
32
32
  const promisify = (asyncFn, finish, cancellable, ...leading) => new Promise((resolve, reject) => {
33
33
  const creationStack = process.env.NODE_ENV === "production" ? undefined : new Error("GTKX async operation started here");
34
- asyncFn(...leading, tryGetHandle(cancellable), (_source, asyncResult) => {
34
+ const cancellableHandle = cancellable == null ? null : getHandle(cancellable);
35
+ asyncFn(...leading, cancellableHandle, (_source, asyncResult) => {
35
36
  settle({ finish, creationStack, resolve, reject }, asyncResult);
36
37
  });
37
38
  });
@@ -1 +1 @@
1
- {"version":3,"file":"promisify.js","sourceRoot":"","sources":["../src/promisify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAe7C,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAAE,aAAgC,EAAQ,EAAE;IACnF,IAAI,aAAa,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO;IACX,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO;IACX,CAAC;IAED,KAAK,CAAC,KAAK,GAAG,aAAa,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAsB,UAA4B,EAAE,WAAmB,EAAQ,EAAE;IAC5F,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IAE9D,IAAI,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,WAAgB,CAAC,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,mBAAmB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QAC1C,MAAM,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtE,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,SAAS,GAAG,CACd,OAAqC,EACrC,MAA0B,EAC1B,WAAsC,EACtC,GAAG,OAAkB,EACX,EAAE,CACZ,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC/B,MAAM,aAAa,GACf,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAEvG,OAAO,CAAC,GAAG,OAAO,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC,OAAsB,EAAE,WAAmB,EAAE,EAAE;QAC3F,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEP,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { tryGetHandle } from \"./registry.js\";\n\n/**\n * Extracts the value of a completed asynchronous operation from its `GAsyncResult`, throwing when\n * the operation failed.\n */\ntype FinishResult<R extends object, T> = (result: R) => T;\n\ntype Settlement<R extends object, T> = {\n finish: FinishResult<R, T>;\n creationStack: Error | undefined;\n resolve: (value: T) => void;\n reject: (reason: Error) => void;\n};\n\nconst attachCreationStack = (error: unknown, creationStack: Error | undefined): void => {\n if (creationStack === undefined || !(error instanceof Error)) {\n return;\n }\n\n if (error.cause !== undefined || !Object.isExtensible(error)) {\n return;\n }\n\n error.cause = creationStack;\n};\n\nconst settle = <R extends object, T>(settlement: Settlement<R, T>, asyncResult: object): void => {\n const { finish, creationStack, resolve, reject } = settlement;\n\n try {\n resolve(finish(asyncResult as R));\n } catch (error) {\n attachCreationStack(error, creationStack);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n};\n\n/**\n * Wraps a GIO-style asynchronous function that takes a completion callback into a\n * promise, invoking the finish function to extract the result. Outside production,\n * the call site's stack is captured and attached as the rejection error's cause.\n *\n * @param asyncFn The async function, called with the leading arguments, the cancellable, and a completion callback.\n * @param finish Extracts the result from the async result passed to the completion callback.\n * @param cancellable A cancellable object, or null/undefined for none.\n * @param leading Arguments passed to `asyncFn` before the cancellable and callback.\n * @returns A promise resolving to the finished result, or rejecting if `finish` throws.\n */\nconst promisify = <R extends object, T>(\n asyncFn: (...args: unknown[]) => void,\n finish: FinishResult<R, T>,\n cancellable: object | null | undefined,\n ...leading: unknown[]\n): Promise<T> =>\n new Promise<T>((resolve, reject) => {\n const creationStack =\n process.env.NODE_ENV === \"production\" ? undefined : new Error(\"GTKX async operation started here\");\n\n asyncFn(...leading, tryGetHandle(cancellable), (_source: object | null, asyncResult: object) => {\n settle({ finish, creationStack, resolve, reject }, asyncResult);\n });\n });\n\nexport { promisify };\n"]}
1
+ {"version":3,"file":"promisify.js","sourceRoot":"","sources":["../src/promisify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAe1C,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAAE,aAAgC,EAAQ,EAAE;IACnF,IAAI,aAAa,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO;IACX,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO;IACX,CAAC;IAED,KAAK,CAAC,KAAK,GAAG,aAAa,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAsB,UAA4B,EAAE,WAAmB,EAAQ,EAAE;IAC5F,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IAE9D,IAAI,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,WAAgB,CAAC,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,mBAAmB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QAC1C,MAAM,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtE,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,SAAS,GAAG,CACd,OAAqC,EACrC,MAA0B,EAC1B,WAAsC,EACtC,GAAG,OAAkB,EACX,EAAE,CACZ,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC/B,MAAM,aAAa,GACf,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAEvG,MAAM,iBAAiB,GAAG,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE9E,OAAO,CAAC,GAAG,OAAO,EAAE,iBAAiB,EAAE,CAAC,OAAsB,EAAE,WAAmB,EAAE,EAAE;QACnF,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEP,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { getHandle } from \"./registry.js\";\n\n/**\n * Extracts the value of a completed asynchronous operation from its `GAsyncResult`, throwing when\n * the operation failed.\n */\ntype FinishResult<R extends object, T> = (result: R) => T;\n\ntype Settlement<R extends object, T> = {\n finish: FinishResult<R, T>;\n creationStack: Error | undefined;\n resolve: (value: T) => void;\n reject: (reason: Error) => void;\n};\n\nconst attachCreationStack = (error: unknown, creationStack: Error | undefined): void => {\n if (creationStack === undefined || !(error instanceof Error)) {\n return;\n }\n\n if (error.cause !== undefined || !Object.isExtensible(error)) {\n return;\n }\n\n error.cause = creationStack;\n};\n\nconst settle = <R extends object, T>(settlement: Settlement<R, T>, asyncResult: object): void => {\n const { finish, creationStack, resolve, reject } = settlement;\n\n try {\n resolve(finish(asyncResult as R));\n } catch (error) {\n attachCreationStack(error, creationStack);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n};\n\n/**\n * Wraps a GIO-style asynchronous function that takes a completion callback into a\n * promise, invoking the finish function to extract the result. Outside production,\n * the call site's stack is captured and attached as the rejection error's cause.\n *\n * @param asyncFn The async function, called with the leading arguments, the cancellable, and a completion callback.\n * @param finish Extracts the result from the async result passed to the completion callback.\n * @param cancellable A cancellable object, or null/undefined for none.\n * @param leading Arguments passed to `asyncFn` before the cancellable and callback.\n * @returns A promise resolving to the finished result, or rejecting if `finish` throws.\n */\nconst promisify = <R extends object, T>(\n asyncFn: (...args: unknown[]) => void,\n finish: FinishResult<R, T>,\n cancellable: object | null | undefined,\n ...leading: unknown[]\n): Promise<T> =>\n new Promise<T>((resolve, reject) => {\n const creationStack =\n process.env.NODE_ENV === \"production\" ? undefined : new Error(\"GTKX async operation started here\");\n\n const cancellableHandle = cancellable == null ? null : getHandle(cancellable);\n\n asyncFn(...leading, cancellableHandle, (_source: object | null, asyncResult: object) => {\n settle({ finish, creationStack, resolve, reject }, asyncResult);\n });\n });\n\nexport { promisify };\n"]}
@@ -1,15 +1,47 @@
1
- import type { RegisterClassProperty } from "@gtkx/native";
1
+ import type { ExternalObject, Handle, RegisterClassProperty } from "@gtkx/native";
2
2
  import type { AnyClass } from "@gtkx/utils";
3
- type PropertyAccessor = {
3
+ import { type ValueGuard } from "./param-spec.js";
4
+ import { type InterfaceProperty } from "./registry.js";
5
+ import { type ValueNarrower, type ValueWriter } from "./value.js";
6
+ type PropertyCheck = {
4
7
  name: string;
8
+ propertyName: string;
9
+ handle: ExternalObject<Handle>;
10
+ flags: number;
11
+ valueType: bigint;
12
+ canHoldValue: ValueGuard;
13
+ narrowValue: ValueNarrower;
14
+ write?: ValueWriter;
15
+ scratch?: ExternalObject<Handle>;
16
+ };
17
+ type PropertyAccessor = PropertyCheck & {
18
+ memberName: string;
5
19
  storage: symbol;
6
- pspec: object;
20
+ hasGeneratedMember: boolean;
21
+ isInterfaceProperty?: boolean;
22
+ delegate?: InterfaceProperty;
7
23
  };
8
24
  /** A `GObject.ParamSpec` wrapper describing one property's name, type, flags and default. */
9
25
  type PropertySpec = object;
10
- declare function makeGetProperty(accessors: PropertyAccessor[]): (this: object, propertyId: number, value: object) => void;
11
- declare function makeSetProperty(accessors: PropertyAccessor[]): (this: object, propertyId: number, value: object) => void;
12
- declare function buildAccessors(klass: AnyClass, properties: Record<string, PropertySpec>): PropertyAccessor[];
26
+ type PropertyDispatch = {
27
+ accessors: PropertyAccessor[];
28
+ delegates: Map<string, InterfaceProperty>;
29
+ };
30
+ type PropertyDispatchSource = {
31
+ klass: AnyClass;
32
+ properties: Record<string, PropertySpec>;
33
+ adoptedTypes: bigint[];
34
+ };
35
+ type ConstructProperty = {
36
+ name: string;
37
+ value: ExternalObject<Handle>;
38
+ };
39
+ declare const GET_PROPERTY_VFUNC = "vfuncGetProperty";
40
+ declare const SET_PROPERTY_VFUNC = "vfuncSetProperty";
41
+ declare function constructPropertyFor(gtype: bigint, name: string, value: unknown, wrapper: object): ConstructProperty | undefined;
42
+ declare function makeGetProperty(dispatch: PropertyDispatch): (this: object, propertyId: number, value: object, pspec: PropertySpec) => void;
43
+ declare function makeSetProperty(dispatch: PropertyDispatch): (this: object, propertyId: number, value: object, pspec: PropertySpec) => void;
44
+ declare function buildPropertyDispatch(source: PropertyDispatchSource): PropertyDispatch;
13
45
  declare function toNativeProperties(properties: Record<string, PropertySpec>): RegisterClassProperty[];
14
- export { buildAccessors, makeGetProperty, makeSetProperty, toNativeProperties, type PropertyAccessor, type PropertySpec, };
46
+ export { buildPropertyDispatch, constructPropertyFor, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, SET_PROPERTY_VFUNC, toNativeProperties, type ConstructProperty, type PropertyDispatch, type PropertySpec, };
15
47
  //# sourceMappingURL=properties.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../src/properties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0B,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAO5C,KAAK,gBAAgB,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,6FAA6F;AAC7F,KAAK,YAAY,GAAG,MAAM,CAAC;AA0D3B,iBAAS,eAAe,CAAC,SAAS,EAAE,gBAAgB,EAAE,IACtB,MAAM,MAAM,EAAE,YAAY,MAAM,EAAE,OAAO,MAAM,KAAG,IAAI,CAKrF;AAED,iBAAS,eAAe,CAAC,SAAS,EAAE,gBAAgB,EAAE,IACtB,MAAM,MAAM,EAAE,YAAY,MAAM,EAAE,OAAO,MAAM,KAAG,IAAI,CAKrF;AAED,iBAAS,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,gBAAgB,EAAE,CAUrG;AAED,iBAAS,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,qBAAqB,EAAE,CAK7F;AAED,OAAO,EACH,cAAc,EACd,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,YAAY,GACpB,CAAC"}
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,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK5C,OAAO,E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