quickjs-emscripten
quickjs-emscripten copied to clipboard
Inspect and iterate handles
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 https://github.com/justjake/quickjs-emscripten/issues/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 readshandle.lengthand returns it as a number or undefined to make writingfor (i=0;i<length;i++)loops easier. - For iterable collections like Map, Set, Array: add
context.getIterator(handle)callshandle[Symbol.iterator]()and then exposes the result as anIterableIteratorto host javascript.
Usability improvements
- The
SuccessOrFail<T, QuickJSHandle>return type is largely replaced with a new return typeDisposableSuccess<T> | DisposableFail<QuickJSHandle>. The new type implementsresult.unwrap()as a replacement forcontext.unwrapResult(result). It also implementsdispose()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 likecontext.callMethod(handle, 'keys')orcontext.callMethod('values')which can be used with the new iterator.
Equality
- Added
context.eq(a, b),context.sameValue(a, b),context.sameValueZero(a, b)