File: QuickJSAsyncRuntime.md

package info (click to toggle)
node-quickjs-emscripten 0.23.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,900 kB
  • sloc: ansic: 71,457; javascript: 7,638; makefile: 506; sh: 153
file content (408 lines) | stat: -rw-r--r-- 10,283 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
[quickjs-emscripten](../README.md) / [Exports](../modules.md) / QuickJSAsyncRuntime

# Class: QuickJSAsyncRuntime

## Hierarchy

- [`QuickJSRuntime`](QuickJSRuntime.md)

  ↳ **`QuickJSAsyncRuntime`**

## Table of contents

### Properties

- [context](QuickJSAsyncRuntime.md#context)

### Accessors

- [alive](QuickJSAsyncRuntime.md#alive)

### Methods

- [assertOwned](QuickJSAsyncRuntime.md#assertowned)
- [computeMemoryUsage](QuickJSAsyncRuntime.md#computememoryusage)
- [dispose](QuickJSAsyncRuntime.md#dispose)
- [dumpMemoryUsage](QuickJSAsyncRuntime.md#dumpmemoryusage)
- [executePendingJobs](QuickJSAsyncRuntime.md#executependingjobs)
- [hasPendingJob](QuickJSAsyncRuntime.md#haspendingjob)
- [newContext](QuickJSAsyncRuntime.md#newcontext)
- [removeInterruptHandler](QuickJSAsyncRuntime.md#removeinterrupthandler)
- [removeModuleLoader](QuickJSAsyncRuntime.md#removemoduleloader)
- [setInterruptHandler](QuickJSAsyncRuntime.md#setinterrupthandler)
- [setMaxStackSize](QuickJSAsyncRuntime.md#setmaxstacksize)
- [setMemoryLimit](QuickJSAsyncRuntime.md#setmemorylimit)
- [setModuleLoader](QuickJSAsyncRuntime.md#setmoduleloader)

## Properties

### context

• **context**: `undefined` \| [`QuickJSAsyncContext`](QuickJSAsyncContext.md)

If this runtime was created as as part of a context, points to the context
associated with the runtime.

If this runtime was created stand-alone, this may or may not contain a context.
A context here may be allocated if one is needed by the runtime, eg for [computeMemoryUsage](QuickJSAsyncRuntime.md#computememoryusage).

#### Overrides

[QuickJSRuntime](QuickJSRuntime.md).[context](QuickJSRuntime.md#context)

#### Defined in

[ts/runtime-asyncify.ts:19](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime-asyncify.ts#L19)

## Accessors

### alive

• `get` **alive**(): `boolean`

#### Returns

`boolean`

#### Inherited from

QuickJSRuntime.alive

#### Defined in

[ts/runtime.ts:126](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L126)

## Methods

### assertOwned

▸ **assertOwned**(`handle`): `void`

Assert that `handle` is owned by this runtime.

**`throws`** QuickJSWrongOwner if owned by a different runtime.

#### Parameters

| Name | Type |
| :------ | :------ |
| `handle` | [`QuickJSHandle`](../modules.md#quickjshandle) |

#### Returns

`void`

#### Inherited from

[QuickJSRuntime](QuickJSRuntime.md).[assertOwned](QuickJSRuntime.md#assertowned)

#### Defined in

[ts/runtime.ts:326](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L326)

___

### computeMemoryUsage

▸ **computeMemoryUsage**(): [`QuickJSHandle`](../modules.md#quickjshandle)

Compute memory usage for this runtime. Returns the result as a handle to a
JSValue object. Use [QuickJSContext.dump](QuickJSContext.md#dump) to convert to a native object.
Calling this method will allocate more memory inside the runtime. The information
is accurate as of just before the call to `computeMemoryUsage`.
For a human-digestible representation, see [dumpMemoryUsage](QuickJSAsyncRuntime.md#dumpmemoryusage).

#### Returns

[`QuickJSHandle`](../modules.md#quickjshandle)

#### Inherited from

[QuickJSRuntime](QuickJSRuntime.md).[computeMemoryUsage](QuickJSRuntime.md#computememoryusage)

#### Defined in

[ts/runtime.ts:295](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L295)

___

### dispose

▸ **dispose**(): `void`

Dispose of the underlying resources used by this object.

#### Returns

`void`

#### Inherited from

[QuickJSRuntime](QuickJSRuntime.md).[dispose](QuickJSRuntime.md#dispose)

#### Defined in

[ts/runtime.ts:130](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L130)

___

### dumpMemoryUsage

▸ **dumpMemoryUsage**(): `string`

#### Returns

`string`

a human-readable description of memory usage in this runtime.
For programmatic access to this information, see [computeMemoryUsage](QuickJSAsyncRuntime.md#computememoryusage).

#### Inherited from

[QuickJSRuntime](QuickJSRuntime.md).[dumpMemoryUsage](QuickJSRuntime.md#dumpmemoryusage)

#### Defined in

[ts/runtime.ts:306](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L306)

___

### executePendingJobs

▸ **executePendingJobs**(`maxJobsToExecute?`): [`ExecutePendingJobsResult`](../modules.md#executependingjobsresult)

Execute pendingJobs on the runtime until `maxJobsToExecute` jobs are
executed (default all pendingJobs), the queue is exhausted, or the runtime
encounters an exception.

In QuickJS, promises and async functions *inside the runtime* create
pendingJobs. These do not execute immediately and need to triggered to run.

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `maxJobsToExecute` | `number` \| `void` | `-1` | When negative, run all pending jobs. Otherwise execute at most `maxJobsToExecute` before returning. |

#### Returns

[`ExecutePendingJobsResult`](../modules.md#executependingjobsresult)

On success, the number of executed jobs. On error, the exception
that stopped execution, and the context it occurred in. Note that
executePendingJobs will not normally return errors thrown inside async
functions or rejected promises. Those errors are available by calling
[resolvePromise](QuickJSContext.md#resolvepromise) on the promise handle returned by the async function.

#### Inherited from

[QuickJSRuntime](QuickJSRuntime.md).[executePendingJobs](QuickJSRuntime.md#executependingjobs)

#### Defined in

[ts/runtime.ts:240](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L240)

___

### hasPendingJob

▸ **hasPendingJob**(): `boolean`

In QuickJS, promises and async functions create pendingJobs. These do not execute
immediately and need to be run by calling [executePendingJobs](QuickJSAsyncRuntime.md#executependingjobs).

#### Returns

`boolean`

true if there is at least one pendingJob queued up.

#### Inherited from

[QuickJSRuntime](QuickJSRuntime.md).[hasPendingJob](QuickJSRuntime.md#haspendingjob)

#### Defined in

[ts/runtime.ts:191](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L191)

___

### newContext

▸ **newContext**(`options?`): [`QuickJSAsyncContext`](QuickJSAsyncContext.md)

#### Parameters

| Name | Type |
| :------ | :------ |
| `options` | [`ContextOptions`](../interfaces/ContextOptions.md) |

#### Returns

[`QuickJSAsyncContext`](QuickJSAsyncContext.md)

#### Overrides

[QuickJSRuntime](QuickJSRuntime.md).[newContext](QuickJSRuntime.md#newcontext)

#### Defined in

[ts/runtime-asyncify.ts:42](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime-asyncify.ts#L42)

___

### removeInterruptHandler

▸ **removeInterruptHandler**(): `void`

Remove the interrupt handler, if any.
See [setInterruptHandler](QuickJSAsyncRuntime.md#setinterrupthandler).

#### Returns

`void`

#### Inherited from

[QuickJSRuntime](QuickJSRuntime.md).[removeInterruptHandler](QuickJSRuntime.md#removeinterrupthandler)

#### Defined in

[ts/runtime.ts:216](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L216)

___

### removeModuleLoader

▸ **removeModuleLoader**(): `void`

Remove the the loader set by [setModuleLoader](QuickJSAsyncRuntime.md#setmoduleloader). This disables module loading.

#### Returns

`void`

#### Inherited from

[QuickJSRuntime](QuickJSRuntime.md).[removeModuleLoader](QuickJSRuntime.md#removemoduleloader)

#### Defined in

[ts/runtime.ts:178](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L178)

___

### setInterruptHandler

▸ **setInterruptHandler**(`cb`): `void`

Set a callback which is regularly called by the QuickJS engine when it is
executing code. This callback can be used to implement an execution
timeout.

The interrupt handler can be removed with [removeInterruptHandler](QuickJSAsyncRuntime.md#removeinterrupthandler).

#### Parameters

| Name | Type |
| :------ | :------ |
| `cb` | [`InterruptHandler`](../modules.md#interrupthandler) |

#### Returns

`void`

#### Inherited from

[QuickJSRuntime](QuickJSRuntime.md).[setInterruptHandler](QuickJSRuntime.md#setinterrupthandler)

#### Defined in

[ts/runtime.ts:204](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L204)

___

### setMaxStackSize

▸ **setMaxStackSize**(`stackSize`): `void`

Set the max stack size for this runtime in bytes.
To remove the limit, set to `0`.

Setting this limit also adjusts the global `ASYNCIFY_STACK_SIZE` for the entire [QuickJSAsyncWASMModule](QuickJSAsyncWASMModule.md).
See the [pull request](https://github.com/justjake/quickjs-emscripten/pull/114) for more details.

#### Parameters

| Name | Type |
| :------ | :------ |
| `stackSize` | `number` |

#### Returns

`void`

#### Overrides

[QuickJSRuntime](QuickJSRuntime.md).[setMaxStackSize](QuickJSRuntime.md#setmaxstacksize)

#### Defined in

[ts/runtime-asyncify.ts:84](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime-asyncify.ts#L84)

___

### setMemoryLimit

▸ **setMemoryLimit**(`limitBytes`): `void`

Set the max memory this runtime can allocate.
To remove the limit, set to `-1`.

#### Parameters

| Name | Type |
| :------ | :------ |
| `limitBytes` | `number` |

#### Returns

`void`

#### Inherited from

[QuickJSRuntime](QuickJSRuntime.md).[setMemoryLimit](QuickJSRuntime.md#setmemorylimit)

#### Defined in

[ts/runtime.ts:280](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime.ts#L280)

___

### setModuleLoader

▸ **setModuleLoader**(`moduleLoader`, `moduleNormalizer?`): `void`

Set the loader for EcmaScript modules requested by any context in this
runtime.

The loader can be removed with [removeModuleLoader](QuickJSAsyncRuntime.md#removemoduleloader).

#### Parameters

| Name | Type |
| :------ | :------ |
| `moduleLoader` | [`JSModuleLoaderAsync`](../interfaces/JSModuleLoaderAsync.md) |
| `moduleNormalizer?` | [`JSModuleNormalizerAsync`](../interfaces/JSModuleNormalizerAsync.md) |

#### Returns

`void`

#### Overrides

[QuickJSRuntime](QuickJSRuntime.md).[setModuleLoader](QuickJSRuntime.md#setmoduleloader)

#### Defined in

[ts/runtime-asyncify.ts:67](https://github.com/justjake/quickjs-emscripten/blob/main/ts/runtime-asyncify.ts#L67)