-
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.
generate error enums correctly, like GLib.UriError
- Loading branch information
Showing
4 changed files
with
55 additions
and
5 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,11 @@ | ||
import { libName, openLib } from "../base_utils/ffipp.js"; | ||
|
||
import { $string, $u32 } from "../base_utils/types.ts"; | ||
|
||
const { g } = openLib(libName("glib-2.0", 0), { | ||
g: { | ||
quark_from_string: $u32($string), | ||
}, | ||
}); | ||
|
||
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
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); | ||
} |