@gtkx/runtime 1.6.0 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/application-class.d.ts +1 -1
- package/dist/application-class.d.ts.map +1 -1
- package/dist/application-class.js +1 -2
- package/dist/application-class.js.map +1 -1
- package/dist/arg.d.ts +4 -1
- package/dist/arg.d.ts.map +1 -1
- package/dist/arg.js.map +1 -1
- package/dist/bind.d.ts.map +1 -1
- package/dist/bind.js +1 -9
- package/dist/bind.js.map +1 -1
- package/dist/callback.d.ts +6 -1
- package/dist/callback.d.ts.map +1 -1
- package/dist/callback.js +33 -21
- package/dist/callback.js.map +1 -1
- package/dist/closure.d.ts +3 -1
- package/dist/closure.d.ts.map +1 -1
- package/dist/closure.js +17 -6
- package/dist/closure.js.map +1 -1
- package/dist/descriptors.d.ts +22 -51
- package/dist/descriptors.d.ts.map +1 -1
- package/dist/descriptors.js +53 -27
- package/dist/descriptors.js.map +1 -1
- package/dist/fn.d.ts.map +1 -1
- package/dist/fn.js +23 -9
- package/dist/fn.js.map +1 -1
- package/dist/folded-lengths.d.ts +2 -1
- package/dist/folded-lengths.d.ts.map +1 -1
- package/dist/folded-lengths.js +17 -7
- package/dist/folded-lengths.js.map +1 -1
- package/dist/index.d.ts +2 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -24
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +2 -2
- package/dist/internal.js.map +1 -1
- package/dist/native-value.d.ts +9 -1
- package/dist/native-value.d.ts.map +1 -1
- package/dist/native-value.js +20 -3
- package/dist/native-value.js.map +1 -1
- package/dist/properties.d.ts +1 -1
- package/dist/properties.d.ts.map +1 -1
- package/dist/properties.js +2 -11
- package/dist/properties.js.map +1 -1
- package/dist/register-class.d.ts +45 -249
- package/dist/register-class.d.ts.map +1 -1
- package/dist/register-class.js.map +1 -1
- package/dist/signal.d.ts.map +1 -1
- package/dist/signal.js +9 -22
- package/dist/signal.js.map +1 -1
- package/dist/t.d.ts +5 -21
- package/dist/t.d.ts.map +1 -1
- package/dist/t.js +1 -5
- package/dist/t.js.map +1 -1
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js +7 -1
- package/dist/type.js.map +1 -1
- package/dist/value.d.ts.map +1 -1
- package/dist/value.js +7 -1
- package/dist/value.js.map +1 -1
- package/dist/variant.d.ts +2 -6
- package/dist/variant.d.ts.map +1 -1
- package/dist/variant.js.map +1 -1
- package/dist/vfunc-call.d.ts.map +1 -1
- package/dist/vfunc-call.js +2 -11
- package/dist/vfunc-call.js.map +1 -1
- package/package.json +9 -5
- package/src/application-class.ts +2 -2
- package/src/arg.ts +4 -1
- package/src/bind.ts +1 -12
- package/src/callback.ts +53 -29
- package/src/closure.ts +31 -6
- package/src/descriptors.ts +95 -59
- package/src/fn.ts +31 -10
- package/src/folded-lengths.ts +23 -10
- package/src/index.ts +2 -24
- package/src/internal.ts +2 -2
- package/src/native-value.ts +24 -3
- package/src/properties.ts +3 -16
- package/src/register-class.ts +45 -249
- package/src/signal.ts +9 -34
- package/src/t.ts +5 -21
- package/src/type.ts +9 -1
- package/src/value.ts +9 -1
- package/src/variant.ts +2 -6
- package/src/vfunc-call.ts +3 -16
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<p align="center">
|
|
14
14
|
<a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/v/create-gtkx?color=cb3837&logo=npm&label=create-gtkx" alt="npm version" /></a>
|
|
15
15
|
<a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/dm/create-gtkx?color=cb3837&logo=npm&label=downloads" alt="npm downloads" /></a>
|
|
16
|
-
<img src="https://img.shields.io/badge/node-%E2%89%
|
|
16
|
+
<img src="https://img.shields.io/badge/node-%E2%89%A526.7-339933?logo=node.js&logoColor=white" alt="Node >= 26.7" />
|
|
17
17
|
<a href="https://github.com/gtkx-org/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License: MPL-2.0" /></a>
|
|
18
18
|
<a href="https://github.com/gtkx-org/gtkx/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/gtkx-org/gtkx/ci.yml?branch=main&logo=github&label=CI" alt="CI status" /></a>
|
|
19
19
|
<img src="https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white" alt="TypeScript" />
|
|
@@ -116,7 +116,7 @@ At runtime, the native Rust core calls straight into the system GTK4, Adwaita, a
|
|
|
116
116
|
|
|
117
117
|
## Quick start
|
|
118
118
|
|
|
119
|
-
GTKX is Linux-only and needs Node.js
|
|
119
|
+
GTKX is Linux-only and needs Node.js 26.7 or later. See [Requirements](#requirements).
|
|
120
120
|
|
|
121
121
|
Scaffold a new app with the `create-gtkx` initializer:
|
|
122
122
|
|
|
@@ -145,8 +145,8 @@ The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tu
|
|
|
145
145
|
|
|
146
146
|
GTKX is Linux-only. You need:
|
|
147
147
|
|
|
148
|
-
- Linux with the GTK4 (4.20 or later)
|
|
149
|
-
- Node.js
|
|
148
|
+
- Linux with the GTK4 (4.20 or later), Adwaita (1.8 or later), and GLib development libraries
|
|
149
|
+
- Node.js 26.7 or later
|
|
150
150
|
|
|
151
151
|
The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other targets need to build it from the GTKX repository, which requires a Rust toolchain.
|
|
152
152
|
|
|
@@ -167,7 +167,7 @@ GTKX is stable and ready for production use.
|
|
|
167
167
|
|
|
168
168
|
## Contributing
|
|
169
169
|
|
|
170
|
-
Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js
|
|
170
|
+
Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js 26.7 or later, pnpm, and a Rust toolchain.
|
|
171
171
|
|
|
172
172
|
## License
|
|
173
173
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-class.d.ts","sourceRoot":"","sources":["../src/application-class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"application-class.d.ts","sourceRoot":"","sources":["../src/application-class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAO5C,KAAK,iBAAiB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC;AAErD;;;GAGG;AACH,KAAK,sBAAsB,GAAG;IAC1B,kGAAkG;IAClG,IAAI,IAAI,IAAI,CAAC;CAChB,CAAC;AAEF,KAAK,2BAA2B,GAAG;IAC/B,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC;CAC1D,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACvB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;CAC/B,CAAC;AAEF,8EAA8E;AAC9E,KAAK,gBAAgB,CAAC,CAAC,SAAS,sBAAsB,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AA2CjG,QAAA,MAAM,oBAAoB,GAAI,aAAa,MAAM,KAAG,WAAW,IAAI,2BAQlE,CAAC;AAEF,QAAA,MAAM,kBAAkB,GAAI,aAAa,mBAAmB,KAAG,IAY9D,CAAC;AAKF;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,iBAAiB,GAAI,CAAC,SAAS,sBAAsB,EAAE,CAAC,EAAE,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,KAAG,CAKxG,CAAC;AAEF,OAAO,EACH,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,GACnC,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getOrInsert } from "@gtkx/utils";
|
|
2
1
|
import { releaseDefaultApplication } from "./default-application.js";
|
|
3
2
|
import { registerClass } from "./register-class.js";
|
|
4
3
|
import { getClassType } from "./registry.js";
|
|
@@ -54,7 +53,7 @@ const shutDownThroughRun = (application) => {
|
|
|
54
53
|
shuttingDownApplications.delete(application);
|
|
55
54
|
}
|
|
56
55
|
};
|
|
57
|
-
const deriveApplicationClass = (base) =>
|
|
56
|
+
const deriveApplicationClass = (base) => derivedClasses.getOrInsertComputed(base, () => buildApplicationClass(base));
|
|
58
57
|
/**
|
|
59
58
|
* Constructs an application GTKX can shut down. GLib parses an application's command line at most
|
|
60
59
|
* once per instance and crashes on a second parse, so {@link runApplication} and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-class.js","sourceRoot":"","sources":["../src/application-class.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"application-class.js","sourceRoot":"","sources":["../src/application-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AA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"./default-application.js\";\nimport { registerClass } from \"./register-class.js\";\nimport { getClassType } from \"./registry.js\";\nimport { typeName } from \"./type.js\";\nimport { callParent } from \"./vfunc-call.js\";\n\ntype CommandLineResult = [boolean, string[], number];\n\n/**\n * The GIO application surface {@link createApplication} builds on, which `Gio.Application` and\n * every subclass of it satisfies structurally.\n */\ntype CommandLineApplication = {\n /** Marks the application as quitting, so GLib's own `run` returns without driving a main loop. */\n quit(): void;\n};\n\ntype LocalCommandLineApplication = {\n runLocalCommandLine(argv: string[]): CommandLineResult;\n};\n\ntype ShutdownApplication = {\n run(argv: string[]): number;\n};\n\n/** An application class together with the construct properties it accepts. */\ntype ApplicationClass<T extends CommandLineApplication, P> = AnyClass<T> & (new (props: P) => T);\n\nconst derivedClasses: WeakMap<AnyClass, AnyClass> = new WeakMap();\nconst derivedApplicationClasses: Set<AnyClass> = new Set();\nconst quitApplications: WeakSet<object> = new WeakSet();\nconst shuttingDownApplications: WeakSet<object> = new WeakSet();\n\nconst derivedTypeName = (base: AnyClass): string => `Gtkx${typeName(getClassType(base)) ?? base.name}`;\n\nconst buildApplicationClass = (base: AnyClass<CommandLineApplication>): AnyClass<CommandLineApplication> => {\n class DerivedApplication extends base {\n runLocalCommandLine(argv: string[]): CommandLineResult {\n return this.vfuncLocalCommandLine(argv);\n }\n\n protected vfuncLocalCommandLine(argv: string[]): CommandLineResult {\n if (shuttingDownApplications.has(this)) {\n this.quit();\n\n return [true, argv, 0];\n }\n\n return callParent(DerivedApplication, \"vfuncLocalCommandLine\", this, argv) as CommandLineResult;\n }\n\n protected vfuncNameLost(): boolean {\n quitApplications.add(this);\n\n return callParent(DerivedApplication, \"vfuncNameLost\", this) as boolean;\n }\n\n override quit(): void {\n quitApplications.add(this);\n super.quit();\n }\n }\n\n const derived = registerClass(DerivedApplication, { typeName: derivedTypeName(base) });\n derivedApplicationClasses.add(derived);\n\n return derived;\n};\n\nconst isDerivedApplication = (application: object): application is LocalCommandLineApplication => {\n for (const derived of derivedApplicationClasses) {\n if (application instanceof derived) {\n return true;\n }\n }\n\n return false;\n};\n\nconst shutDownThroughRun = (application: ShutdownApplication): void => {\n if (!isDerivedApplication(application) || quitApplications.has(application)) {\n return;\n }\n\n shuttingDownApplications.add(application);\n\n try {\n application.run([]);\n } finally {\n shuttingDownApplications.delete(application);\n }\n};\n\nconst deriveApplicationClass = <T extends CommandLineApplication>(base: AnyClass<T>): AnyClass<T> =>\n derivedClasses.getOrInsertComputed(base, () => buildApplicationClass(base)) as AnyClass<T>;\n\n/**\n * Constructs an application GTKX can shut down. GLib parses an application's command line at most\n * once per instance and crashes on a second parse, so {@link runApplication} and\n * {@link quitApplication} only accept an application built here.\n *\n * Whatever `g_application_constructed` assigned to the process-wide default is handed straight back,\n * so merely building an application never makes it what `Gio.Application.getDefault()` returns.\n * {@link runApplication} is the only place that claims that default, which keeps it pointing at an\n * application GTKX has actually started rather than at one that is still unregistered.\n *\n * @param base The application class to construct, such as `Gtk.Application`.\n * @param props Construct properties, passed through unchanged.\n * @returns An instance of a class derived from `base`, registered once per base class as its own GType.\n */\nconst createApplication = <T extends CommandLineApplication, P>(base: ApplicationClass<T, P>, props: P): T => {\n const application = new (deriveApplicationClass(base) as new (props: P) => T)(props);\n releaseDefaultApplication(application);\n\n return application;\n};\n\nexport {\n createApplication,\n isDerivedApplication,\n shutDownThroughRun,\n type ApplicationClass,\n type CommandLineApplication,\n type LocalCommandLineApplication,\n};\n"]}
|
package/dist/arg.d.ts
CHANGED
|
@@ -11,7 +11,10 @@ type Arg = {
|
|
|
11
11
|
isConsumed?: boolean;
|
|
12
12
|
/** When true, the argument is a `GValue` the callee fills in, packed into the result as what it holds. */
|
|
13
13
|
isUnpacked?: boolean;
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* When true, the caller must provide the argument: `undefined` is rejected instead of reaching
|
|
16
|
+
* C as `NULL`, and so is `null` for a type that reaches C as a pointer.
|
|
17
|
+
*/
|
|
15
18
|
isRequired?: boolean;
|
|
16
19
|
};
|
|
17
20
|
declare const isOutputArg: (arg: Arg) => boolean;
|
package/dist/arg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arg.d.ts","sourceRoot":"","sources":["../src/arg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,iGAAiG;AACjG,KAAK,GAAG,GAAG;IACP,kGAAkG;IAClG,IAAI,EAAE,UAAU,CAAC;IACjB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;IAC5B,wGAAwG;IACxG,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,wFAAwF;IACxF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0GAA0G;IAC1G,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB
|
|
1
|
+
{"version":3,"file":"arg.d.ts","sourceRoot":"","sources":["../src/arg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,iGAAiG;AACjG,KAAK,GAAG,GAAG;IACP,kGAAkG;IAClG,IAAI,EAAE,UAAU,CAAC;IACjB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;IAC5B,wGAAwG;IACxG,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,wFAAwF;IACxF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0GAA0G;IAC1G,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,WAAW,GAAI,KAAK,GAAG,KAAG,OAAsC,CAAC;AACvE,QAAA,MAAM,UAAU,GAAI,KAAK,GAAG,KAAG,OAAoC,CAAC;AACpE,QAAA,MAAM,oBAAoB,GAAI,KAAK,GAAG,KAAG,OAAyC,CAAC;AACnF,QAAA,MAAM,aAAa,GAAI,KAAK,GAAG,KAAG,OAAkC,CAAC;AACrE,QAAA,MAAM,QAAQ,GAAI,KAAK,GAAG,KAAG,OAAwE,CAAC;AACtG,QAAA,MAAM,gBAAgB,GAAI,KAAK,GAAG,KAAG,OAA4C,CAAC;AAElF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,oBAAoB,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,GAAG,EAAE,CAAC"}
|
package/dist/arg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arg.js","sourceRoot":"","sources":["../src/arg.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"arg.js","sourceRoot":"","sources":["../src/arg.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC;AACvE,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,OAAO,CAAC;AACpE,MAAM,oBAAoB,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,iBAAiB,KAAK,IAAI,CAAC;AACnF,MAAM,aAAa,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,UAAU,KAAK,IAAI,CAAC;AACrE,MAAM,QAAQ,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,GAAG,CAAC,iBAAiB,KAAK,IAAI,CAAC;AACtG,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;AAElF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,oBAAoB,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAY,CAAC","sourcesContent":["import type { Descriptor } from \"@gtkx/native\";\n\n/** How one argument of a native call or signal emission is marshalled and which way it flows. */\ntype Arg = {\n /** Descriptor the value is marshalled with, wrapped in a pointer to it for an output argument. */\n type: Descriptor;\n /** Direction of an output argument, omitted for a plain input argument. */\n direction?: \"out\" | \"inout\";\n /** When true, the caller supplies the storage the callee writes into, rather than a pointer to fill. */\n isCallerAllocated?: boolean;\n /** When true, the argument is consumed internally and left out of the packed result. */\n isConsumed?: boolean;\n /** When true, the argument is a `GValue` the callee fills in, packed into the result as what it holds. */\n isUnpacked?: boolean;\n /**\n * When true, the caller must provide the argument: `undefined` is rejected instead of reaching\n * C as `NULL`, and so is `null` for a type that reaches C as a pointer.\n */\n isRequired?: boolean;\n};\n\nconst isOutputArg = (arg: Arg): boolean => arg.direction !== undefined;\nconst isInoutArg = (arg: Arg): boolean => arg.direction === \"inout\";\nconst isCallerAllocatedArg = (arg: Arg): boolean => arg.isCallerAllocated === true;\nconst isUnpackedArg = (arg: Arg): boolean => arg.isUnpacked === true;\nconst isRefArg = (arg: Arg): boolean => arg.direction !== undefined && arg.isCallerAllocated !== true;\nconst requiresInputArg = (arg: Arg): boolean => !isRefArg(arg) || isInoutArg(arg);\n\nexport { isOutputArg, isInoutArg, isCallerAllocatedArg, isRefArg, isUnpackedArg, requiresInputArg, type Arg };\n"]}
|
package/dist/bind.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAsB,MAAM,cAAc,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,iBAAS,IAAI,CACT,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,UAAU,EAAE,EAC5B,gBAAgB,EAAE,UAAU,GAC7B,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAInC;AAED,iBAAS,eAAe,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,UAAU,CAAC,OAAO,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAsB,MAAM,cAAc,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,iBAAS,IAAI,CACT,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,UAAU,EAAE,EAC5B,gBAAgB,EAAE,UAAU,GAC7B,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAInC;AAED,iBAAS,eAAe,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,UAAU,CAAC,OAAO,IAAI,CAAC,CAIrG;AAED,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/bind.js
CHANGED
|
@@ -16,15 +16,7 @@ function bind(sharedLibrary, symbol, argDescriptors, returnDescriptor) {
|
|
|
16
16
|
}
|
|
17
17
|
function createBindCache() {
|
|
18
18
|
const cache = new Map();
|
|
19
|
-
return (key, ...args) =>
|
|
20
|
-
const existing = cache.get(key);
|
|
21
|
-
if (existing !== undefined) {
|
|
22
|
-
return existing;
|
|
23
|
-
}
|
|
24
|
-
const bound = bind(...args);
|
|
25
|
-
cache.set(key, bound);
|
|
26
|
-
return bound;
|
|
27
|
-
};
|
|
19
|
+
return (key, ...args) => cache.getOrInsertComputed(key, () => bind(...args));
|
|
28
20
|
}
|
|
29
21
|
export { bind, createBindCache };
|
|
30
22
|
//# sourceMappingURL=bind.js.map
|
package/dist/bind.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.js","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,IAAI,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,SAAS,IAAI,CACT,aAAqB,EACrB,MAAc,EACd,cAA4B,EAC5B,gBAA4B;IAE5B,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;IAEvF,OAAO,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,eAAe;IACpB,MAAM,KAAK,GAAyC,IAAI,GAAG,EAAE,CAAC;IAE9D,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE
|
|
1
|
+
{"version":3,"file":"bind.js","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,IAAI,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,SAAS,IAAI,CACT,aAAqB,EACrB,MAAc,EACd,cAA4B,EAC5B,gBAA4B;IAE5B,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;IAEvF,OAAO,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,eAAe;IACpB,MAAM,KAAK,GAAyC,IAAI,GAAG,EAAE,CAAC;IAE9D,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { call, type Descriptor, bind as nativeBind } from \"@gtkx/native\";\n\n/**\n * Precompiles a call to a C function, marshalling the values it is given through the argument\n * descriptors and the result through the return one. The symbol is resolved in the shared library\n * on the first call.\n *\n * @param sharedLibrary The shared library to resolve the symbol in.\n * @param symbol The name of the C function to bind.\n * @param argDescriptors Describe the C arguments, in declaration order.\n * @param returnDescriptor Describes the C return value.\n * @returns A function calling the bound symbol.\n */\nfunction bind(\n sharedLibrary: string,\n symbol: string,\n argDescriptors: Descriptor[],\n returnDescriptor: Descriptor,\n): (...values: unknown[]) => unknown {\n const descriptor = nativeBind(sharedLibrary, symbol, argDescriptors, returnDescriptor);\n\n return (...values) => call(descriptor, values);\n}\n\nfunction createBindCache(): (key: string, ...args: Parameters<typeof bind>) => ReturnType<typeof bind> {\n const cache: Map<string, ReturnType<typeof bind>> = new Map();\n\n return (key, ...args) => cache.getOrInsertComputed(key, () => bind(...args));\n}\n\nexport { bind, createBindCache };\n"]}
|
package/dist/callback.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ type CallbackSpec = {
|
|
|
9
9
|
};
|
|
10
10
|
declare const isCallerAllocatedOut: (descriptor: Descriptor) => boolean;
|
|
11
11
|
declare const wrapCallbackValue: (spec: CallbackDescriptor, callback: unknown) => unknown;
|
|
12
|
+
/** Thrown when a value passed where a callback, signal handler or vfunc is expected cannot be called. */
|
|
13
|
+
declare class CallbackMarshalError extends TypeError {
|
|
14
|
+
/** Name callers match on when the error is caught as a plain `TypeError`. */
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
12
17
|
declare function wrapCallback(fn: Callback, spec: CallbackSpec, kind: CallbackKind): Callback;
|
|
13
|
-
export { isCallerAllocatedOut, wrapCallbackValue, wrapCallback };
|
|
18
|
+
export { CallbackMarshalError, isCallerAllocatedOut, wrapCallbackValue, wrapCallback };
|
|
14
19
|
//# sourceMappingURL=callback.d.ts.map
|
package/dist/callback.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../src/callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../src/callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,kBAAkB,CAAC;AAa1E,KAAK,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAChD,KAAK,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;AAcpD,KAAK,YAAY,GAAG;IAChB,cAAc,EAAE,UAAU,EAAE,CAAC;IAC7B,gBAAgB,EAAE,UAAU,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAqCF,QAAA,MAAM,oBAAoB,GAAI,YAAY,UAAU,KAAG,OACmD,CAAC;AAgN3G,QAAA,MAAM,iBAAiB,GAAI,MAAM,kBAAkB,EAAE,UAAU,OAAO,KAAG,OACa,CAAC;AAKvF,yGAAyG;AACzG,cAAM,oBAAqB,SAAQ,SAAS;IACxC,6EAA6E;IAC7D,IAAI,SAA0B;CACjD;AAED,iBAAS,YAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,QAAQ,CAuBpF;AAED,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/callback.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { copy } from "@gtkx/native";
|
|
2
|
-
import { foldedLengthSources } from "./folded-lengths.js";
|
|
2
|
+
import { foldedLengthArgIndices, foldedLengthSources, } from "./folded-lengths.js";
|
|
3
3
|
import { fromNative, toNative } from "./native-value.js";
|
|
4
|
-
import { getHandle } from "./registry.js";
|
|
4
|
+
import { describeValueKind, getHandle } from "./registry.js";
|
|
5
5
|
import { splitTupleResult } from "./tuple.js";
|
|
6
6
|
import { copyValue } from "./value.js";
|
|
7
7
|
import { popSeedFrame, pushSeedFrame } from "./vfunc-seeds.js";
|
|
8
8
|
const CALLBACK_TRAITS = {
|
|
9
|
-
callback: { isInstanceBound: false, hasInstanceArg: false, hasFoldedLengths: true },
|
|
10
|
-
signal: { isInstanceBound: false, hasInstanceArg: true, hasFoldedLengths: false },
|
|
11
|
-
vfunc: { isInstanceBound: true, hasInstanceArg: true, hasFoldedLengths: true },
|
|
9
|
+
callback: { isInstanceBound: false, hasInstanceArg: false, hasFoldedLengths: true, hasFoldedInputs: true },
|
|
10
|
+
signal: { isInstanceBound: false, hasInstanceArg: true, hasFoldedLengths: false, hasFoldedInputs: false },
|
|
11
|
+
vfunc: { isInstanceBound: true, hasInstanceArg: true, hasFoldedLengths: true, hasFoldedInputs: false },
|
|
12
12
|
};
|
|
13
13
|
const fillCallerAllocatedBuffer = (descriptor, target, source) => {
|
|
14
14
|
if (descriptor.kind === "boxed" && descriptor.typeName === "GValue") {
|
|
@@ -23,7 +23,7 @@ const fillCallerAllocatedBuffer = (descriptor, target, source) => {
|
|
|
23
23
|
};
|
|
24
24
|
const isCallerAllocatedOut = (descriptor) => (descriptor.kind === "boxed" || descriptor.kind === "struct") && descriptor.isCallerAllocated === true;
|
|
25
25
|
const collectRefArg = (descriptor, wrappedValue, inputs, out) => {
|
|
26
|
-
if (descriptor.inout === true) {
|
|
26
|
+
if (descriptor.inout === true && !out.isFolded) {
|
|
27
27
|
inputs.push(wrappedValue.value);
|
|
28
28
|
}
|
|
29
29
|
out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });
|
|
@@ -33,18 +33,21 @@ const collectCallbackArg = (descriptor, wrappedValue, inputs, out) => {
|
|
|
33
33
|
collectRefArg(descriptor, wrappedValue, inputs, out);
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
if (!out.isFolded) {
|
|
37
|
+
inputs.push(wrappedValue);
|
|
38
|
+
}
|
|
37
39
|
if (descriptor !== undefined && isCallerAllocatedOut(descriptor)) {
|
|
38
40
|
out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });
|
|
39
41
|
}
|
|
40
42
|
};
|
|
41
|
-
const partitionCallbackArgs = (
|
|
43
|
+
const partitionCallbackArgs = (plan, wrapped) => {
|
|
42
44
|
const inputs = [];
|
|
43
45
|
const params = [];
|
|
44
|
-
const collected = { params, argIndex: start };
|
|
45
|
-
for (let i = start; i < effectiveTypes.length; i++) {
|
|
46
|
+
const collected = { params, argIndex: plan.start, isFolded: false };
|
|
47
|
+
for (let i = plan.start; i < plan.effectiveTypes.length; i++) {
|
|
46
48
|
collected.argIndex = i;
|
|
47
|
-
|
|
49
|
+
collected.isFolded = plan.foldedInputIndices.has(i);
|
|
50
|
+
collectCallbackArg(plan.effectiveTypes[i], wrapped[i], inputs, collected);
|
|
48
51
|
}
|
|
49
52
|
return { inputs, outParams: params };
|
|
50
53
|
};
|
|
@@ -124,14 +127,13 @@ const wrapCallbackArgs = (effectiveTypes, rawArgs) => {
|
|
|
124
127
|
}
|
|
125
128
|
};
|
|
126
129
|
const trimCallbackInputs = (plan, wrapped) => {
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
wrapped.shift();
|
|
130
|
+
const inputs = [];
|
|
131
|
+
for (let index = plan.start; index < plan.effectiveTypes.length; index++) {
|
|
132
|
+
if (!plan.foldedInputIndices.has(index)) {
|
|
133
|
+
inputs.push(wrapped[index]);
|
|
134
|
+
}
|
|
133
135
|
}
|
|
134
|
-
return
|
|
136
|
+
return inputs;
|
|
135
137
|
};
|
|
136
138
|
const nativeReturn = (plan, primary) => toNative(plan.returnDescriptor, plan.hasPrimary ? primary : undefined);
|
|
137
139
|
const runCallback = (plan, rawArgs) => {
|
|
@@ -141,7 +143,7 @@ const runCallback = (plan, rawArgs) => {
|
|
|
141
143
|
if (!plan.hasOutParams) {
|
|
142
144
|
return nativeReturn(plan, plan.fn.apply(thisArg, trimCallbackInputs(plan, rawArgs)));
|
|
143
145
|
}
|
|
144
|
-
const { inputs, outParams } = partitionCallbackArgs(
|
|
146
|
+
const { inputs, outParams } = partitionCallbackArgs(plan, rawArgs);
|
|
145
147
|
const result = applyCallback(plan, thisArg, inputs, outParams);
|
|
146
148
|
if (outParams.length === 0) {
|
|
147
149
|
return nativeReturn(plan, result);
|
|
@@ -160,9 +162,18 @@ const getEffectiveTypes = (spec) => {
|
|
|
160
162
|
return spec.argDescriptors.filter((_, i) => i !== userDataIndex);
|
|
161
163
|
};
|
|
162
164
|
const wrapCallbackValue = (spec, callback) => callback == null ? callback : wrapCallback(callback, spec, "callback");
|
|
165
|
+
const planFoldedInputIndices = (spec, hasFoldedInputs) => hasFoldedInputs ? foldedLengthArgIndices(spec) : new Set();
|
|
166
|
+
/** Thrown when a value passed where a callback, signal handler or vfunc is expected cannot be called. */
|
|
167
|
+
class CallbackMarshalError extends TypeError {
|
|
168
|
+
/** Name callers match on when the error is caught as a plain `TypeError`. */
|
|
169
|
+
name = "CallbackMarshalError";
|
|
170
|
+
}
|
|
163
171
|
function wrapCallback(fn, spec, kind) {
|
|
172
|
+
if (typeof fn !== "function") {
|
|
173
|
+
throw new CallbackMarshalError(`Cannot marshal ${describeValueKind(fn)} into a ${kind}`);
|
|
174
|
+
}
|
|
164
175
|
const effectiveTypes = getEffectiveTypes(spec);
|
|
165
|
-
const { isInstanceBound, hasInstanceArg, hasFoldedLengths } = CALLBACK_TRAITS[kind];
|
|
176
|
+
const { isInstanceBound, hasInstanceArg, hasFoldedLengths, hasFoldedInputs } = CALLBACK_TRAITS[kind];
|
|
166
177
|
const start = hasInstanceArg ? 1 : 0;
|
|
167
178
|
const plan = {
|
|
168
179
|
fn,
|
|
@@ -174,8 +185,9 @@ function wrapCallback(fn, spec, kind) {
|
|
|
174
185
|
lengthSources: planLengthSources(spec, hasFoldedLengths),
|
|
175
186
|
hasOutParams: haveOutParamArgs(effectiveTypes, start),
|
|
176
187
|
hasRefOutParams: haveRefOutParamArgs(effectiveTypes, start),
|
|
188
|
+
foldedInputIndices: planFoldedInputIndices(spec, hasFoldedInputs),
|
|
177
189
|
};
|
|
178
190
|
return (...rawArgs) => runCallback(plan, rawArgs);
|
|
179
191
|
}
|
|
180
|
-
export { isCallerAllocatedOut, wrapCallbackValue, wrapCallback };
|
|
192
|
+
export { CallbackMarshalError, isCallerAllocatedOut, wrapCallbackValue, wrapCallback };
|
|
181
193
|
//# sourceMappingURL=callback.js.map
|
package/dist/callback.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callback.js","sourceRoot":"","sources":["../src/callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAyC,MAAM,qBAAqB,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAiB,MAAM,kBAAkB,CAAC;AA4B9E,MAAM,eAAe,GAAyC;IAC1D,QAAQ,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE;IACnF,MAAM,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE;IACjF,KAAK,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EA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K;QACL,eAAe;QACf,aAAa,EAAE,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC;QACxD,YAAY,EAAE,gBAAgB,CAAC,cAAc,EAAE,KAAK,CAAC;QACrD,eAAe,EAAE,mBAAmB,CAAC,cAAc,EAAE,KAAK,CAAC;KAC9D,CAAC;IAEF,OAAO,CAAC,GAAG,OAAkB,EAAW,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1E,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { copy, type Descriptor } from \"@gtkx/native\";\nimport type { CallbackDescriptor, RefDescriptor } from \"./descriptors.js\";\nimport { foldedLengthSources, type LengthSource, type LengthSources } from \"./folded-lengths.js\";\nimport { fromNative, toNative } from \"./native-value.js\";\nimport { getHandle } from \"./registry.js\";\nimport { splitTupleResult } from \"./tuple.js\";\nimport { copyValue } from \"./value.js\";\nimport { popSeedFrame, pushSeedFrame, type RefSeeds } from \"./vfunc-seeds.js\";\n\ntype Callback = (...args: unknown[]) => unknown;\ntype CallbackKind = \"vfunc\" | \"signal\" | \"callback\";\ntype CallbackTraits = { isInstanceBound: boolean; hasInstanceArg: boolean; hasFoldedLengths: boolean };\ntype OutParam = { value: unknown; descriptor: Descriptor; argIndex: number };\ntype LengthLink = { target: OutParam; sources: LengthSource[] };\ntype OutParamGroups = { lengthLinks: LengthLink[]; valueParams: OutParam[] };\ntype OutValues = Map<number, unknown>;\n\ntype CallbackSpec = {\n argDescriptors: Descriptor[];\n returnDescriptor: Descriptor;\n userDataIndex?: number;\n};\n\ntype CallbackPlan = {\n fn: Callback;\n effectiveTypes: Descriptor[];\n returnDescriptor: Descriptor;\n hasPrimary: boolean;\n start: number;\n isInstanceBound: boolean;\n lengthSources: LengthSources;\n hasOutParams: boolean;\n hasRefOutParams: boolean;\n};\n\nconst CALLBACK_TRAITS: Record<CallbackKind, CallbackTraits> = {\n callback: { isInstanceBound: false, hasInstanceArg: false, hasFoldedLengths: true },\n signal: { isInstanceBound: false, hasInstanceArg: true, hasFoldedLengths: false },\n vfunc: { isInstanceBound: true, hasInstanceArg: true, hasFoldedLengths: true },\n};\n\nconst fillCallerAllocatedBuffer = (descriptor: Descriptor, target: object, source: object): void => {\n if (descriptor.kind === \"boxed\" && descriptor.typeName === \"GValue\") {\n copyValue(getHandle(target), getHandle(source));\n\n return;\n }\n\n if ((descriptor.kind === \"boxed\" || descriptor.kind === \"struct\") && descriptor.size !== undefined) {\n copy(getHandle(target), getHandle(source), descriptor.size);\n\n return;\n }\n\n throw new Error(`Cannot write caller-allocated ${descriptor.kind} out-parameter: no known byte size`);\n};\n\nconst isCallerAllocatedOut = (descriptor: Descriptor): boolean =>\n (descriptor.kind === \"boxed\" || descriptor.kind === \"struct\") && descriptor.isCallerAllocated === true;\n\nconst collectRefArg = (\n descriptor: RefDescriptor,\n wrappedValue: unknown,\n inputs: unknown[],\n out: { params: OutParam[]; argIndex: number },\n): void => {\n if (descriptor.inout === true) {\n inputs.push((wrappedValue as { value: unknown }).value);\n }\n\n out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });\n};\n\nconst collectCallbackArg = (\n descriptor: Descriptor | undefined,\n wrappedValue: unknown,\n inputs: unknown[],\n out: { params: OutParam[]; argIndex: number },\n): void => {\n if (descriptor?.kind === \"ref\") {\n collectRefArg(descriptor, wrappedValue, inputs, out);\n\n return;\n }\n\n inputs.push(wrappedValue);\n\n if (descriptor !== undefined && isCallerAllocatedOut(descriptor)) {\n out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });\n }\n};\n\nconst partitionCallbackArgs = (\n effectiveTypes: Descriptor[],\n wrapped: unknown[],\n start: number,\n): { inputs: unknown[]; outParams: OutParam[] } => {\n const inputs: unknown[] = [];\n const params: OutParam[] = [];\n const collected = { params, argIndex: start };\n\n for (let i = start; i < effectiveTypes.length; i++) {\n collected.argIndex = i;\n collectCallbackArg(effectiveTypes[i], wrapped[i], inputs, collected);\n }\n\n return { inputs, outParams: params };\n};\n\nconst hasOutParamArg = (descriptor: Descriptor | undefined): boolean =>\n descriptor !== undefined && (descriptor.kind === \"ref\" || isCallerAllocatedOut(descriptor));\n\nconst hasRefOutParamArg = (descriptor: Descriptor | undefined): boolean =>\n descriptor?.kind === \"ref\" && descriptor.inout !== true;\n\nconst haveOutParamArgs = (effectiveTypes: Descriptor[], start: number): boolean =>\n effectiveTypes.slice(start).some((descriptor) => hasOutParamArg(descriptor));\n\nconst haveRefOutParamArgs = (effectiveTypes: Descriptor[], start: number): boolean =>\n effectiveTypes.slice(start).some((descriptor) => hasRefOutParamArg(descriptor));\n\nconst groupOutParams = (outParams: OutParam[], lengthSources: LengthSources): OutParamGroups => {\n const groups: OutParamGroups = { lengthLinks: [], valueParams: [] };\n\n for (const outParam of outParams) {\n const sources = lengthSources.get(outParam.argIndex);\n\n if (sources === undefined) {\n groups.valueParams.push(outParam);\n } else {\n groups.lengthLinks.push({ target: outParam, sources });\n }\n }\n\n return groups;\n};\n\nconst getLength = (value: unknown): number => {\n const length = (value as { length?: unknown } | null | undefined)?.length;\n\n return typeof length === \"number\" ? length : 0;\n};\n\nconst lengthSourceValue = (source: LengthSource, outValues: OutValues, primary: unknown): unknown =>\n source.kind === \"return\" ? primary : outValues.get(source.argIndex);\n\nconst foldedLength = (sources: LengthSource[], outValues: OutValues, primary: unknown): number =>\n Math.min(...sources.map((source) => getLength(lengthSourceValue(source, outValues, primary))));\n\nconst resolveOutValues = (groups: OutParamGroups, values: unknown[], primary: unknown): OutValues => {\n const outValues: OutValues = new Map();\n\n for (const [position, outParam] of groups.valueParams.entries()) {\n outValues.set(outParam.argIndex, values[position]);\n }\n\n for (const link of groups.lengthLinks) {\n outValues.set(link.target.argIndex, foldedLength(link.sources, outValues, primary));\n }\n\n return outValues;\n};\n\nconst writeOutParams = (outParams: OutParam[], outValues: OutValues): void => {\n for (const outParam of outParams) {\n const { descriptor } = outParam;\n const outValue = outValues.get(outParam.argIndex);\n\n if (descriptor.kind === \"ref\") {\n (outParam.value as { value: unknown }).value = toNative(descriptor.innerDescriptor, outValue);\n } else if (outValue != null && outParam.value != null) {\n fillCallerAllocatedBuffer(descriptor, outParam.value, outValue);\n }\n }\n};\n\nconst collectRefSeeds = (outParams: OutParam[]): RefSeeds => {\n const seeds: RefSeeds = new Map();\n\n for (const outParam of outParams) {\n const seed = (outParam.value as { value?: unknown } | null)?.value;\n\n if (seed != null && hasRefOutParamArg(outParam.descriptor)) {\n seeds.set(outParam.argIndex, seed);\n }\n }\n\n return seeds;\n};\n\nconst applyCallback = (plan: CallbackPlan, thisArg: unknown, inputs: unknown[], outParams: OutParam[]): unknown => {\n if (!plan.hasRefOutParams) {\n return plan.fn.apply(thisArg, inputs);\n }\n\n pushSeedFrame({ argDescriptors: plan.effectiveTypes, instance: thisArg, seeds: collectRefSeeds(outParams) });\n\n try {\n return plan.fn.apply(thisArg, inputs);\n } finally {\n popSeedFrame();\n }\n};\n\nconst getThisArg = (isInstanceBound: boolean, wrapped: unknown[]): unknown =>\n isInstanceBound ? (wrapped[0] ?? null) : null;\n\nconst wrapCallbackArgs = (effectiveTypes: Descriptor[], rawArgs: unknown[]): void => {\n let index = 0;\n\n for (const descriptor of effectiveTypes) {\n rawArgs[index] = fromNative(descriptor, rawArgs[index]);\n index += 1;\n }\n};\n\nconst trimCallbackInputs = (plan: CallbackPlan, wrapped: unknown[]): unknown[] => {\n const count = plan.effectiveTypes.length;\n\n if (wrapped.length > count) {\n wrapped.length = count;\n }\n\n for (let index = 0; index < plan.start; index++) {\n wrapped.shift();\n }\n\n return wrapped;\n};\n\nconst nativeReturn = (plan: CallbackPlan, primary: unknown): unknown =>\n toNative(plan.returnDescriptor, plan.hasPrimary ? primary : undefined);\n\nconst runCallback = (plan: CallbackPlan, rawArgs: unknown[]): unknown => {\n const { effectiveTypes } = plan;\n wrapCallbackArgs(effectiveTypes, rawArgs);\n const thisArg = getThisArg(plan.isInstanceBound, rawArgs);\n\n if (!plan.hasOutParams) {\n return nativeReturn(plan, plan.fn.apply(thisArg, trimCallbackInputs(plan, rawArgs)));\n }\n\n const { inputs, outParams } = partitionCallbackArgs(effectiveTypes, rawArgs, plan.start);\n const result = applyCallback(plan, thisArg, inputs, outParams);\n\n if (outParams.length === 0) {\n return nativeReturn(plan, result);\n }\n\n const groups = groupOutParams(outParams, plan.lengthSources);\n const { primary, outValues } = splitTupleResult(result, plan.hasPrimary, groups.valueParams.length);\n writeOutParams(outParams, resolveOutValues(groups, outValues, primary));\n\n return nativeReturn(plan, primary);\n};\n\nconst planLengthSources = (spec: CallbackSpec, hasFoldedLengths: boolean): LengthSources =>\n hasFoldedLengths ? foldedLengthSources(spec) : new Map<number, LengthSource[]>();\n\nconst getEffectiveTypes = (spec: CallbackSpec): Descriptor[] => {\n const { userDataIndex } = spec;\n\n if (userDataIndex === undefined) {\n return spec.argDescriptors;\n }\n\n return spec.argDescriptors.filter((_, i) => i !== userDataIndex);\n};\n\nconst wrapCallbackValue = (spec: CallbackDescriptor, callback: unknown): unknown =>\n callback == null ? callback : wrapCallback(callback as Callback, spec, \"callback\");\n\nfunction wrapCallback(fn: Callback, spec: CallbackSpec, kind: CallbackKind): Callback {\n const effectiveTypes = getEffectiveTypes(spec);\n const { isInstanceBound, hasInstanceArg, hasFoldedLengths } = CALLBACK_TRAITS[kind];\n const start = hasInstanceArg ? 1 : 0;\n\n const plan: CallbackPlan = {\n fn,\n effectiveTypes,\n returnDescriptor: spec.returnDescriptor,\n hasPrimary: spec.returnDescriptor.kind !== \"void\",\n start,\n isInstanceBound,\n lengthSources: planLengthSources(spec, hasFoldedLengths),\n hasOutParams: haveOutParamArgs(effectiveTypes, start),\n hasRefOutParams: haveRefOutParamArgs(effectiveTypes, start),\n };\n\n return (...rawArgs: unknown[]): unknown => runCallback(plan, rawArgs);\n}\n\nexport { isCallerAllocatedOut, wrapCallbackValue, wrapCallback };\n"]}
|
|
1
|
+
{"version":3,"file":"callback.js","sourceR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M,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAErC,MAAM,IAAI,GAAiB;QACvB,EAAE;QACF,cAAc;QACd,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,UAAU,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,KAAK,MAAM;QACjD,KAAK;QACL,eAAe;QACf,aAAa,EAAE,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC;QACxD,YAAY,EAAE,gBAAgB,CAAC,cAAc,EAAE,KAAK,CAAC;QACrD,eAAe,EAAE,mBAAmB,CAAC,cAAc,EAAE,KAAK,CAAC;QAC3D,kBAAkB,EAAE,sBAAsB,CAAC,IAAI,EAAE,eAAe,CAAC;KACpE,CAAC;IAEF,OAAO,CAAC,GAAG,OAAkB,EAAW,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1E,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { copy, type Descriptor } from \"@gtkx/native\";\nimport type { CallbackDescriptor, RefDescriptor } from \"./descriptors.js\";\nimport {\n foldedLengthArgIndices,\n foldedLengthSources,\n type LengthSource,\n type LengthSources,\n} from \"./folded-lengths.js\";\nimport { fromNative, toNative } from \"./native-value.js\";\nimport { describeValueKind, getHandle } from \"./registry.js\";\nimport { splitTupleResult } from \"./tuple.js\";\nimport { copyValue } from \"./value.js\";\nimport { popSeedFrame, pushSeedFrame, type RefSeeds } from \"./vfunc-seeds.js\";\n\ntype Callback = (...args: unknown[]) => unknown;\ntype CallbackKind = \"vfunc\" | \"signal\" | \"callback\";\ntype CallbackTraits = {\n isInstanceBound: boolean;\n hasInstanceArg: boolean;\n hasFoldedLengths: boolean;\n hasFoldedInputs: boolean;\n};\ntype OutParam = { value: unknown; descriptor: Descriptor; argIndex: number };\ntype CollectedArgs = { params: OutParam[]; argIndex: number; isFolded: boolean };\ntype PartitionedArgs = { inputs: unknown[]; outParams: OutParam[] };\ntype LengthLink = { target: OutParam; sources: LengthSource[] };\ntype OutParamGroups = { lengthLinks: LengthLink[]; valueParams: OutParam[] };\ntype OutValues = Map<number, unknown>;\n\ntype CallbackSpec = {\n argDescriptors: Descriptor[];\n returnDescriptor: Descriptor;\n userDataIndex?: number;\n};\n\ntype CallbackPlan = {\n fn: Callback;\n effectiveTypes: Descriptor[];\n returnDescriptor: Descriptor;\n hasPrimary: boolean;\n start: number;\n isInstanceBound: boolean;\n lengthSources: LengthSources;\n hasOutParams: boolean;\n hasRefOutParams: boolean;\n foldedInputIndices: ReadonlySet<number>;\n};\n\nconst CALLBACK_TRAITS: Record<CallbackKind, CallbackTraits> = {\n callback: { isInstanceBound: false, hasInstanceArg: false, hasFoldedLengths: true, hasFoldedInputs: true },\n signal: { isInstanceBound: false, hasInstanceArg: true, hasFoldedLengths: false, hasFoldedInputs: false },\n vfunc: { isInstanceBound: true, hasInstanceArg: true, hasFoldedLengths: true, hasFoldedInputs: false },\n};\n\nconst fillCallerAllocatedBuffer = (descriptor: Descriptor, target: object, source: object): void => {\n if (descriptor.kind === \"boxed\" && descriptor.typeName === \"GValue\") {\n copyValue(getHandle(target), getHandle(source));\n\n return;\n }\n\n if ((descriptor.kind === \"boxed\" || descriptor.kind === \"struct\") && descriptor.size !== undefined) {\n copy(getHandle(target), getHandle(source), descriptor.size);\n\n return;\n }\n\n throw new Error(`Cannot write caller-allocated ${descriptor.kind} out-parameter: no known byte size`);\n};\n\nconst isCallerAllocatedOut = (descriptor: Descriptor): boolean =>\n (descriptor.kind === \"boxed\" || descriptor.kind === \"struct\") && descriptor.isCallerAllocated === true;\n\nconst collectRefArg = (\n descriptor: RefDescriptor,\n wrappedValue: unknown,\n inputs: unknown[],\n out: CollectedArgs,\n): void => {\n if (descriptor.inout === true && !out.isFolded) {\n inputs.push((wrappedValue as { value: unknown }).value);\n }\n\n out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });\n};\n\nconst collectCallbackArg = (\n descriptor: Descriptor | undefined,\n wrappedValue: unknown,\n inputs: unknown[],\n out: CollectedArgs,\n): void => {\n if (descriptor?.kind === \"ref\") {\n collectRefArg(descriptor, wrappedValue, inputs, out);\n\n return;\n }\n\n if (!out.isFolded) {\n inputs.push(wrappedValue);\n }\n\n if (descriptor !== undefined && isCallerAllocatedOut(descriptor)) {\n out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });\n }\n};\n\nconst partitionCallbackArgs = (plan: CallbackPlan, wrapped: unknown[]): PartitionedArgs => {\n const inputs: unknown[] = [];\n const params: OutParam[] = [];\n const collected: CollectedArgs = { params, argIndex: plan.start, isFolded: false };\n\n for (let i = plan.start; i < plan.effectiveTypes.length; i++) {\n collected.argIndex = i;\n collected.isFolded = plan.foldedInputIndices.has(i);\n collectCallbackArg(plan.effectiveTypes[i], wrapped[i], inputs, collected);\n }\n\n return { inputs, outParams: params };\n};\n\nconst hasOutParamArg = (descriptor: Descriptor | undefined): boolean =>\n descriptor !== undefined && (descriptor.kind === \"ref\" || isCallerAllocatedOut(descriptor));\n\nconst hasRefOutParamArg = (descriptor: Descriptor | undefined): boolean =>\n descriptor?.kind === \"ref\" && descriptor.inout !== true;\n\nconst haveOutParamArgs = (effectiveTypes: Descriptor[], start: number): boolean =>\n effectiveTypes.slice(start).some((descriptor) => hasOutParamArg(descriptor));\n\nconst haveRefOutParamArgs = (effectiveTypes: Descriptor[], start: number): boolean =>\n effectiveTypes.slice(start).some((descriptor) => hasRefOutParamArg(descriptor));\n\nconst groupOutParams = (outParams: OutParam[], lengthSources: LengthSources): OutParamGroups => {\n const groups: OutParamGroups = { lengthLinks: [], valueParams: [] };\n\n for (const outParam of outParams) {\n const sources = lengthSources.get(outParam.argIndex);\n\n if (sources === undefined) {\n groups.valueParams.push(outParam);\n } else {\n groups.lengthLinks.push({ target: outParam, sources });\n }\n }\n\n return groups;\n};\n\nconst getLength = (value: unknown): number => {\n const length = (value as { length?: unknown } | null | undefined)?.length;\n\n return typeof length === \"number\" ? length : 0;\n};\n\nconst lengthSourceValue = (source: LengthSource, outValues: OutValues, primary: unknown): unknown =>\n source.kind === \"return\" ? primary : outValues.get(source.argIndex);\n\nconst foldedLength = (sources: LengthSource[], outValues: OutValues, primary: unknown): number =>\n Math.min(...sources.map((source) => getLength(lengthSourceValue(source, outValues, primary))));\n\nconst resolveOutValues = (groups: OutParamGroups, values: unknown[], primary: unknown): OutValues => {\n const outValues: OutValues = new Map();\n\n for (const [position, outParam] of groups.valueParams.entries()) {\n outValues.set(outParam.argIndex, values[position]);\n }\n\n for (const link of groups.lengthLinks) {\n outValues.set(link.target.argIndex, foldedLength(link.sources, outValues, primary));\n }\n\n return outValues;\n};\n\nconst writeOutParams = (outParams: OutParam[], outValues: OutValues): void => {\n for (const outParam of outParams) {\n const { descriptor } = outParam;\n const outValue = outValues.get(outParam.argIndex);\n\n if (descriptor.kind === \"ref\") {\n (outParam.value as { value: unknown }).value = toNative(descriptor.innerDescriptor, outValue);\n } else if (outValue != null && outParam.value != null) {\n fillCallerAllocatedBuffer(descriptor, outParam.value, outValue);\n }\n }\n};\n\nconst collectRefSeeds = (outParams: OutParam[]): RefSeeds => {\n const seeds: RefSeeds = new Map();\n\n for (const outParam of outParams) {\n const seed = (outParam.value as { value?: unknown } | null)?.value;\n\n if (seed != null && hasRefOutParamArg(outParam.descriptor)) {\n seeds.set(outParam.argIndex, seed);\n }\n }\n\n return seeds;\n};\n\nconst applyCallback = (plan: CallbackPlan, thisArg: unknown, inputs: unknown[], outParams: OutParam[]): unknown => {\n if (!plan.hasRefOutParams) {\n return plan.fn.apply(thisArg, inputs);\n }\n\n pushSeedFrame({ argDescriptors: plan.effectiveTypes, instance: thisArg, seeds: collectRefSeeds(outParams) });\n\n try {\n return plan.fn.apply(thisArg, inputs);\n } finally {\n popSeedFrame();\n }\n};\n\nconst getThisArg = (isInstanceBound: boolean, wrapped: unknown[]): unknown =>\n isInstanceBound ? (wrapped[0] ?? null) : null;\n\nconst wrapCallbackArgs = (effectiveTypes: Descriptor[], rawArgs: unknown[]): void => {\n let index = 0;\n\n for (const descriptor of effectiveTypes) {\n rawArgs[index] = fromNative(descriptor, rawArgs[index]);\n index += 1;\n }\n};\n\nconst trimCallbackInputs = (plan: CallbackPlan, wrapped: unknown[]): unknown[] => {\n const inputs: unknown[] = [];\n\n for (let index = plan.start; index < plan.effectiveTypes.length; index++) {\n if (!plan.foldedInputIndices.has(index)) {\n inputs.push(wrapped[index]);\n }\n }\n\n return inputs;\n};\n\nconst nativeReturn = (plan: CallbackPlan, primary: unknown): unknown =>\n toNative(plan.returnDescriptor, plan.hasPrimary ? primary : undefined);\n\nconst runCallback = (plan: CallbackPlan, rawArgs: unknown[]): unknown => {\n const { effectiveTypes } = plan;\n wrapCallbackArgs(effectiveTypes, rawArgs);\n const thisArg = getThisArg(plan.isInstanceBound, rawArgs);\n\n if (!plan.hasOutParams) {\n return nativeReturn(plan, plan.fn.apply(thisArg, trimCallbackInputs(plan, rawArgs)));\n }\n\n const { inputs, outParams } = partitionCallbackArgs(plan, rawArgs);\n const result = applyCallback(plan, thisArg, inputs, outParams);\n\n if (outParams.length === 0) {\n return nativeReturn(plan, result);\n }\n\n const groups = groupOutParams(outParams, plan.lengthSources);\n const { primary, outValues } = splitTupleResult(result, plan.hasPrimary, groups.valueParams.length);\n writeOutParams(outParams, resolveOutValues(groups, outValues, primary));\n\n return nativeReturn(plan, primary);\n};\n\nconst planLengthSources = (spec: CallbackSpec, hasFoldedLengths: boolean): LengthSources =>\n hasFoldedLengths ? foldedLengthSources(spec) : new Map<number, LengthSource[]>();\n\nconst getEffectiveTypes = (spec: CallbackSpec): Descriptor[] => {\n const { userDataIndex } = spec;\n\n if (userDataIndex === undefined) {\n return spec.argDescriptors;\n }\n\n return spec.argDescriptors.filter((_, i) => i !== userDataIndex);\n};\n\nconst wrapCallbackValue = (spec: CallbackDescriptor, callback: unknown): unknown =>\n callback == null ? callback : wrapCallback(callback as Callback, spec, \"callback\");\n\nconst planFoldedInputIndices = (spec: CallbackSpec, hasFoldedInputs: boolean): ReadonlySet<number> =>\n hasFoldedInputs ? foldedLengthArgIndices(spec) : new Set<number>();\n\n/** Thrown when a value passed where a callback, signal handler or vfunc is expected cannot be called. */\nclass CallbackMarshalError extends TypeError {\n /** Name callers match on when the error is caught as a plain `TypeError`. */\n public override name = \"CallbackMarshalError\";\n}\n\nfunction wrapCallback(fn: Callback, spec: CallbackSpec, kind: CallbackKind): Callback {\n if (typeof fn !== \"function\") {\n throw new CallbackMarshalError(`Cannot marshal ${describeValueKind(fn)} into a ${kind}`);\n }\n\n const effectiveTypes = getEffectiveTypes(spec);\n const { isInstanceBound, hasInstanceArg, hasFoldedLengths, hasFoldedInputs } = CALLBACK_TRAITS[kind];\n const start = hasInstanceArg ? 1 : 0;\n\n const plan: CallbackPlan = {\n fn,\n effectiveTypes,\n returnDescriptor: spec.returnDescriptor,\n hasPrimary: spec.returnDescriptor.kind !== \"void\",\n start,\n isInstanceBound,\n lengthSources: planLengthSources(spec, hasFoldedLengths),\n hasOutParams: haveOutParamArgs(effectiveTypes, start),\n hasRefOutParams: haveRefOutParamArgs(effectiveTypes, start),\n foldedInputIndices: planFoldedInputIndices(spec, hasFoldedInputs),\n };\n\n return (...rawArgs: unknown[]): unknown => runCallback(plan, rawArgs);\n}\n\nexport { CallbackMarshalError, isCallerAllocatedOut, wrapCallbackValue, wrapCallback };\n"]}
|
package/dist/closure.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ExternalObject, type Handle } from "@gtkx/native";
|
|
2
|
+
import { type CallbackDescriptor } from "./descriptors.js";
|
|
2
3
|
/**
|
|
3
4
|
* Handler backing a `GClosure`. It receives the closure's parameters already converted from their
|
|
4
5
|
* `GValue`s, and its result is written back into the closure's return `GValue` when it has one.
|
|
@@ -8,6 +9,7 @@ import { type ExternalObject, type Handle } from "@gtkx/native";
|
|
|
8
9
|
* handler produces that parameter's value. It stops being valid once the handler returns.
|
|
9
10
|
*/
|
|
10
11
|
type ClosureCallback = (...args: never[]) => unknown;
|
|
12
|
+
declare function newCCallbackClosure(key: string, callback: CallbackDescriptor, fn: unknown): ExternalObject<Handle>;
|
|
11
13
|
/**
|
|
12
14
|
* Marshals a value passed where a `GObject.Closure` is expected into a closure handle: a function
|
|
13
15
|
* becomes a new `GClosure` dispatching into it, and an existing closure yields its own handle.
|
|
@@ -22,5 +24,5 @@ declare class ClosureMarshalError extends TypeError {
|
|
|
22
24
|
/** Name callers match on when the error is caught as a plain `TypeError`. */
|
|
23
25
|
name: string;
|
|
24
26
|
}
|
|
25
|
-
export { type ClosureCallback, ClosureMarshalError, toClosure, tryToClosure };
|
|
27
|
+
export { type ClosureCallback, ClosureMarshalError, newCCallbackClosure, toClosure, tryToClosure };
|
|
26
28
|
//# sourceMappingURL=closure.d.ts.map
|
package/dist/closure.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closure.d.ts","sourceRoot":"","sources":["../src/closure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"closure.d.ts","sourceRoot":"","sources":["../src/closure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAuB,MAAM,cAAc,CAAC;AAGrF,OAAO,EAGH,KAAK,kBAAkB,EAO1B,MAAM,kBAAkB,CAAC;AAM1B;;;;;;;GAOG;AACH,KAAK,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAkFrD,iBAAS,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,EAAE,EAAE,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,CAQ3G;AAED;;;;;GAKG;AACH,iBAAS,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,CAUzD;AAED,oGAAoG;AACpG,iBAAS,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS,CAExE;AAED,sGAAsG;AACtG,cAAM,mBAAoB,SAAQ,SAAS;IACvC,6EAA6E;IAC7D,IAAI,SAAyB;CAChD;AAED,OAAO,EAAE,KAAK,eAAe,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/closure.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { read } from "@gtkx/native";
|
|
1
|
+
import { read, symbolAddress } from "@gtkx/native";
|
|
2
2
|
import {} from "@gtkx/utils";
|
|
3
|
-
import { bind } from "./bind.js";
|
|
4
|
-
import { boxedT, callbackT, sizedArrayT, structT, uint32T, uint64T, voidT } from "./descriptors.js";
|
|
3
|
+
import { bind, createBindCache } from "./bind.js";
|
|
4
|
+
import { biguint64T, boxedT, callbackT, sizedArrayT, structT, uint32T, uint64T, voidT, } from "./descriptors.js";
|
|
5
5
|
import { CLOSURE_SIZE, LIB, VALUE_SIZE, VALUE_T } from "./library.js";
|
|
6
6
|
import { describeValueKind, getClassType, getHandle, getWrapperClass, wrapHandle } from "./registry.js";
|
|
7
7
|
import { resolveBoxedType, typeIsA } from "./type.js";
|
|
@@ -40,7 +40,10 @@ const gCclosureNew = bind(LIB, "g_cclosure_new", [MARSHAL_T], OWNED_CLOSURE_T);
|
|
|
40
40
|
const gValueGetBoxed = bind(LIB, "g_value_get_boxed", [VALUE_T], NESTED_VALUE_T);
|
|
41
41
|
const gClosureRef = bind(LIB, "g_closure_ref", [CLOSURE_T], uint64T);
|
|
42
42
|
const gClosureSink = bind(LIB, "g_closure_sink", [CLOSURE_T], voidT);
|
|
43
|
-
const gClosureSetMarshal = bind(LIB, "g_closure_set_marshal", [CLOSURE_T,
|
|
43
|
+
const gClosureSetMarshal = bind(LIB, "g_closure_set_marshal", [CLOSURE_T, biguint64T], voidT);
|
|
44
|
+
const cclosureNewCache = createBindCache();
|
|
45
|
+
const genericMarshal = {};
|
|
46
|
+
const genericClosureMarshal = () => (genericMarshal.address ??= symbolAddress(LIB, "g_cclosure_marshal_generic"));
|
|
44
47
|
const isClosureInstance = (value) => typeIsA(getClassType(value.constructor), resolveBoxedType(CLOSURE_T));
|
|
45
48
|
const getNestedValue = (param) => wrapHandle(gValueGetBoxed(param), getWrapperClass(resolveBoxedType(VALUE_T)));
|
|
46
49
|
const fromParamValue = (param) => getValueType(param) === resolveBoxedType(VALUE_T) ? getNestedValue(param) : fromValue(param);
|
|
@@ -56,12 +59,20 @@ function marshalFor(callback) {
|
|
|
56
59
|
}
|
|
57
60
|
function newClosure(callback) {
|
|
58
61
|
const handle = gCclosureNew(marshalFor(callback));
|
|
59
|
-
const marshal = read(handle,
|
|
62
|
+
const marshal = read(handle, biguint64T, CCLOSURE_CALLBACK_OFFSET);
|
|
60
63
|
gClosureRef(handle);
|
|
61
64
|
gClosureSink(handle);
|
|
62
65
|
gClosureSetMarshal(handle, marshal);
|
|
63
66
|
return handle;
|
|
64
67
|
}
|
|
68
|
+
function newCCallbackClosure(key, callback, fn) {
|
|
69
|
+
const create = cclosureNewCache(key, LIB, "g_cclosure_new", [callback], OWNED_CLOSURE_T);
|
|
70
|
+
const handle = create(fn);
|
|
71
|
+
gClosureRef(handle);
|
|
72
|
+
gClosureSink(handle);
|
|
73
|
+
gClosureSetMarshal(handle, genericClosureMarshal());
|
|
74
|
+
return handle;
|
|
75
|
+
}
|
|
65
76
|
/**
|
|
66
77
|
* Marshals a value passed where a `GObject.Closure` is expected into a closure handle: a function
|
|
67
78
|
* becomes a new `GClosure` dispatching into it, and an existing closure yields its own handle.
|
|
@@ -86,5 +97,5 @@ class ClosureMarshalError extends TypeError {
|
|
|
86
97
|
/** Name callers match on when the error is caught as a plain `TypeError`. */
|
|
87
98
|
name = "ClosureMarshalError";
|
|
88
99
|
}
|
|
89
|
-
export { ClosureMarshalError, toClosure, tryToClosure };
|
|
100
|
+
export { ClosureMarshalError, newCCallbackClosure, toClosure, tryToClosure };
|
|
90
101
|
//# sourceMappingURL=closure.js.map
|
package/dist/closure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closure.js","sourceRoot":"","sources":["../src/closure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,IAAI,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAiB,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAYhE,MAAM,wBAAwB,GAAG,YAAY,CAAC;AAC9C,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,EAAE,oBAAoB,EAAE,CAAC,CAAC;AAElG,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,EAAE;IACvC,SAAS,EAAE,MAAM;IACjB,aAAa,EAAE,GAAG;IAClB,aAAa,EAAE,oBAAoB;CACtC,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,MAAM,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,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,UAAU,CAAC,KAAwB,CAAC,CAAC;IAChD,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1E,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,IAAI,mBAAmB,CAAC,kBAAkB,iBAAiB,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACvG,CAAC;AAED,oGAAoG;AACpG,SAAS,YAAY,CAAC,KAAc;IAChC,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED,sGAAsG;AACtG,MAAM,mBAAoB,SAAQ,SAAS;IACvC,6EAA6E;IAC7D,IAAI,GAAG,qBAAqB,CAAC;CAChD;AAED,OAAO,EAAwB,mBAAmB,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { type ExternalObject, type Handle, read } from \"@gtkx/native\";\nimport { type AnyClass } from \"@gtkx/utils\";\nimport { bind } from \"./bind.js\";\nimport { boxedT, callbackT, sizedArrayT, structT, uint32T, uint64T, voidT } from \"./descriptors.js\";\nimport { CLOSURE_SIZE, LIB, VALUE_SIZE, VALUE_T } from \"./library.js\";\nimport { describeValueKind, getClassType, getHandle, getWrapperClass, wrapHandle } from \"./registry.js\";\nimport { resolveBoxedType, typeIsA } from \"./type.js\";\nimport { fromValue, getValueType, intoValue } from \"./value.js\";\n\n/**\n * Handler backing a `GClosure`. It receives the closure's parameters already converted from their\n * `GValue`s, and its result is written back into the closure's return `GValue` when it has one.\n *\n * A parameter that is itself a `GValue`, such as the target a property binding transform fills in,\n * arrives as the caller's own `GObject.Value` rather than a copy, so writing to it is how the\n * handler produces that parameter's value. It stops being valid once the handler returns.\n */\ntype ClosureCallback = (...args: never[]) => unknown;\n\nconst CCLOSURE_CALLBACK_OFFSET = CLOSURE_SIZE;\nconst N_PARAM_VALUES_INDEX = 2;\nconst MARSHAL_DATA_INDEX = 5;\nconst CLOSURE_T = boxedT(\"GClosure\", { sharedLibrary: LIB, getTypeFnName: \"g_closure_get_type\" });\n\nconst OWNED_CLOSURE_T = boxedT(\"GClosure\", {\n ownership: \"full\",\n sharedLibrary: LIB,\n getTypeFnName: \"g_closure_get_type\",\n});\n\nconst MARSHAL_VALUE_T = boxedT(\"GValue\", {\n sharedLibrary: LIB,\n getTypeFnName: \"g_value_get_type\",\n size: VALUE_SIZE,\n isCallerAllocated: true,\n});\n\nconst MARSHAL_T = callbackT(\n [\n CLOSURE_T,\n MARSHAL_VALUE_T,\n uint32T,\n sizedArrayT(MARSHAL_VALUE_T, N_PARAM_VALUES_INDEX, \"borrowed\", { elementSize: VALUE_SIZE }),\n uint64T,\n uint64T,\n ],\n voidT,\n {\n hasUserData: true,\n userDataIndex: MARSHAL_DATA_INDEX,\n hasDestroy: true,\n destroyKind: \"closureNotify\",\n scope: \"notified\",\n },\n);\n\nconst NESTED_VALUE_T = structT(\"borrowed\");\nconst gCclosureNew = bind(LIB, \"g_cclosure_new\", [MARSHAL_T], OWNED_CLOSURE_T);\nconst gValueGetBoxed = bind(LIB, \"g_value_get_boxed\", [VALUE_T], NESTED_VALUE_T);\nconst gClosureRef = bind(LIB, \"g_closure_ref\", [CLOSURE_T], uint64T);\nconst gClosureSink = bind(LIB, \"g_closure_sink\", [CLOSURE_T], voidT);\nconst gClosureSetMarshal = bind(LIB, \"g_closure_set_marshal\", [CLOSURE_T, uint64T], voidT);\n\nconst isClosureInstance = (value: object): boolean =>\n typeIsA(getClassType(value.constructor as AnyClass), resolveBoxedType(CLOSURE_T));\n\nconst getNestedValue = (param: ExternalObject<Handle>): object | null =>\n wrapHandle(gValueGetBoxed(param) as ExternalObject<Handle> | null, getWrapperClass(resolveBoxedType(VALUE_T)));\n\nconst fromParamValue = (param: ExternalObject<Handle>): unknown =>\n getValueType(param) === resolveBoxedType(VALUE_T) ? getNestedValue(param) : fromValue(param);\n\nfunction marshalFor(callback: ClosureCallback): (...args: unknown[]) => void {\n return (_closure: unknown, returnValue: unknown, _count: unknown, paramValues: unknown): void => {\n const values = paramValues as ExternalObject<Handle>[];\n const args = values.map((value) => fromParamValue(value));\n const result = (callback as (...values: unknown[]) => unknown)(...(args as never[]));\n\n if (returnValue !== null) {\n intoValue(returnValue as ExternalObject<Handle>, result);\n }\n };\n}\n\nfunction newClosure(callback: ClosureCallback): ExternalObject<Handle> {\n const handle = gCclosureNew(marshalFor(callback)) as ExternalObject<Handle>;\n const marshal = read(handle, uint64T, CCLOSURE_CALLBACK_OFFSET);\n gClosureRef(handle);\n gClosureSink(handle);\n gClosureSetMarshal(handle, marshal);\n\n return handle;\n}\n\n/**\n * Marshals a value passed where a `GObject.Closure` is expected into a closure handle: a function\n * becomes a new `GClosure` dispatching into it, and an existing closure yields its own handle.\n * @param value Function to wrap, or an already-built closure.\n * @throws {ClosureMarshalError} When the value is neither.\n */\nfunction toClosure(value: unknown): ExternalObject<Handle> {\n if (typeof value === \"function\") {\n return newClosure(value as ClosureCallback);\n }\n\n if (typeof value === \"object\" && value !== null && isClosureInstance(value)) {\n return getHandle(value);\n }\n\n throw new ClosureMarshalError(`Cannot marshal ${describeValueKind(value)} into a GObject.Closure`);\n}\n\n/** Same as {@link toClosure}, but passes a null or undefined value through as no closure at all. */\nfunction tryToClosure(value: unknown): ExternalObject<Handle> | undefined {\n return value == null ? undefined : toClosure(value);\n}\n\n/** Thrown when a value passed where a `GObject.Closure` is expected cannot be marshalled into one. */\nclass ClosureMarshalError extends TypeError {\n /** Name callers match on when the error is caught as a plain `TypeError`. */\n public override name = \"ClosureMarshalError\";\n}\n\nexport { type ClosureCallback, ClosureMarshalError, toClosure, tryToClosure };\n"]}
|
|
1
|
+
{"version":3,"file":"closure.js","sourceRoot":"","sources":["../src/closure.ts"],"names":[],"mappings":"AAAA,O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gB,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,EAAE,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC,CAAC;IACzF,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,CAA2B,CAAC;IACpD,WAAW,CAAC,MAAM,CAAC,CAAC;IACpB,YAAY,CAAC,MAAM,CAAC,CAAC;IACrB,kBAAkB,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,CAAC;IAEpD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAAC,KAAc;IAC7B,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,UAAU,CAAC,KAAwB,CAAC,CAAC;IAChD,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1E,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,IAAI,mBAAmB,CAAC,kBAAkB,iBAAiB,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACvG,CAAC;AAED,oGAAoG;AACpG,SAAS,YAAY,CAAC,KAAc;IAChC,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED,sGAAsG;AACtG,MAAM,mBAAoB,SAAQ,SAAS;IACvC,6EAA6E;IAC7D,IAAI,GAAG,qBAAqB,CAAC;CAChD;AAED,OAAO,EAAwB,mBAAmB,EAAE,mBAAmB,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { type ExternalObject, type Handle, read, symbolAddress } from \"@gtkx/native\";\nimport { type AnyClass } from \"@gtkx/utils\";\nimport { bind, createBindCache } from \"./bind.js\";\nimport {\n biguint64T,\n boxedT,\n type CallbackDescriptor,\n callbackT,\n sizedArrayT,\n structT,\n uint32T,\n uint64T,\n voidT,\n} from \"./descriptors.js\";\nimport { CLOSURE_SIZE, LIB, VALUE_SIZE, VALUE_T } from \"./library.js\";\nimport { describeValueKind, getClassType, getHandle, getWrapperClass, wrapHandle } from \"./registry.js\";\nimport { resolveBoxedType, typeIsA } from \"./type.js\";\nimport { fromValue, getValueType, intoValue } from \"./value.js\";\n\n/**\n * Handler backing a `GClosure`. It receives the closure's parameters already converted from their\n * `GValue`s, and its result is written back into the closure's return `GValue` when it has one.\n *\n * A parameter that is itself a `GValue`, such as the target a property binding transform fills in,\n * arrives as the caller's own `GObject.Value` rather than a copy, so writing to it is how the\n * handler produces that parameter's value. It stops being valid once the handler returns.\n */\ntype ClosureCallback = (...args: never[]) => unknown;\n\nconst CCLOSURE_CALLBACK_OFFSET = CLOSURE_SIZE;\nconst N_PARAM_VALUES_INDEX = 2;\nconst MARSHAL_DATA_INDEX = 5;\nconst CLOSURE_T = boxedT(\"GClosure\", { sharedLibrary: LIB, getTypeFnName: \"g_closure_get_type\" });\n\nconst OWNED_CLOSURE_T = boxedT(\"GClosure\", {\n ownership: \"full\",\n sharedLibrary: LIB,\n getTypeFnName: \"g_closure_get_type\",\n});\n\nconst MARSHAL_VALUE_T = boxedT(\"GValue\", {\n sharedLibrary: LIB,\n getTypeFnName: \"g_value_get_type\",\n size: VALUE_SIZE,\n isCallerAllocated: true,\n});\n\nconst MARSHAL_T = callbackT(\n [\n CLOSURE_T,\n MARSHAL_VALUE_T,\n uint32T,\n sizedArrayT(MARSHAL_VALUE_T, N_PARAM_VALUES_INDEX, \"borrowed\", { elementSize: VALUE_SIZE }),\n uint64T,\n uint64T,\n ],\n voidT,\n {\n hasUserData: true,\n userDataIndex: MARSHAL_DATA_INDEX,\n hasDestroy: true,\n destroyKind: \"closureNotify\",\n scope: \"notified\",\n },\n);\n\nconst NESTED_VALUE_T = structT(\"borrowed\");\nconst gCclosureNew = bind(LIB, \"g_cclosure_new\", [MARSHAL_T], OWNED_CLOSURE_T);\nconst gValueGetBoxed = bind(LIB, \"g_value_get_boxed\", [VALUE_T], NESTED_VALUE_T);\nconst gClosureRef = bind(LIB, \"g_closure_ref\", [CLOSURE_T], uint64T);\nconst gClosureSink = bind(LIB, \"g_closure_sink\", [CLOSURE_T], voidT);\nconst gClosureSetMarshal = bind(LIB, \"g_closure_set_marshal\", [CLOSURE_T, biguint64T], voidT);\nconst cclosureNewCache = createBindCache();\nconst genericMarshal: { address?: bigint } = {};\n\nconst genericClosureMarshal = (): bigint =>\n (genericMarshal.address ??= symbolAddress(LIB, \"g_cclosure_marshal_generic\"));\n\nconst isClosureInstance = (value: object): boolean =>\n typeIsA(getClassType(value.constructor as AnyClass), resolveBoxedType(CLOSURE_T));\n\nconst getNestedValue = (param: ExternalObject<Handle>): object | null =>\n wrapHandle(gValueGetBoxed(param) as ExternalObject<Handle> | null, getWrapperClass(resolveBoxedType(VALUE_T)));\n\nconst fromParamValue = (param: ExternalObject<Handle>): unknown =>\n getValueType(param) === resolveBoxedType(VALUE_T) ? getNestedValue(param) : fromValue(param);\n\nfunction marshalFor(callback: ClosureCallback): (...args: unknown[]) => void {\n return (_closure: unknown, returnValue: unknown, _count: unknown, paramValues: unknown): void => {\n const values = paramValues as ExternalObject<Handle>[];\n const args = values.map((value) => fromParamValue(value));\n const result = (callback as (...values: unknown[]) => unknown)(...(args as never[]));\n\n if (returnValue !== null) {\n intoValue(returnValue as ExternalObject<Handle>, result);\n }\n };\n}\n\nfunction newClosure(callback: ClosureCallback): ExternalObject<Handle> {\n const handle = gCclosureNew(marshalFor(callback)) as ExternalObject<Handle>;\n const marshal = read(handle, biguint64T, CCLOSURE_CALLBACK_OFFSET);\n gClosureRef(handle);\n gClosureSink(handle);\n gClosureSetMarshal(handle, marshal);\n\n return handle;\n}\n\nfunction newCCallbackClosure(key: string, callback: CallbackDescriptor, fn: unknown): ExternalObject<Handle> {\n const create = cclosureNewCache(key, LIB, \"g_cclosure_new\", [callback], OWNED_CLOSURE_T);\n const handle = create(fn) as ExternalObject<Handle>;\n gClosureRef(handle);\n gClosureSink(handle);\n gClosureSetMarshal(handle, genericClosureMarshal());\n\n return handle;\n}\n\n/**\n * Marshals a value passed where a `GObject.Closure` is expected into a closure handle: a function\n * becomes a new `GClosure` dispatching into it, and an existing closure yields its own handle.\n * @param value Function to wrap, or an already-built closure.\n * @throws {ClosureMarshalError} When the value is neither.\n */\nfunction toClosure(value: unknown): ExternalObject<Handle> {\n if (typeof value === \"function\") {\n return newClosure(value as ClosureCallback);\n }\n\n if (typeof value === \"object\" && value !== null && isClosureInstance(value)) {\n return getHandle(value);\n }\n\n throw new ClosureMarshalError(`Cannot marshal ${describeValueKind(value)} into a GObject.Closure`);\n}\n\n/** Same as {@link toClosure}, but passes a null or undefined value through as no closure at all. */\nfunction tryToClosure(value: unknown): ExternalObject<Handle> | undefined {\n return value == null ? undefined : toClosure(value);\n}\n\n/** Thrown when a value passed where a `GObject.Closure` is expected cannot be marshalled into one. */\nclass ClosureMarshalError extends TypeError {\n /** Name callers match on when the error is caught as a plain `TypeError`. */\n public override name = \"ClosureMarshalError\";\n}\n\nexport { type ClosureCallback, ClosureMarshalError, newCCallbackClosure, toClosure, tryToClosure };\n"]}
|