Skip to content
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

Inspect and iterate handles #200

Merged
merged 43 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"lsan_interface.h": "c",
"math.h": "c",
"stdbool.h": "c",
"emscripten.h": "c"
"emscripten.h": "c",
"quickjs-atom.h": "c"
},
"files.exclude": {
".yarn/releases/*": true
}
}
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.
Expand Down
58 changes: 35 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,9 @@ build variant of quickjs-emscripten, and also the [DEBUG_SYNC] build variant.
The debug sync build variant has extra instrumentation code for detecting memory
leaks.

The class [TestQuickJSWASMModule] exposes the memory leak detection API, although
this API is only accurate when using `DEBUG_SYNC` variant.
The class [TestQuickJSWASMModule] exposes the memory leak detection API,
although this API is only accurate when using `DEBUG_SYNC` variant. You can also
enable [debug logging](#debugging) to help diagnose failures.

```typescript
// Define your test suite in a function, so that you can test against
Expand Down Expand Up @@ -744,40 +745,51 @@ You can use quickjs-emscripten directly from an HTML file in two ways:

### Debugging

- Switch to a DEBUG build variant of the WebAssembly module to see debug log messages from the C part of this library:
Debug logging can be enabled globally, or for specific runtimes. You need to use a DEBUG build variant of the WebAssembly module to see debug log messages from the C part of this library.

```typescript
import { newQuickJSWASMModule, DEBUG_SYNC } from "quickjs-emscripten"
```typescript
import { newQuickJSWASMModule, DEBUG_SYNC } from "quickjs-emscripten"

const QuickJS = await newQuickJSWASMModule(DEBUG_SYNC)
```

With quickjs-emscripten-core:

const QuickJS = await newQuickJSWASMModule(DEBUG_SYNC)
```
```typescript
import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
import DEBUG_SYNC from "@jitl/quickjs-wasmfile-debug-sync"

const QuickJS = await newQuickJSWASMModuleFromVariant(DEBUG_SYNC)
```

With quickjs-emscripten-core:
To enable debug logging globally, call [setDebugMode][setDebugMode]. This affects global Javascript parts of the library, like the module loader and asyncify internals, and is inherited by runtimes created after the call.

```typescript
import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
import DEBUG_SYNC from "@jitl/quickjs-wasmfile-debug-sync"
```typescript
import { setDebugMode } from "quickjs-emscripten"

const QuickJS = await newQuickJSWASMModuleFromVariant(DEBUG_SYNC)
```
setDebugMode(true)
```

- Enable debug log messages from the Javascript part of this library with [setDebugMode][setDebugMode]:
With quickjs-emscripten-core:

```typescript
import { setDebugMode } from "quickjs-emscripten"
```typescript
import { setDebugMode } from "quickjs-emscripten-core"

setDebugMode(true)
```
setDebugMode(true)
```

With quickjs-emscripten-core:
To enable debug logging for a specific runtime, call [setDebugModeRt][setDebugModeRt]. This affects only the runtime and its associated contexts.

```typescript
import { setDebugMode } from "quickjs-emscripten-core"
```typescript
const runtime = QuickJS.newRuntime()
runtime.setDebugMode(true)

setDebugMode(true)
```
const context = QuickJS.newContext()
context.runtime.setDebugMode(true)
```

[setDebugMode]: doc/quickjs-emscripten/exports.md#setdebugmode
[setDebugModeRt]: https://github.com/justjake/quickjs-emscripten/blob/main/doc/quickjs-emscripten-core/classes/QuickJSRuntime.md#setdebugmode

### Supported Platforms

Expand Down
Loading
Loading