-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw invoke errors #12
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0ad4128
add gerrorToString function
vixalien 1216486
reduce invoke error memory size as it's a pointer
vixalien 9a64a2b
log invoke error correctly
vixalien 8c3700c
throw GError when function invocation fails
vixalien 4a8cd86
cache repos
vixalien 3d3dcd3
use a global GLib.Error
vixalien 3ab134f
attach stack trace to generated GError
vixalien 6198538
generate error enums correctly, like GLib.UriError
vixalien 289041f
remove commented-out code
vixalien 8481524
fix adding a second pointer value for structs
vixalien 41f6597
remove unused girepository_find_by_name symbol
vixalien b37fb11
remove undefined function
vixalien d404423
use namespace as repository cache key
ahgilak acdb37c
Revert "use namespace as repository cache key"
vixalien b91d388
automatically load the latest version of a typelib
vixalien 61f9d0c
handle error when requiring namespaces
vixalien 5cc0e41
use BigUint64Array to store passed invoke errors
vixalien 2f170b4
throw generic message when a function invocation fails without a gerror
vixalien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not a good idea to use introspection inside deno_gi as it can lead to recursive dependency on it's self.
is it possible to do this with only using static bindings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's the best idea ever, but it's the best approach.
This is because the
GLib.Error
must be consistent with other instances ofGLib.Error
so that we can do instance checks like so:The above code would not work otherwise because
GLib.Error
would be a completely different instance fromerror
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay that makes sense