quickjs-emscripten-sync 1.3.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -37
- package/dist/index.d.ts +29 -22
- package/dist/quickjs-emscripten-sync.mjs +842 -0
- package/dist/quickjs-emscripten-sync.umd.js +15 -15
- package/package.json +12 -21
- package/src/default.ts +2 -2
- package/src/index.test.ts +159 -65
- package/src/index.ts +67 -66
- package/src/marshal/custom.test.ts +50 -0
- package/src/marshal/custom.ts +36 -0
- package/src/marshal/function.test.ts +60 -72
- package/src/marshal/function.ts +15 -18
- package/src/marshal/index.test.ts +88 -84
- package/src/marshal/index.ts +16 -18
- package/src/marshal/json.test.ts +32 -38
- package/src/marshal/json.ts +5 -7
- package/src/marshal/object.test.ts +52 -79
- package/src/marshal/object.ts +8 -15
- package/src/marshal/primitive.test.ts +16 -21
- package/src/marshal/primitive.ts +11 -10
- package/src/marshal/promise.test.ts +21 -22
- package/src/marshal/promise.ts +6 -13
- package/src/marshal/properties.test.ts +21 -26
- package/src/marshal/properties.ts +15 -17
- package/src/unmarshal/custom.test.ts +50 -0
- package/src/unmarshal/custom.ts +31 -0
- package/src/unmarshal/function.test.ts +52 -74
- package/src/unmarshal/function.ts +13 -22
- package/src/unmarshal/index.test.ts +58 -50
- package/src/unmarshal/index.ts +12 -13
- package/src/unmarshal/object.test.ts +37 -43
- package/src/unmarshal/object.ts +16 -20
- package/src/unmarshal/primitive.test.ts +15 -15
- package/src/unmarshal/primitive.ts +11 -18
- package/src/unmarshal/promise.test.ts +13 -13
- package/src/unmarshal/promise.ts +10 -19
- package/src/unmarshal/properties.test.ts +8 -8
- package/src/unmarshal/properties.ts +44 -45
- package/src/util.test.ts +2 -7
- package/src/util.ts +3 -8
- package/src/vmmap.test.ts +72 -88
- package/src/vmmap.ts +26 -44
- package/src/vmutil.test.ts +73 -89
- package/src/vmutil.ts +24 -47
- package/src/wrapper.test.ts +108 -148
- package/src/wrapper.ts +59 -62
- package/dist/quickjs-emscripten-sync.es.js +0 -951
- package/src/marshal/symbol.test.ts +0 -24
- package/src/marshal/symbol.ts +0 -20
- package/src/unmarshal/symbol.test.ts +0 -25
- package/src/unmarshal/symbol.ts +0 -12
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ This library wraps [quickjs-emscripten](https://github.com/justjake/quickjs-emsc
|
|
|
12
12
|
- Functions
|
|
13
13
|
- Classes and instances
|
|
14
14
|
- Objects with prototypes and any property descriptors
|
|
15
|
+
- Promises
|
|
15
16
|
- Expose objects as a global object in QuickJS
|
|
16
17
|
- Marshaling limitation for specific objects
|
|
17
18
|
- Register a pair of objects that will be considered the same between the browser and QuickJS
|
|
@@ -32,10 +33,10 @@ class Cls {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
const
|
|
36
|
-
const arena = new Arena(
|
|
36
|
+
const ctx = (await getQuickJS()).newContext();
|
|
37
|
+
const arena = new Arena(ctx, { isMarshalable: true });
|
|
37
38
|
|
|
38
|
-
// We can pass objects to the
|
|
39
|
+
// We can pass objects to the context and run code safely
|
|
39
40
|
const exposed = {
|
|
40
41
|
Cls,
|
|
41
42
|
cls: new Cls(),
|
|
@@ -48,12 +49,12 @@ arena.evalCode(`cls.field`); // returns 0
|
|
|
48
49
|
arena.evalCode(`cls.method()`); // returns 1
|
|
49
50
|
arena.evalCode(`cls.field`); // returns 1
|
|
50
51
|
|
|
51
|
-
arena.evalCode(`syncedCls.field`);
|
|
52
|
-
exposed.syncedCls.method();
|
|
53
|
-
arena.evalCode(`syncedCls.field`);
|
|
52
|
+
arena.evalCode(`syncedCls.field`); // returns 0
|
|
53
|
+
exposed.syncedCls.method(); // returns 1
|
|
54
|
+
arena.evalCode(`syncedCls.field`); // returns 1
|
|
54
55
|
|
|
55
56
|
arena.dispose();
|
|
56
|
-
|
|
57
|
+
ctx.dispose();
|
|
57
58
|
```
|
|
58
59
|
|
|
59
60
|
[Example code](src/index.test.ts) is available as the unit test code.
|
|
@@ -72,15 +73,14 @@ import { getQuickJS } from "quickjs-emscripten";
|
|
|
72
73
|
import { Arena } from "quickjs-emscripten-sync";
|
|
73
74
|
|
|
74
75
|
(async function() {
|
|
75
|
-
const
|
|
76
|
-
const vm = quickjs.createVm();
|
|
76
|
+
const ctx = (await getQuickJS()).newContext();
|
|
77
77
|
|
|
78
78
|
// init Arena
|
|
79
79
|
// ⚠️ Marshaling is opt-in for security reasons.
|
|
80
80
|
// ⚠️ Be careful when activating marshalling.
|
|
81
|
-
const arena = new Arena(
|
|
81
|
+
const arena = new Arena(ctx, { isMarshalable: true });
|
|
82
82
|
|
|
83
|
-
// expose objects as global objects in QuickJS
|
|
83
|
+
// expose objects as global objects in QuickJS context
|
|
84
84
|
arena.expose({
|
|
85
85
|
console: {
|
|
86
86
|
log: console.log
|
|
@@ -99,15 +99,15 @@ import { Arena } from "quickjs-emscripten-sync";
|
|
|
99
99
|
data.hoge = "changed!";
|
|
100
100
|
console.log(arena.evalCode(`data.hoge`)); // "changed!"
|
|
101
101
|
|
|
102
|
-
// Don't forget calling arena.dispose() before disposing QuickJS
|
|
102
|
+
// Don't forget calling arena.dispose() before disposing QuickJS context!
|
|
103
103
|
arena.dispose();
|
|
104
|
-
|
|
104
|
+
ctx.dispose();
|
|
105
105
|
})();
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
## Marshaling Limitations
|
|
109
109
|
|
|
110
|
-
Objects are automatically converted when they cross between the host and the QuickJS
|
|
110
|
+
Objects are automatically converted when they cross between the host and the QuickJS context. The conversion of a host's object to a handle is called marshaling, and the conversion of a handle to a host's object is called unmarshaling.
|
|
111
111
|
|
|
112
112
|
And for marshalling, it is possible to control whether the conversion is performed or not.
|
|
113
113
|
|
|
@@ -116,7 +116,7 @@ For example, exposing the host's global object to QuickJS is very heavy and dang
|
|
|
116
116
|
```js
|
|
117
117
|
import { Arena, complexity } from "quickjs-emscripten-sync";
|
|
118
118
|
|
|
119
|
-
const arena = new Arena(
|
|
119
|
+
const arena = new Arena(ctx, {
|
|
120
120
|
isMarshalable: (target: any) => {
|
|
121
121
|
// prevent passing globalThis to QuickJS
|
|
122
122
|
if (target === window) return false;
|
|
@@ -183,32 +183,55 @@ By default, quickjs-emscripten-sync doesn't prevent any marshaling, even in such
|
|
|
183
183
|
|
|
184
184
|
### `Arena`
|
|
185
185
|
|
|
186
|
-
The Arena class manages all generated handles at once by quickjs-emscripten and automatically converts objects between the host and the QuickJS
|
|
186
|
+
The Arena class manages all generated handles at once by quickjs-emscripten and automatically converts objects between the host and the QuickJS context.
|
|
187
187
|
|
|
188
|
-
#### `new Arena(
|
|
188
|
+
#### `new Arena(ctx: QuickJSContext, options?: Options)`
|
|
189
189
|
|
|
190
|
-
Constructs a new Arena instance. It requires a quickjs-emscripten
|
|
190
|
+
Constructs a new Arena instance. It requires a quickjs-emscripten context initialized with `quickjs.newContext()`.
|
|
191
191
|
|
|
192
192
|
Options accepted:
|
|
193
193
|
|
|
194
194
|
```ts
|
|
195
195
|
type Options = {
|
|
196
|
+
/** A callback that returns a boolean value that determines whether an object is marshalled or not. If false, no marshaling will be done and undefined will be passed to the QuickJS VM, otherwise marshaling will be done. By default, all objects will be marshalled. */
|
|
196
197
|
isMarshalable?: boolean | "json" | ((target: any) => boolean | "json");
|
|
198
|
+
/** Pre-registered pairs of objects that will be considered the same between the host and the QuickJS VM. This will be used automatically during the conversion. By default, it will be registered automatically with `defaultRegisteredObjects`.
|
|
199
|
+
*
|
|
200
|
+
* Instead of a string, you can also pass a QuickJSHandle directly. In that case, however, you have to dispose of them manually when destroying the VM.
|
|
201
|
+
*/
|
|
197
202
|
registeredObjects?: Iterable<[any, QuickJSHandle | string]>;
|
|
203
|
+
/** Register functions to convert an object to a QuickJS handle. */
|
|
204
|
+
customMarshaller?: Iterable<
|
|
205
|
+
(target: unknown, ctx: QuickJSContext) => QuickJSHandle | undefined
|
|
206
|
+
>;
|
|
207
|
+
/** Register functions to convert a QuickJS handle to an object. */
|
|
208
|
+
customUnmarshaller?: Iterable<
|
|
209
|
+
(target: QuickJSHandle, ctx: QuickJSContext) => any
|
|
210
|
+
>;
|
|
211
|
+
/** A callback that returns a boolean value that determines whether an object is wrappable by proxies. If returns false, note that the object cannot be synchronized between the host and the QuickJS even if arena.sync is used. */
|
|
212
|
+
isWrappable?: (target: any) => boolean;
|
|
213
|
+
/** A callback that returns a boolean value that determines whether an QuickJS handle is wrappable by proxies. If returns false, note that the handle cannot be synchronized between the host and the QuickJS even if arena.sync is used. */
|
|
214
|
+
isHandleWrappable?: (handle: QuickJSHandle, ctx: QuickJSContext) => boolean;
|
|
215
|
+
/** Compatibility with quickjs-emscripten prior to v0.15. Inject code for compatibility into context at Arena class initialization time. */
|
|
216
|
+
compat?: boolean;
|
|
198
217
|
}
|
|
199
218
|
```
|
|
200
219
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
220
|
+
Notes:
|
|
221
|
+
|
|
222
|
+
**`isMarshalable`**: Determines how marshalling will be done when sending objects from the host to the context. **Make sure to set the marshalling to be the minimum necessary as it may reduce the security of your application.** [Please read the section on security above.](#security-warning)
|
|
223
|
+
|
|
224
|
+
- `"json"` (**default**, safety): Target object will be serialized as JSON in host and then parsed in context. Functions and classes will be lost in the process.
|
|
225
|
+
- `false` (safety): Target object will not be always marshalled as `undefined`.
|
|
226
|
+
- `(target: any) => boolean | "json"` (recoomended): You can control marshalling mode for each objects. If you want to do marshalling, usually use this method. Allow partial marshalling by returning `true` only for some objects.
|
|
227
|
+
- `true` (**risky and not recommended**): Target object will be always marshaled. This setting may reduce security.
|
|
228
|
+
|
|
229
|
+
**`registeredObjects`**: You can pre-register a pair of objects that will be considered the same between the host and the QuickJS context. This will be used automatically during the conversion. By default, it will be registered automatically with [`defaultRegisteredObjects`](src/default.ts). If you want to add a new pair to this, please do the following:
|
|
207
230
|
|
|
208
231
|
```js
|
|
209
232
|
import { defaultRegisteredObjects } from "quickjs-emscripten-sync";
|
|
210
233
|
|
|
211
|
-
const arena = new Arena(
|
|
234
|
+
const arena = new Arena(ctx, {
|
|
212
235
|
registeredObjects: [
|
|
213
236
|
...defaultRegisteredObjects,
|
|
214
237
|
[Math, "Math"]
|
|
@@ -216,36 +239,36 @@ const arena = new Arena(vm, {
|
|
|
216
239
|
});
|
|
217
240
|
```
|
|
218
241
|
|
|
219
|
-
Instead of a string, you can also pass a QuickJSHandle directly. In that case, however, you have to dispose of them manually when destroying the
|
|
242
|
+
Instead of a string, you can also pass a QuickJSHandle directly. In that case, however, you have to dispose of them manually when destroying the context.
|
|
220
243
|
|
|
221
244
|
#### `dispose()`
|
|
222
245
|
|
|
223
|
-
Dispose of the arena and managed handles. This method won't dispose the
|
|
246
|
+
Dispose of the arena and managed handles. This method won't dispose the context itself, so the context has to be disposed of manually.
|
|
224
247
|
|
|
225
248
|
#### `evalCode<T = any>(code: string): T | undefined`
|
|
226
249
|
|
|
227
|
-
Evaluate JS code in the
|
|
250
|
+
Evaluate JS code in the context and get the result as an object on the host side. It also converts and re-throws error objects when an error is thrown during evaluation.
|
|
228
251
|
|
|
229
252
|
#### `executePendingJobs(): number`
|
|
230
253
|
|
|
231
|
-
Almost same as `
|
|
254
|
+
Almost same as `ctx.runtime.executePendingJobs()`, but it converts and re-throws error objects when an error is thrown during evaluation.
|
|
232
255
|
|
|
233
256
|
#### `expose(obj: { [k: string]: any })`
|
|
234
257
|
|
|
235
|
-
Expose objects as global objects in the
|
|
258
|
+
Expose objects as global objects in the context.
|
|
236
259
|
|
|
237
|
-
By default, exposed objects are not synchronized between the host and the
|
|
260
|
+
By default, exposed objects are not synchronized between the host and the context.
|
|
238
261
|
If you want to sync an objects, first wrap the object with `sync` method, and then expose the wrapped object.
|
|
239
262
|
|
|
240
263
|
#### `sync<T>(target: T): T`
|
|
241
264
|
|
|
242
|
-
Enables sync for the object between the host and the
|
|
265
|
+
Enables sync for the object between the host and the context and returns objects wrapped with proxies.
|
|
243
266
|
|
|
244
|
-
The return value is necessary in order to reflect changes to the object from the host to the
|
|
267
|
+
The return value is necessary in order to reflect changes to the object from the host to the context. Please note that setting a value in the field or deleting a field in the original object will not synchronize it.
|
|
245
268
|
|
|
246
269
|
#### `register(target: any, code: string | QuickJSHandle)`
|
|
247
270
|
|
|
248
|
-
Register a pair of objects that will be considered the same between the host and the QuickJS
|
|
271
|
+
Register a pair of objects that will be considered the same between the host and the QuickJS context.
|
|
249
272
|
|
|
250
273
|
#### `unregisterAll(targets: Iterable<[any, string | QuickJSHandle]>)`
|
|
251
274
|
|
|
@@ -271,9 +294,9 @@ Measure the complexity of an object as you traverse the field and prototype chai
|
|
|
271
294
|
|
|
272
295
|
### How to work
|
|
273
296
|
|
|
274
|
-
quickjs-emscripten can execute JS code safely, but it requires to deal with a lot of handles and lifetimes. Also, when destroying the
|
|
297
|
+
quickjs-emscripten can execute JS code safely, but it requires to deal with a lot of handles and lifetimes. Also, when destroying the context, any un-destroyed handle will result in an error.
|
|
275
298
|
|
|
276
|
-
quickjs-emscripten-sync will automatically manage all handles once generated by QuickJS
|
|
299
|
+
quickjs-emscripten-sync will automatically manage all handles once generated by QuickJS context in an Arena class.
|
|
277
300
|
And it will automatically "marshal" objects as handles and "unmarshal" handles as objects to enable seamless data exchange between the browser and QuickJS. It recursively traverses the object properties and prototype chain to transform objects. A function is called after its arguments and this arg are automatically converted for the environment in which the function is defined. The return value will be automatically converted to match the environment of the caller.
|
|
278
301
|
Most objects are wrapped by proxies during conversion, allowing "set" and "delete" operations on objects to be synchronized between the browser and QuickJS.
|
|
279
302
|
|
|
@@ -281,7 +304,7 @@ Most objects are wrapped by proxies during conversion, allowing "set" and "delet
|
|
|
281
304
|
|
|
282
305
|
#### Class constructor
|
|
283
306
|
|
|
284
|
-
When initializing a new instance, it is not possible to fully proxy this arg (a.k.a. `new.target`) inside the class constructor. Therefore, after the constructor call, the fields set for this are re-set to this on the
|
|
307
|
+
When initializing a new instance, it is not possible to fully proxy this arg (a.k.a. `new.target`) inside the class constructor. Therefore, after the constructor call, the fields set for this are re-set to this on the context side. Therefore, there may be some edge cases where the constructor may not work properly.
|
|
285
308
|
|
|
286
309
|
```js
|
|
287
310
|
class Cls {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import type { QuickJSContext } from 'quickjs-emscripten';
|
|
1
2
|
import type { QuickJSDeferredPromise } from 'quickjs-emscripten';
|
|
2
|
-
import { QuickJSHandle } from 'quickjs-emscripten';
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import type { VmCallResult } from 'quickjs-emscripten/dist/vm-interface';
|
|
3
|
+
import type { QuickJSHandle } from 'quickjs-emscripten';
|
|
4
|
+
import type { SuccessOrFail } from 'quickjs-emscripten';
|
|
5
|
+
import type { VmCallResult } from 'quickjs-emscripten';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The Arena class manages all generated handles at once by quickjs-emscripten and automatically converts objects between the host and the QuickJS VM.
|
|
9
9
|
*/
|
|
10
10
|
export declare class Arena {
|
|
11
|
-
|
|
11
|
+
context: QuickJSContext;
|
|
12
12
|
_map: VMMap;
|
|
13
13
|
_registeredMap: VMMap;
|
|
14
14
|
_registeredMapDispose: Set<any>;
|
|
@@ -17,8 +17,8 @@ export declare class Arena {
|
|
|
17
17
|
_symbol: symbol;
|
|
18
18
|
_symbolHandle: QuickJSHandle;
|
|
19
19
|
_options?: Options;
|
|
20
|
-
/** Constructs a new Arena instance. It requires a quickjs-emscripten
|
|
21
|
-
constructor(
|
|
20
|
+
/** Constructs a new Arena instance. It requires a quickjs-emscripten context initialized with `quickjs.newContext()`. */
|
|
21
|
+
constructor(ctx: QuickJSContext, options?: Options);
|
|
22
22
|
/**
|
|
23
23
|
* Dispose of the arena and managed handles. This method won't dispose the VM itself, so the VM has to be disposed of manually.
|
|
24
24
|
*/
|
|
@@ -85,7 +85,7 @@ export declare class Arena {
|
|
|
85
85
|
_unwrapHandle(target: QuickJSHandle): [QuickJSHandle, boolean];
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export declare function call(
|
|
88
|
+
export declare function call(ctx: QuickJSContext, code: string, thisArg?: QuickJSHandle, ...args: QuickJSHandle[]): QuickJSHandle;
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* Measure the complexity of an object as you traverse the field and prototype chain. If max is specified, when the complexity reaches max, the traversal is terminated and it returns the max. In this function, one object and function are counted as a complexity of 1, and primitives are not counted as a complexity.
|
|
@@ -99,49 +99,61 @@ export declare function consumeAll<T extends QuickJSHandle[], K>(handles: T, cb:
|
|
|
99
99
|
*/
|
|
100
100
|
export declare const defaultRegisteredObjects: [any, string][];
|
|
101
101
|
|
|
102
|
-
export declare function eq(
|
|
102
|
+
export declare function eq(ctx: QuickJSContext, a: QuickJSHandle, b: QuickJSHandle): boolean;
|
|
103
103
|
|
|
104
104
|
export declare function isES2015Class(cls: any): cls is new (...args: any[]) => any;
|
|
105
105
|
|
|
106
|
-
export declare function isHandleObject(
|
|
106
|
+
export declare function isHandleObject(ctx: QuickJSContext, h: QuickJSHandle): boolean;
|
|
107
107
|
|
|
108
108
|
export declare function isObject(value: any): value is object | Function;
|
|
109
109
|
|
|
110
|
-
export declare function json(
|
|
110
|
+
export declare function json(ctx: QuickJSContext, target: any): QuickJSHandle;
|
|
111
111
|
|
|
112
112
|
export declare function marshal(target: unknown, options: Options_2): QuickJSHandle;
|
|
113
113
|
|
|
114
114
|
export declare type Options = {
|
|
115
115
|
/** A callback that returns a boolean value that determines whether an object is marshalled or not. If false, no marshaling will be done and undefined will be passed to the QuickJS VM, otherwise marshaling will be done. By default, all objects will be marshalled. */
|
|
116
116
|
isMarshalable?: boolean | "json" | ((target: any) => boolean | "json");
|
|
117
|
-
/**
|
|
117
|
+
/** Pre-registered pairs of objects that will be considered the same between the host and the QuickJS VM. This will be used automatically during the conversion. By default, it will be registered automatically with `defaultRegisteredObjects`.
|
|
118
118
|
*
|
|
119
119
|
* Instead of a string, you can also pass a QuickJSHandle directly. In that case, however, you have to dispose of them manually when destroying the VM.
|
|
120
120
|
*/
|
|
121
121
|
registeredObjects?: Iterable<[any, QuickJSHandle | string]>;
|
|
122
|
+
/** Register functions to convert an object to a QuickJS handle. */
|
|
123
|
+
customMarshaller?: Iterable<(target: unknown, ctx: QuickJSContext) => QuickJSHandle | undefined>;
|
|
124
|
+
/** Register functions to convert a QuickJS handle to an object. */
|
|
125
|
+
customUnmarshaller?: Iterable<(target: QuickJSHandle, ctx: QuickJSContext) => any>;
|
|
126
|
+
/** A callback that returns a boolean value that determines whether an object is wrappable by proxies. If returns false, note that the object cannot be synchronized between the host and the QuickJS even if arena.sync is used. */
|
|
127
|
+
isWrappable?: (target: any) => boolean;
|
|
128
|
+
/** A callback that returns a boolean value that determines whether an QuickJS handle is wrappable by proxies. If returns false, note that the handle cannot be synchronized between the host and the QuickJS even if arena.sync is used. */
|
|
129
|
+
isHandleWrappable?: (handle: QuickJSHandle, ctx: QuickJSContext) => boolean;
|
|
130
|
+
/** Compatibility with quickjs-emscripten prior to v0.15. Inject code for compatibility into context at Arena class initialization time. */
|
|
131
|
+
compat?: boolean;
|
|
122
132
|
};
|
|
123
133
|
|
|
124
134
|
declare type Options_2 = {
|
|
125
|
-
|
|
135
|
+
ctx: QuickJSContext;
|
|
126
136
|
unmarshal: (handle: QuickJSHandle) => unknown;
|
|
127
137
|
isMarshalable?: (target: unknown) => boolean | "json";
|
|
128
138
|
find: (target: unknown) => QuickJSHandle | undefined;
|
|
129
139
|
pre: (target: unknown, handle: QuickJSHandle | QuickJSDeferredPromise, mode: true | "json" | undefined) => QuickJSHandle | undefined;
|
|
130
140
|
preApply?: (target: Function, thisArg: unknown, args: unknown[]) => any;
|
|
141
|
+
custom?: Iterable<(obj: unknown, ctx: QuickJSContext) => QuickJSHandle | undefined>;
|
|
131
142
|
};
|
|
132
143
|
|
|
133
144
|
declare type Options_3 = {
|
|
134
|
-
|
|
145
|
+
ctx: QuickJSContext;
|
|
135
146
|
/** marshal returns handle and boolean indicates that the handle should be disposed after use */
|
|
136
147
|
marshal: (target: unknown) => [QuickJSHandle, boolean];
|
|
137
148
|
find: (handle: QuickJSHandle) => unknown | undefined;
|
|
138
149
|
pre: <T = unknown>(target: T, handle: QuickJSHandle) => T | undefined;
|
|
150
|
+
custom?: Iterable<(obj: QuickJSHandle, ctx: QuickJSContext) => any>;
|
|
139
151
|
};
|
|
140
152
|
|
|
141
153
|
export declare function unmarshal(handle: QuickJSHandle, options: Options_3): any;
|
|
142
154
|
|
|
143
155
|
export declare class VMMap {
|
|
144
|
-
|
|
156
|
+
ctx: QuickJSContext;
|
|
145
157
|
_map1: Map<any, number>;
|
|
146
158
|
_map2: Map<any, number>;
|
|
147
159
|
_map3: Map<number, QuickJSHandle>;
|
|
@@ -153,7 +165,7 @@ export declare class VMMap {
|
|
|
153
165
|
_mapDelete: QuickJSHandle;
|
|
154
166
|
_mapClear: QuickJSHandle;
|
|
155
167
|
_counter: number;
|
|
156
|
-
constructor(
|
|
168
|
+
constructor(ctx: QuickJSContext);
|
|
157
169
|
set(key: any, handle: QuickJSHandle, key2?: any, handle2?: QuickJSHandle): boolean;
|
|
158
170
|
merge(iteratable: Iterable<[any, QuickJSHandle | undefined] | [any, QuickJSHandle | undefined, any, QuickJSHandle | undefined]> | undefined): void;
|
|
159
171
|
get(key: any): QuickJSHandle | undefined;
|
|
@@ -166,12 +178,7 @@ export declare class VMMap {
|
|
|
166
178
|
clear(): void;
|
|
167
179
|
dispose(): void;
|
|
168
180
|
get size(): number;
|
|
169
|
-
[Symbol.iterator](): Iterator<[
|
|
170
|
-
any,
|
|
171
|
-
QuickJSHandle,
|
|
172
|
-
any,
|
|
173
|
-
QuickJSHandle | undefined
|
|
174
|
-
]>;
|
|
181
|
+
[Symbol.iterator](): Iterator<[any, QuickJSHandle, any, QuickJSHandle | undefined]>;
|
|
175
182
|
_get2(num: number): any;
|
|
176
183
|
_call(fn: QuickJSHandle, thisArg: QuickJSHandle | undefined, ...args: QuickJSHandle[]): QuickJSHandle;
|
|
177
184
|
}
|