Skip to content

Commit

Permalink
Support providing and retrieving WebAssembly.Memory (#147)
Browse files Browse the repository at this point in the history
* Add imported memory Emscripten flag

* WASM memory

* access WASM memory

* docs?

* Polyfill Symbol.dispose

* remove internal use of "using" because it caused an issue

* update lifetime docs

* test variant memory

* doc

* rebase
  • Loading branch information
justjake authored Jan 24, 2024
1 parent 7832516 commit daa9da6
Show file tree
Hide file tree
Showing 117 changed files with 1,295 additions and 676 deletions.
2 changes: 1 addition & 1 deletion doc/@jitl/quickjs-ffi-types/exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ for the Emscripten stack.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:242](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L242)
[packages/quickjs-ffi-types/src/emscripten-types.ts:246](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L246)

***

Expand Down
59 changes: 38 additions & 21 deletions doc/@jitl/quickjs-ffi-types/interfaces/EmscriptenModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ QuickJS.
- [TOTAL\_MEMORY](EmscriptenModule.md#total-memory)
- [TOTAL\_STACK](EmscriptenModule.md#total-stack)
- [wasmBinary?](EmscriptenModule.md#wasmbinary)
- [wasmMemory?](EmscriptenModule.md#wasmmemory)
- [Methods](EmscriptenModule.md#methods)
- [UTF8ToString()](EmscriptenModule.md#utf8tostring)
- [\_free()](EmscriptenModule.md#free)
Expand All @@ -48,7 +49,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:164](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L164)
[packages/quickjs-ffi-types/src/emscripten-types.ts:168](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L168)

***

Expand All @@ -58,7 +59,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:154](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L154)
[packages/quickjs-ffi-types/src/emscripten-types.ts:158](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L158)

***

Expand All @@ -68,7 +69,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:155](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L155)
[packages/quickjs-ffi-types/src/emscripten-types.ts:159](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L159)

***

Expand All @@ -78,7 +79,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:153](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L153)
[packages/quickjs-ffi-types/src/emscripten-types.ts:157](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L157)

***

Expand All @@ -88,7 +89,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:159](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L159)
[packages/quickjs-ffi-types/src/emscripten-types.ts:163](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L163)

***

Expand All @@ -98,7 +99,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:160](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L160)
[packages/quickjs-ffi-types/src/emscripten-types.ts:164](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L164)

***

Expand All @@ -108,7 +109,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:157](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L157)
[packages/quickjs-ffi-types/src/emscripten-types.ts:161](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L161)

***

Expand All @@ -118,7 +119,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:158](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L158)
[packages/quickjs-ffi-types/src/emscripten-types.ts:162](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L162)

***

Expand All @@ -128,7 +129,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:156](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L156)
[packages/quickjs-ffi-types/src/emscripten-types.ts:160](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L160)

***

Expand All @@ -138,7 +139,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:163](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L163)
[packages/quickjs-ffi-types/src/emscripten-types.ts:167](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L167)

***

Expand All @@ -148,7 +149,7 @@ QuickJS.
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:162](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L162)
[packages/quickjs-ffi-types/src/emscripten-types.ts:166](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L166)

***

Expand All @@ -164,7 +165,23 @@ Compile this to WebAssembly.Module

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:103](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L103)
[packages/quickjs-ffi-types/src/emscripten-types.ts:104](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L104)

***

### wasmMemory?

> **wasmMemory**?: `Memory`
If provided, use this WebAssembly.Memory instead of an automatically created one.

#### Inherited from

[`@jitl/quickjs-ffi-types.EmscriptenModuleLoaderOptions.wasmMemory`](EmscriptenModuleLoaderOptions.md#wasmmemory)

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:107](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L107)

## Methods

Expand All @@ -187,7 +204,7 @@ https://emscripten.org/docs/api_reference/preamble.js.html#UTF8ToString

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:140](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L140)
[packages/quickjs-ffi-types/src/emscripten-types.ts:144](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L144)

***

