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
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cdc73d0
getOwnPropertyNames flags
justjake Aug 25, 2024
9bec8c7
getLength
justjake Aug 25, 2024
76c28ab
getPropNames, QuicJSIterator
justjake Aug 25, 2024
b6d01ba
isEqual
justjake Aug 25, 2024
b2a0af5
wip codegen
justjake Aug 25, 2024
6d264b8
DisposableResult
justjake Aug 25, 2024
00efed4
fix new ffi typings
justjake Aug 25, 2024
a59c735
wip
justjake Aug 25, 2024
7820830
upgrade emcc
justjake Aug 25, 2024
cb29b27
iterate on build
justjake Aug 25, 2024
0fa9174
regen
justjake Aug 25, 2024
e1cb8b6
new doc
justjake Aug 25, 2024
3cf1e39
adjust DisposableResult impl and union
justjake Aug 25, 2024
0cd9531
fix types more
justjake Aug 25, 2024
382448e
getPropNames passing
justjake Aug 26, 2024
310f072
getPropNames -> getOwnPropertyNames
justjake Aug 26, 2024
481f178
Iterator -> IterableIterator
justjake Aug 26, 2024
2b9369d
improve getOwnPropertyNames docs
justjake Aug 26, 2024
28f8688
improve iteration docs and add defaults to getOwnPropertyNames
justjake Aug 26, 2024
ff7a4c3
add callMethod convinience function
justjake Aug 26, 2024
c6270f3
add callFunction example
justjake Aug 26, 2024
f7c3691
enable debug logging per runtime
justjake Aug 31, 2024
ac63996
regen
justjake Aug 31, 2024
420555a
docs for debug mode changes
justjake Aug 31, 2024
9c5ae6c
debug log improvement
justjake Aug 31, 2024
1b0657a
runtime data func not callable from js
justjake Aug 31, 2024
37b0d85
regen
justjake Aug 31, 2024
7b128b2
fix build issue
justjake Aug 31, 2024
0106a86
gen doc
justjake Aug 31, 2024
f53f1c3
doc
justjake Aug 31, 2024
d0d5840
for some reason lockfile changed
justjake Aug 31, 2024
9d80b4d
test: turn on debug mode via env var
justjake Aug 31, 2024
0bd818b
fix test leak
justjake Aug 31, 2024
69bc3d9
changelog, naming adjustments
justjake Aug 31, 2024
5504852
fix type rename error
justjake Aug 31, 2024
33b870e
fix node test build
justjake Aug 31, 2024
80e107c
tweak to ensure path stuff doesnt affect build
justjake Aug 31, 2024
31aa729
restore previous build tsconfig
justjake Aug 31, 2024
2af655d
disable asyncify-advise, its just really spammy
justjake Aug 31, 2024
9652df4
derp naming
justjake Aug 31, 2024
6f71942
stuff
justjake Aug 31, 2024
06a83bf
[[ -> [ for docker build
justjake Aug 31, 2024
a6ca6f4
lint
justjake Aug 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
changelog, naming adjustments
  • Loading branch information
justjake committed Aug 31, 2024
commit 69bc3d9ee060742dd14f99acc4eacfe891ba8dcc
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog

## v0.30.0

- [#200](https://github.com/justjake/quickjs-emscripten/pull/200) Inspect and iterate handles, equality, changes to result types, changes to debug logging.
- [#195](https://github.com/justjake/quickjs-emscripten/pull/195) Export `setDebugMode`

### Collection & Iteration

- 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.

## v0.29.2

- [#179](https://github.com/justjake/quickjs-emscripten/pull/161) Add a work-around for a bug in Webkit ARM to quickjs build variants. quickjs-ng is still affected by this bug.

## v0.29.1

- [#161](https://github.com/justjake/quickjs-emscripten/pull/161) Fix a bug where `context.evalCode(..., { type: 'module' })` would return success when some kinds of error occurred when using `quickjs` variants.
4 changes: 2 additions & 2 deletions packages/quickjs-emscripten-core/src/context-asyncify.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import type {
JSRuntimePointer,
JSValuePointer,
} from "@jitl/quickjs-ffi-types"
import type { ContextResult } from "./context"
import type { QuickJSContextResult } from "./context"
import { QuickJSContext } from "./context"
import type { Lifetime } from "./lifetime"
import type { QuickJSModuleCallbacks } from "./module"
@@ -46,7 +46,7 @@ export class QuickJSAsyncContext extends QuickJSContext {
filename: string = "eval.js",
/** See {@link EvalFlags} for number semantics */
options?: number | ContextEvalOptions,
): Promise<ContextResult<QuickJSHandle>> {
): Promise<QuickJSContextResult<QuickJSHandle>> {
const detectModule = (options === undefined ? 1 : 0) as EvalDetectModule
const flags = evalOptionsToFlags(options) as EvalFlags
let resultPtr = 0 as JSValuePointer
20 changes: 10 additions & 10 deletions packages/quickjs-emscripten-core/src/context.ts
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ import type {
} from "./vm-interface"
import { QuickJSIterator } from "./QuickJSIterator"

export type ContextResult<S> = DisposableResult<S, QuickJSHandle>
export type QuickJSContextResult<S> = DisposableResult<S, QuickJSHandle>

/**
* Property key for getting or setting a property on a handle with
@@ -752,7 +752,7 @@ export class QuickJSContext
*
* @param promiseLikeHandle - A handle to a Promise-like value with a `.then(onSuccess, onError)` method.
*/
resolvePromise(promiseLikeHandle: QuickJSHandle): Promise<ContextResult<QuickJSHandle>> {
resolvePromise(promiseLikeHandle: QuickJSHandle): Promise<QuickJSContextResult<QuickJSHandle>> {
this.runtime.assertOwned(promiseLikeHandle)
const vmResolveResult = Scope.withScope((scope) => {
const vmPromise = scope.manage(this.getProp(this.global, "Promise"))
@@ -763,7 +763,7 @@ export class QuickJSContext
return Promise.resolve(vmResolveResult)
}

return new Promise<ContextResult<QuickJSHandle>>((resolve) => {
return new Promise<QuickJSContextResult<QuickJSHandle>>((resolve) => {
Scope.withScope((scope) => {
const resolveHandle = scope.manage(
this.newFunction("resolve", (value) => {
@@ -911,7 +911,7 @@ export class QuickJSContext
strings: true,
numbersAsStrings: true,
},
): ContextResult<DisposableArray<QuickJSHandle>> {
): QuickJSContextResult<DisposableArray<QuickJSHandle>> {
this.runtime.assertOwned(handle)
handle.value // assert alive
const flags = getOwnPropertyNamesOptionsToFlags(options)
@@ -958,7 +958,7 @@ export class QuickJSContext
* }
* ```
*/
getIterator(iterableHandle: QuickJSHandle): ContextResult<QuickJSIterator> {
getIterator(iterableHandle: QuickJSHandle): QuickJSContextResult<QuickJSIterator> {
const SymbolIterator = (this._SymbolIterator ??= this.memory.manage(
this.getWellKnownSymbol("iterator"),
))
@@ -1061,17 +1061,17 @@ export class QuickJSContext
func: QuickJSHandle,
thisVal: QuickJSHandle,
args?: QuickJSHandle[],
): ContextResult<QuickJSHandle>
): QuickJSContextResult<QuickJSHandle>
callFunction(
func: QuickJSHandle,
thisVal: QuickJSHandle,
...args: QuickJSHandle[]
): ContextResult<QuickJSHandle>
): QuickJSContextResult<QuickJSHandle>
callFunction(
func: QuickJSHandle,
thisVal: QuickJSHandle,
...restArgs: Array<QuickJSHandle | QuickJSHandle[] | undefined>
): ContextResult<QuickJSHandle> {
): QuickJSContextResult<QuickJSHandle> {
this.runtime.assertOwned(func)
let args
const firstArg = restArgs[0]
@@ -1115,7 +1115,7 @@ export class QuickJSContext
thisHandle: QuickJSHandle,
key: QuickJSPropertyKey,
args: QuickJSHandle[] = [],
): ContextResult<QuickJSHandle> {
): QuickJSContextResult<QuickJSHandle> {
return this.getProp(thisHandle, key).consume((func) =>
this.callFunction(func, thisHandle, args),
)
@@ -1164,7 +1164,7 @@ export class QuickJSContext
* See {@link EvalFlags} for number semantics.
*/
options?: number | ContextEvalOptions,
): ContextResult<QuickJSHandle> {
): QuickJSContextResult<QuickJSHandle> {
const detectModule = (options === undefined ? 1 : 0) as EvalDetectModule
const flags = evalOptionsToFlags(options) as EvalFlags
const resultPtr = this.memory