Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Inspect and iterate handles #200

Merged
merged 43 commits into from
Aug 31, 2024
Merged

Inspect and iterate handles #200

merged 43 commits into from
Aug 31, 2024

Conversation

justjake
Copy link
Owner

@justjake justjake commented Aug 26, 2024

This PR is a large change aimed to make it easier to work values in the guest, primarily focused on reading guest objects and collections. There are also a major but hopefully non-breaking change to the SuccessOrFail result type returned by many operations

Collection & Iteration

Fixes #185

  • For objects and arrays: add context.getOwnPropertyNames(handle, options) to iterate the key or array index handles.
  • For arrays: add context.getLength(handle) which reads handle.length and returns it as a number or undefined to make writing for (i=0;i<length;i++) loops easier.
  • For iterable collections like Map, Set, Array: add context.getIterator(handle) calls handle[Symbol.iterator]() and then exposes the result as an IterableIterator to host javascript.

Usability improvements

  • The SuccessOrFail<T, QuickJSHandle> return type is largely replaced with a new return type DisposableSuccess<T> | DisposableFail<QuickJSHandle>. The new type implements result.unwrap() as a replacement for context.unwrapResult(result). It also implements dispose() directly, so you no longer need to distinguish between success and failure to clean up.
  • add context.callMethod(handle, 'methodName'), this makes it easier to call methods like context.callMethod(handle, 'keys') or context.callMethod('values') which can be used with the new iterator.

Equality

  • Added context.eq(a, b), context.sameValue(a, b), context.sameValueZero(a, b)

Debug logging changes

Debug logging is now disabled by default, even when using a DEBUG variant. It can be enabled on a runtime-by-runtime basis with runtime.setDebugMode(boolean) or context.runtime.setDebugMode(boolean), or globally using setDebugMode(boolean). As with before, you should use a DEBUG variant to see logs from the WebAssembly C code.

@justjake justjake force-pushed the jake--iterate-props branch from d1a95c6 to d0d5840 Compare August 31, 2024 17:55
@justjake justjake enabled auto-merge (squash) August 31, 2024 21:33
@justjake justjake merged commit 7d6814c into main Aug 31, 2024
1 check passed
@justjake justjake deleted the jake--iterate-props branch August 31, 2024 21:34
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: return property keys of a JSValue
1 participant