Skip to content

Commit 7d6814c

Browse files
authored
Inspect and iterate handles (#200)
* getOwnPropertyNames flags * getLength * getPropNames, QuicJSIterator * isEqual * wip codegen * DisposableResult * fix new ffi typings * wip * upgrade emcc * iterate on build * regen * new doc * adjust DisposableResult impl and union * fix types more * getPropNames passing * getPropNames -> getOwnPropertyNames * Iterator -> IterableIterator * improve getOwnPropertyNames docs * improve iteration docs and add defaults to getOwnPropertyNames * add callMethod convinience function * add callFunction example * enable debug logging per runtime * regen * docs for debug mode changes * debug log improvement * runtime data func not callable from js * regen * fix build issue * gen doc * doc * for some reason lockfile changed * test: turn on debug mode via env var * fix test leak * changelog, naming adjustments * fix type rename error * fix node test build * tweak to ensure path stuff doesnt affect build * restore previous build tsconfig * disable asyncify-advise, its just really spammy * derp naming * stuff * [[ -> [ for docker build * lint
1 parent 87b3e5d commit 7d6814c

File tree

188 files changed

+9392
-2242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+9392
-2242
lines changed

.vscode/settings.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"lsan_interface.h": "c",
99
"math.h": "c",
1010
"stdbool.h": "c",
11-
"emscripten.h": "c"
11+
"emscripten.h": "c",
12+
"quickjs-atom.h": "c"
13+
},
14+
"files.exclude": {
15+
".yarn/releases/*": true
1216
}
1317
}

CHANGELOG.md

+28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# Changelog
22

3+
## v0.30.0
4+
5+
- [#200](https://github.com/justjake/quickjs-emscripten/pull/200) Inspect and iterate handles, equality, changes to result types, changes to debug logging.
6+
- [#195](https://github.com/justjake/quickjs-emscripten/pull/195) Export `setDebugMode`
7+
8+
### Collection & Iteration
9+
10+
- For objects and arrays: add `context.getOwnPropertyNames(handle, options)` to iterate the key or array index handles.
11+
- 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.
12+
- 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.
13+
14+
### Usability improvements
15+
16+
- 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.
17+
- 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.
18+
19+
### Equality
20+
21+
- Added `context.eq(a, b)`, `context.sameValue(a, b)`, `context.sameValueZero(a, b)`
22+
23+
### Debug logging changes
24+
25+
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.
26+
27+
## v0.29.2
28+
29+
- [#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.
30+
331
## v0.29.1
432

533
- [#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.

README.md

+35-23
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,9 @@ build variant of quickjs-emscripten, and also the [DEBUG_SYNC] build variant.
561561
The debug sync build variant has extra instrumentation code for detecting memory
562562
leaks.
563563

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

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

745746
### Debugging
746747

747-
- Switch to a DEBUG build variant of the WebAssembly module to see debug log messages from the C part of this library:
748+
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.
748749

749-
```typescript
750-
import { newQuickJSWASMModule, DEBUG_SYNC } from "quickjs-emscripten"
750+
```typescript
751+
import { newQuickJSWASMModule, DEBUG_SYNC } from "quickjs-emscripten"
752+
753+
const QuickJS = await newQuickJSWASMModule(DEBUG_SYNC)
754+
```
755+
756+
With quickjs-emscripten-core:
751757

752-
const QuickJS = await newQuickJSWASMModule(DEBUG_SYNC)
753-
```
758+
```typescript
759+
import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
760+
import DEBUG_SYNC from "@jitl/quickjs-wasmfile-debug-sync"
761+
762+
const QuickJS = await newQuickJSWASMModuleFromVariant(DEBUG_SYNC)
763+
```
754764

755-
With quickjs-emscripten-core:
765+
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.
756766

757-
```typescript
758-
import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
759-
import DEBUG_SYNC from "@jitl/quickjs-wasmfile-debug-sync"
767+
```typescript
768+
import { setDebugMode } from "quickjs-emscripten"
760769

761-
const QuickJS = await newQuickJSWASMModuleFromVariant(DEBUG_SYNC)
762-
```
770+
setDebugMode(true)
771+
```
763772

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

766-
```typescript
767-
import { setDebugMode } from "quickjs-emscripten"
775+
```typescript
776+
import { setDebugMode } from "quickjs-emscripten-core"
768777

769-
setDebugMode(true)
770-
```
778+
setDebugMode(true)
779+
```
771780

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

774-
```typescript
775-
import { setDebugMode } from "quickjs-emscripten-core"
783+
```typescript
784+
const runtime = QuickJS.newRuntime()
785+
runtime.setDebugMode(true)
776786

777-
setDebugMode(true)
778-
```
787+
const context = QuickJS.newContext()
788+
context.runtime.setDebugMode(true)
789+
```
779790

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

782794
### Supported Platforms
783795

0 commit comments

Comments
 (0)