Expand All @@ -205,7 +222,7 @@ https://emscripten.org/docs/api_reference/preamble.js.html#UTF8ToString

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:144](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L144)
[packages/quickjs-ffi-types/src/emscripten-types.ts:148](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L148)

***

Expand All @@ -223,7 +240,7 @@ https://emscripten.org/docs/api_reference/preamble.js.html#UTF8ToString

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:143](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L143)
[packages/quickjs-ffi-types/src/emscripten-types.ts:147](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L147)

***

Expand Down Expand Up @@ -256,7 +273,7 @@ https://emscripten.org/docs/api_reference/preamble.js.html#UTF8ToString
#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:145](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L145)
[packages/quickjs-ffi-types/src/emscripten-types.ts:149](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L149)

***

Expand All @@ -282,7 +299,7 @@ Create an instance of the WASM module, call onSuccess(instance), then return ins

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:106](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L106)
[packages/quickjs-ffi-types/src/emscripten-types.ts:110](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L110)

***

Expand All @@ -300,7 +317,7 @@ Create an instance of the WASM module, call onSuccess(instance), then return ins

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:141](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L141)
[packages/quickjs-ffi-types/src/emscripten-types.ts:145](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L145)

***

Expand Down Expand Up @@ -344,7 +361,7 @@ Often `''` (empty string)

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:96](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L96)
[packages/quickjs-ffi-types/src/emscripten-types.ts:97](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L97)

***

Expand All @@ -368,7 +385,7 @@ Called by emscripten as dependencies blocking initialization are added or fulfil

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:112](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L112)
[packages/quickjs-ffi-types/src/emscripten-types.ts:116](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L116)

***

Expand All @@ -393,7 +410,7 @@ https://emscripten.org/docs/api_reference/preamble.js.html#stringToUTF8

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:135](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L135)
[packages/quickjs-ffi-types/src/emscripten-types.ts:139](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L139)

***

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

## Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:245](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L245)
[packages/quickjs-ffi-types/src/emscripten-types.ts:249](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L249)

***

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ See [the Emscripten Module API reference](https://emscripten.org/docs/api_refere
- [Extended By](EmscriptenModuleLoaderOptions.md#extended-by)
- [Properties](EmscriptenModuleLoaderOptions.md#properties)
- [wasmBinary?](EmscriptenModuleLoaderOptions.md#wasmbinary)
- [wasmMemory?](EmscriptenModuleLoaderOptions.md#wasmmemory)
- [Methods](EmscriptenModuleLoaderOptions.md#methods)
- [instantiateWasm()?](EmscriptenModuleLoaderOptions.md#instantiatewasm)
- [locateFile()?](EmscriptenModuleLoaderOptions.md#locatefile)
Expand All @@ -34,7 +35,19 @@ Compile this to WebAssembly.Module

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:103](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L103)
[packages/quickjs-ffi-types/src/emscripten-types.ts:104](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L104)

***

### wasmMemory?

> **wasmMemory**?: `Memory`
If provided, use this WebAssembly.Memory instead of an automatically created one.

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:107](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L107)

## Methods

Expand All @@ -56,7 +69,7 @@ Create an instance of the WASM module, call onSuccess(instance), then return ins

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:106](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L106)
[packages/quickjs-ffi-types/src/emscripten-types.ts:110](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L110)

***

Expand Down Expand Up @@ -96,7 +109,7 @@ Often `''` (empty string)

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:96](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L96)
[packages/quickjs-ffi-types/src/emscripten-types.ts:97](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L97)

***

Expand All @@ -116,7 +129,7 @@ Called by emscripten as dependencies blocking initialization are added or fulfil

#### Source

[packages/quickjs-ffi-types/src/emscripten-types.ts:112](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L112)
[packages/quickjs-ffi-types/src/emscripten-types.ts:116](https://github.com/justjake/quickjs-emscripten/blob/main/packages/quickjs-ffi-types/src/emscripten-types.ts#L116)

***

Expand Down
Loading

0 comments on commit daa9da6

Please sign in to comment.