-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from vixalien/log-invoke-error
Throw invoke errors
- Loading branch information
Showing
10 changed files
with
187 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { libName, openLib } from "../base_utils/ffipp.js"; | ||
|
||
import { $pointer, $string, $u32 } from "../base_utils/types.ts"; | ||
|
||
const { g } = openLib(libName("glib-2.0", 0), { | ||
g: { | ||
quark_from_string: $u32($string), | ||
slist: { | ||
length: $u32($pointer), | ||
nth: $pointer($pointer, $u32), | ||
}, | ||
}, | ||
}); | ||
|
||
export default g; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import glib from "./glib.js"; | ||
import gir from "./girepository.js"; | ||
import gobject from "./gobject.js"; | ||
|
||
export default { ...gir, ...gobject }; | ||
export default { ...gir, ...gobject, ...glib }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,53 @@ | ||
import g from "../bindings/mod.js"; | ||
import handleInfo from "../handleInfo.js"; | ||
import { getGLibError } from "../utils/error.ts"; | ||
import { getName } from "../utils/string.ts"; | ||
|
||
export function createEnum(info) { | ||
const result = new Object(); | ||
|
||
function defineValues(target, info) { | ||
const nValues = g.enum_info.get_n_values(info); | ||
|
||
for (let i = 0; i < nValues; i++) { | ||
const valueInfo = g.enum_info.get_value(info, i); | ||
handleInfo(result, valueInfo); | ||
handleInfo(target, valueInfo); | ||
g.base_info.unref(valueInfo); | ||
} | ||
} | ||
|
||
export function createError(info, error_domain) { | ||
const GError = getGLibError(); | ||
|
||
const ObjectClass = class extends GError { | ||
constructor(props) { | ||
super({ | ||
...props, | ||
domain: g.quark_from_string(error_domain), | ||
}); | ||
} | ||
|
||
[Symbol.hasInstance](instance) { | ||
return (instance instanceof GError) && (instance.domain === this.domain); | ||
} | ||
}; | ||
|
||
Object.defineProperty(ObjectClass, "name", { | ||
value: getName(info), | ||
}); | ||
|
||
defineValues(ObjectClass, info); | ||
|
||
return ObjectClass; | ||
} | ||
|
||
export function createEnum(info) { | ||
const error_domain = g.enum_info.get_error_domain(info); | ||
|
||
if (error_domain) { | ||
return createError(info, error_domain); | ||
} | ||
|
||
const result = new Object(); | ||
|
||
defineValues(result, info); | ||
|
||
return Object.freeze(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { cast_u64_ptr } from "../base_utils/convert.ts"; | ||
import { require } from "../gi.js"; | ||
|
||
export function createGError(pointer: bigint) { | ||
const GError = getGLibError(); | ||
|
||
const error = Object.create(GError.prototype); | ||
Reflect.defineMetadata("gi:ref", cast_u64_ptr(pointer), error); | ||
|
||
error.stack = new Error().stack; | ||
|
||
return error; | ||
} | ||
|
||
export function getGLibError() { | ||
return require("GLib", "2.0").Error; | ||
} |