quickjs-emscripten-sync 1.2.0 → 1.3.0
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/LICENSE +2 -2
- package/README.md +13 -9
- package/dist/index.d.ts +106 -20
- package/dist/quickjs-emscripten-sync.es.js +951 -0
- package/dist/quickjs-emscripten-sync.umd.js +64 -2
- package/package.json +24 -46
- package/src/index.test.ts +70 -0
- package/src/index.ts +9 -4
- package/src/marshal/function.test.ts +8 -7
- package/src/marshal/index.test.ts +46 -5
- package/src/marshal/index.ts +9 -3
- package/src/marshal/json.test.ts +5 -3
- package/src/marshal/object.test.ts +9 -7
- package/src/marshal/primitive.test.ts +2 -0
- package/src/marshal/promise.test.ts +86 -0
- package/src/marshal/promise.ts +26 -0
- package/src/marshal/properties.test.ts +4 -2
- package/src/marshal/symbol.test.ts +3 -1
- package/src/unmarshal/function.test.ts +15 -16
- package/src/unmarshal/index.test.ts +81 -84
- package/src/unmarshal/index.ts +4 -2
- package/src/unmarshal/object.test.ts +11 -9
- package/src/unmarshal/primitive.test.ts +2 -0
- package/src/unmarshal/promise.test.ts +44 -0
- package/src/unmarshal/promise.ts +40 -0
- package/src/unmarshal/properties.test.ts +3 -1
- package/src/unmarshal/symbol.test.ts +3 -1
- package/src/util.test.ts +19 -2
- package/src/util.ts +15 -0
- package/src/vmmap.test.ts +22 -0
- package/src/vmmap.ts +4 -0
- package/src/vmutil.test.ts +44 -3
- package/src/vmutil.ts +47 -7
- package/src/wrapper.test.ts +24 -22
- package/dist/default.d.ts +0 -4
- package/dist/marshal/function.d.ts +0 -2
- package/dist/marshal/index.d.ts +0 -11
- package/dist/marshal/json.d.ts +0 -2
- package/dist/marshal/object.d.ts +0 -2
- package/dist/marshal/primitive.d.ts +0 -2
- package/dist/marshal/properties.d.ts +0 -2
- package/dist/marshal/symbol.d.ts +0 -2
- package/dist/quickjs-emscripten-sync.cjs +0 -2
- package/dist/quickjs-emscripten-sync.cjs.map +0 -1
- package/dist/quickjs-emscripten-sync.modern.js +0 -2
- package/dist/quickjs-emscripten-sync.modern.js.map +0 -1
- package/dist/quickjs-emscripten-sync.module.js +0 -2
- package/dist/quickjs-emscripten-sync.module.js.map +0 -1
- package/dist/quickjs-emscripten-sync.umd.js.map +0 -1
- package/dist/unmarshal/function.d.ts +0 -2
- package/dist/unmarshal/index.d.ts +0 -9
- package/dist/unmarshal/object.d.ts +0 -2
- package/dist/unmarshal/primitive.d.ts +0 -2
- package/dist/unmarshal/properties.d.ts +0 -2
- package/dist/unmarshal/symbol.d.ts +0 -2
- package/dist/util.d.ts +0 -7
- package/dist/vmmap.d.ts +0 -35
- package/dist/vmutil.d.ts +0 -11
- package/dist/wrapper.d.ts +0 -11
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { getQuickJS } from "quickjs-emscripten";
|
|
2
|
+
import { expect, test, vi } from "vitest";
|
|
3
|
+
|
|
2
4
|
import unmarshalSymbol from "./symbol";
|
|
3
5
|
|
|
4
6
|
test("works", async () => {
|
|
5
7
|
const vm = (await getQuickJS()).createVm();
|
|
6
|
-
const pre =
|
|
8
|
+
const pre = vi.fn();
|
|
7
9
|
const obj = vm.newObject();
|
|
8
10
|
const handle = vm.unwrapResult(vm.evalCode(`Symbol("foobar")`));
|
|
9
11
|
|
package/src/util.test.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { expect, test, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
isES2015Class,
|
|
4
|
+
isObject,
|
|
5
|
+
walkObject,
|
|
6
|
+
complexity,
|
|
7
|
+
newDeferred,
|
|
8
|
+
} from "./util";
|
|
2
9
|
|
|
3
10
|
test("isES2015Class", () => {
|
|
4
11
|
expect(isES2015Class(class {})).toBe(true);
|
|
@@ -25,7 +32,7 @@ test("isObject", () => {
|
|
|
25
32
|
});
|
|
26
33
|
|
|
27
34
|
test("walkObject", () => {
|
|
28
|
-
const cb =
|
|
35
|
+
const cb = vi.fn();
|
|
29
36
|
const obj = { a: { b: 1, c: () => {} } };
|
|
30
37
|
const set = new Set<any>([obj, obj.a, obj.a.c]);
|
|
31
38
|
expect(walkObject(obj, cb)).toEqual(set);
|
|
@@ -52,3 +59,13 @@ test("complexity", () => {
|
|
|
52
59
|
expect(complexity({ a: {} })).toBe(2);
|
|
53
60
|
expect(complexity({ a: {} }, 1)).toBe(1);
|
|
54
61
|
});
|
|
62
|
+
|
|
63
|
+
test("newDeferred", () => {
|
|
64
|
+
const deferred = newDeferred();
|
|
65
|
+
deferred.resolve("foo");
|
|
66
|
+
expect(deferred.promise).resolves.toBe("foo");
|
|
67
|
+
|
|
68
|
+
const deferred2 = newDeferred();
|
|
69
|
+
deferred2.reject("bar");
|
|
70
|
+
expect(deferred2.promise).rejects.toBe("bar");
|
|
71
|
+
});
|
package/src/util.ts
CHANGED
|
@@ -51,3 +51,18 @@ export function walkObject(
|
|
|
51
51
|
export function complexity(value: any, max?: number): number {
|
|
52
52
|
return walkObject(value, max ? (_, set) => set.size < max : undefined).size;
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
export function newDeferred<T = unknown>() {
|
|
56
|
+
let res: (v: T | PromiseLike<T>) => void = () => {};
|
|
57
|
+
let rej: (v: T | PromiseLike<T>) => void = () => {};
|
|
58
|
+
const promise = new Promise<T>((resolve, reject) => {
|
|
59
|
+
res = resolve;
|
|
60
|
+
rej = reject;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
promise,
|
|
65
|
+
resolve: res,
|
|
66
|
+
reject: rej,
|
|
67
|
+
};
|
|
68
|
+
}
|
package/src/vmmap.test.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { getQuickJS } from "quickjs-emscripten";
|
|
2
|
+
import { expect, test } from "vitest";
|
|
3
|
+
|
|
2
4
|
import VMMap from "./vmmap";
|
|
3
5
|
import { call } from "./vmutil";
|
|
4
6
|
|
|
@@ -55,6 +57,26 @@ test("getByHandle", async () => {
|
|
|
55
57
|
vm.dispose();
|
|
56
58
|
});
|
|
57
59
|
|
|
60
|
+
test("keys", async () => {
|
|
61
|
+
const quickjs = await getQuickJS();
|
|
62
|
+
const vm = quickjs.createVm();
|
|
63
|
+
|
|
64
|
+
const target = {};
|
|
65
|
+
const handle = vm.newObject();
|
|
66
|
+
const handle2 = vm.newObject();
|
|
67
|
+
|
|
68
|
+
const map = new VMMap(vm);
|
|
69
|
+
expect(Array.from(map.keys())).toEqual([]);
|
|
70
|
+
map.set(target, handle);
|
|
71
|
+
expect(Array.from(map.keys())).toEqual([target]);
|
|
72
|
+
handle.dispose();
|
|
73
|
+
expect(Array.from(map.keys())).toEqual([target]);
|
|
74
|
+
|
|
75
|
+
handle2.dispose();
|
|
76
|
+
map.dispose();
|
|
77
|
+
vm.dispose();
|
|
78
|
+
});
|
|
79
|
+
|
|
58
80
|
test("delete", async () => {
|
|
59
81
|
const quickjs = await getQuickJS();
|
|
60
82
|
const vm = quickjs.createVm();
|
package/src/vmmap.ts
CHANGED
|
@@ -144,6 +144,10 @@ export default class VMMap {
|
|
|
144
144
|
return typeof this.getByHandle(handle) !== "undefined";
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
keys() {
|
|
148
|
+
return this._map1.keys();
|
|
149
|
+
}
|
|
150
|
+
|
|
147
151
|
delete(key: any, dispose?: boolean) {
|
|
148
152
|
const num = this._map1.get(key) ?? this._map2.get(key);
|
|
149
153
|
if (typeof num === "undefined") return;
|
package/src/vmutil.test.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { getQuickJS, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
+
import { expect, test, vi } from "vitest";
|
|
3
|
+
|
|
2
4
|
import {
|
|
5
|
+
fn,
|
|
3
6
|
call,
|
|
4
7
|
consumeAll,
|
|
5
8
|
eq,
|
|
@@ -8,8 +11,31 @@ import {
|
|
|
8
11
|
json,
|
|
9
12
|
mayConsume,
|
|
10
13
|
mayConsumeAll,
|
|
14
|
+
handleFrom,
|
|
11
15
|
} from "./vmutil";
|
|
12
16
|
|
|
17
|
+
test("fn", async () => {
|
|
18
|
+
const quickjs = await getQuickJS();
|
|
19
|
+
const vm = quickjs.createVm();
|
|
20
|
+
|
|
21
|
+
const f = fn(vm, "(a, b) => a + b");
|
|
22
|
+
expect(vm.getNumber(f(undefined, vm.newNumber(1), vm.newNumber(2)))).toBe(3);
|
|
23
|
+
|
|
24
|
+
const obj = vm.newObject();
|
|
25
|
+
vm.setProp(obj, "a", vm.newNumber(2));
|
|
26
|
+
const f2 = fn(vm, "(function() { return this.a + 1; })");
|
|
27
|
+
expect(vm.getNumber(f2(obj))).toBe(3);
|
|
28
|
+
|
|
29
|
+
obj.dispose();
|
|
30
|
+
expect(f.alive).toBe(true);
|
|
31
|
+
expect(f2.alive).toBe(true);
|
|
32
|
+
f2.dispose();
|
|
33
|
+
f.dispose();
|
|
34
|
+
expect(f.alive).toBe(false);
|
|
35
|
+
expect(f2.alive).toBe(false);
|
|
36
|
+
vm.dispose();
|
|
37
|
+
});
|
|
38
|
+
|
|
13
39
|
test("call", async () => {
|
|
14
40
|
const quickjs = await getQuickJS();
|
|
15
41
|
const vm = quickjs.createVm();
|
|
@@ -108,7 +134,7 @@ test("consumeAll", async () => {
|
|
|
108
134
|
expect(
|
|
109
135
|
consumeAll(
|
|
110
136
|
handles,
|
|
111
|
-
|
|
137
|
+
vi.fn(() => o)
|
|
112
138
|
)
|
|
113
139
|
).toBe(o);
|
|
114
140
|
expect(handles.every((h) => !h.alive)).toBe(true);
|
|
@@ -134,7 +160,7 @@ test("mayConsume", async () => {
|
|
|
134
160
|
expect(
|
|
135
161
|
mayConsume(
|
|
136
162
|
[handle, false],
|
|
137
|
-
|
|
163
|
+
vi.fn(() => o)
|
|
138
164
|
)
|
|
139
165
|
).toBe(o);
|
|
140
166
|
expect(handle.alive).toBe(true);
|
|
@@ -166,7 +192,7 @@ test("mayConsumeAll", async () => {
|
|
|
166
192
|
expect(
|
|
167
193
|
mayConsumeAll(
|
|
168
194
|
handles,
|
|
169
|
-
|
|
195
|
+
vi.fn((..._: any[]) => o)
|
|
170
196
|
)
|
|
171
197
|
).toBe(o);
|
|
172
198
|
expect(handles[0][0].alive).toBe(true);
|
|
@@ -188,3 +214,18 @@ test("mayConsumeAll", async () => {
|
|
|
188
214
|
handles2[0][0].dispose();
|
|
189
215
|
vm.dispose();
|
|
190
216
|
});
|
|
217
|
+
|
|
218
|
+
test("handleFrom", async () => {
|
|
219
|
+
const quickjs = await getQuickJS();
|
|
220
|
+
const vm = quickjs.createVm();
|
|
221
|
+
|
|
222
|
+
const handle = vm.newObject();
|
|
223
|
+
const promise = vm.newPromise();
|
|
224
|
+
|
|
225
|
+
expect(handleFrom(handle) === handle).toBe(true);
|
|
226
|
+
expect(handleFrom(promise) === promise.handle).toBe(true);
|
|
227
|
+
|
|
228
|
+
handle.dispose();
|
|
229
|
+
promise.dispose();
|
|
230
|
+
vm.dispose();
|
|
231
|
+
});
|
package/src/vmutil.ts
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
Disposable,
|
|
3
|
+
QuickJSVm,
|
|
4
|
+
QuickJSHandle,
|
|
5
|
+
QuickJSDeferredPromise,
|
|
6
|
+
} from "quickjs-emscripten";
|
|
7
|
+
|
|
8
|
+
export function fn(
|
|
9
|
+
vm: QuickJSVm,
|
|
10
|
+
code: string
|
|
11
|
+
): ((
|
|
12
|
+
thisArg: QuickJSHandle | undefined,
|
|
13
|
+
...args: QuickJSHandle[]
|
|
14
|
+
) => QuickJSHandle) &
|
|
15
|
+
Disposable {
|
|
16
|
+
const handle = vm.unwrapResult(vm.evalCode(code));
|
|
17
|
+
const f = (
|
|
18
|
+
thisArg: QuickJSHandle | undefined,
|
|
19
|
+
...args: QuickJSHandle[]
|
|
20
|
+
): any => {
|
|
21
|
+
return vm.unwrapResult(
|
|
22
|
+
vm.callFunction(handle, thisArg ?? vm.undefined, ...args)
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
f.dispose = () => handle.dispose();
|
|
26
|
+
f.alive = true;
|
|
27
|
+
Object.defineProperty(f, "alive", {
|
|
28
|
+
get: () => handle.alive,
|
|
29
|
+
});
|
|
30
|
+
return f;
|
|
31
|
+
}
|
|
2
32
|
|
|
3
33
|
export function call(
|
|
4
34
|
vm: QuickJSVm,
|
|
@@ -6,12 +36,12 @@ export function call(
|
|
|
6
36
|
thisArg?: QuickJSHandle,
|
|
7
37
|
...args: QuickJSHandle[]
|
|
8
38
|
): QuickJSHandle {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
|
|
13
|
-
);
|
|
14
|
-
}
|
|
39
|
+
const f = fn(vm, code);
|
|
40
|
+
try {
|
|
41
|
+
return f(thisArg, ...args);
|
|
42
|
+
} finally {
|
|
43
|
+
f.dispose();
|
|
44
|
+
}
|
|
15
45
|
}
|
|
16
46
|
|
|
17
47
|
export function eq(vm: QuickJSVm, a: QuickJSHandle, b: QuickJSHandle): boolean {
|
|
@@ -83,3 +113,13 @@ export function mayConsumeAll<T, H extends QuickJSHandle[]>(
|
|
|
83
113
|
}
|
|
84
114
|
}
|
|
85
115
|
}
|
|
116
|
+
|
|
117
|
+
function isQuickJSDeferredPromise(d: Disposable): d is QuickJSDeferredPromise {
|
|
118
|
+
return "handle" in d;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function handleFrom(
|
|
122
|
+
d: QuickJSDeferredPromise | QuickJSHandle
|
|
123
|
+
): QuickJSHandle {
|
|
124
|
+
return isQuickJSDeferredPromise(d) ? d.handle : d;
|
|
125
|
+
}
|
package/src/wrapper.test.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { QuickJSHandle, getQuickJS } from "quickjs-emscripten";
|
|
2
|
+
import { expect, test, vi } from "vitest";
|
|
3
|
+
|
|
2
4
|
import {
|
|
3
5
|
wrap,
|
|
4
6
|
unwrap,
|
|
@@ -16,8 +18,8 @@ test("wrap, unwrap, isWrapped", async () => {
|
|
|
16
18
|
const handle = vm.unwrapResult(vm.evalCode(`({ a: 1 })`));
|
|
17
19
|
const proxyKeySymbol = Symbol();
|
|
18
20
|
const proxyKeySymbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));
|
|
19
|
-
const marshal =
|
|
20
|
-
const syncMode =
|
|
21
|
+
const marshal = vi.fn();
|
|
22
|
+
const syncMode = vi.fn();
|
|
21
23
|
|
|
22
24
|
expect(isWrapped(target, proxyKeySymbol)).toBe(false);
|
|
23
25
|
expect(unwrap(target, proxyKeySymbol)).toBe(target);
|
|
@@ -51,8 +53,8 @@ test("wrap without sync", async () => {
|
|
|
51
53
|
const handle = vm.unwrapResult(vm.evalCode(`({ a: 1 })`));
|
|
52
54
|
const proxyKeySymbol = Symbol();
|
|
53
55
|
const proxyKeySymbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));
|
|
54
|
-
const marshal =
|
|
55
|
-
const syncMode =
|
|
56
|
+
const marshal = vi.fn();
|
|
57
|
+
const syncMode = vi.fn();
|
|
56
58
|
|
|
57
59
|
const wrapped = wrap(
|
|
58
60
|
vm,
|
|
@@ -89,11 +91,11 @@ test("wrap with both sync", async () => {
|
|
|
89
91
|
const handle = vm.unwrapResult(vm.evalCode(`({ a: 1 })`));
|
|
90
92
|
const proxyKeySymbol = Symbol();
|
|
91
93
|
const proxyKeySymbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));
|
|
92
|
-
const marshal =
|
|
94
|
+
const marshal = vi.fn((t: any): [QuickJSHandle, boolean] => [
|
|
93
95
|
t === wrapped ? handle : json(vm, t),
|
|
94
96
|
false,
|
|
95
97
|
]);
|
|
96
|
-
const syncMode =
|
|
98
|
+
const syncMode = vi.fn((): SyncMode => "both");
|
|
97
99
|
|
|
98
100
|
const wrapped = wrap(
|
|
99
101
|
vm,
|
|
@@ -136,11 +138,11 @@ test("wrap with vm sync", async () => {
|
|
|
136
138
|
const handle = vm.unwrapResult(vm.evalCode(`({ a: 1 })`));
|
|
137
139
|
const proxyKeySymbol = Symbol();
|
|
138
140
|
const proxyKeySymbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));
|
|
139
|
-
const marshal =
|
|
141
|
+
const marshal = vi.fn((t: any): [QuickJSHandle, boolean] => [
|
|
140
142
|
t === wrapped ? handle : json(vm, t),
|
|
141
143
|
false,
|
|
142
144
|
]);
|
|
143
|
-
const syncMode =
|
|
145
|
+
const syncMode = vi.fn((): SyncMode => "vm");
|
|
144
146
|
|
|
145
147
|
const wrapped = wrap(
|
|
146
148
|
vm,
|
|
@@ -183,8 +185,8 @@ test("wrapHandle, unwrapHandle, isHandleWrapped", async () => {
|
|
|
183
185
|
const handle = vm.unwrapResult(vm.evalCode(`({ a: 1 })`));
|
|
184
186
|
const proxyKeySymbol = Symbol();
|
|
185
187
|
const proxyKeySymbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));
|
|
186
|
-
const unmarshal =
|
|
187
|
-
const syncMode =
|
|
188
|
+
const unmarshal = vi.fn();
|
|
189
|
+
const syncMode = vi.fn();
|
|
188
190
|
|
|
189
191
|
expect(isHandleWrapped(vm, handle, proxyKeySymbolHandle)).toBe(false);
|
|
190
192
|
expect(unwrapHandle(vm, handle, proxyKeySymbolHandle)).toEqual([
|
|
@@ -234,10 +236,10 @@ test("wrapHandle without sync", async () => {
|
|
|
234
236
|
const handle = vm.unwrapResult(vm.evalCode(`({ a: 1 })`));
|
|
235
237
|
const proxyKeySymbol = Symbol();
|
|
236
238
|
const proxyKeySymbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));
|
|
237
|
-
const unmarshal =
|
|
239
|
+
const unmarshal = vi.fn((h: QuickJSHandle) =>
|
|
238
240
|
wrapped && eq(vm, h, wrapped) ? target : vm.dump(h)
|
|
239
241
|
);
|
|
240
|
-
const syncMode =
|
|
242
|
+
const syncMode = vi.fn();
|
|
241
243
|
|
|
242
244
|
const [wrapped, w] = wrapHandle(
|
|
243
245
|
vm,
|
|
@@ -273,10 +275,10 @@ test("wrapHandle with both sync", async () => {
|
|
|
273
275
|
const handle = vm.unwrapResult(vm.evalCode(`({ a: 1 })`));
|
|
274
276
|
const proxyKeySymbol = Symbol();
|
|
275
277
|
const proxyKeySymbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));
|
|
276
|
-
const unmarshal =
|
|
278
|
+
const unmarshal = vi.fn((h: QuickJSHandle) => {
|
|
277
279
|
return wrapped && eq(vm, h, wrapped) ? target : vm.dump(h);
|
|
278
280
|
});
|
|
279
|
-
const syncMode =
|
|
281
|
+
const syncMode = vi.fn((): SyncMode => "both");
|
|
280
282
|
|
|
281
283
|
const [wrapped, w] = wrapHandle(
|
|
282
284
|
vm,
|
|
@@ -325,10 +327,10 @@ test("wrapHandle with host sync", async () => {
|
|
|
325
327
|
const handle = vm.unwrapResult(vm.evalCode(`({ a: 1 })`));
|
|
326
328
|
const proxyKeySymbol = Symbol();
|
|
327
329
|
const proxyKeySymbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));
|
|
328
|
-
const unmarshal =
|
|
330
|
+
const unmarshal = vi.fn((handle: QuickJSHandle) =>
|
|
329
331
|
wrapped && eq(vm, handle, wrapped) ? target : vm.dump(handle)
|
|
330
332
|
);
|
|
331
|
-
const syncMode =
|
|
333
|
+
const syncMode = vi.fn((): SyncMode => "host");
|
|
332
334
|
|
|
333
335
|
const [wrapped, w] = wrapHandle(
|
|
334
336
|
vm,
|
|
@@ -370,14 +372,14 @@ test("wrap and wrapHandle", async () => {
|
|
|
370
372
|
const handle = vm.unwrapResult(vm.evalCode(`({ a: 1 })`));
|
|
371
373
|
const proxyKeySymbol = Symbol();
|
|
372
374
|
const proxyKeySymbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));
|
|
373
|
-
const marshal =
|
|
375
|
+
const marshal = vi.fn((t: any): [QuickJSHandle, boolean] => [
|
|
374
376
|
wrappedHandle && t === wrapped ? wrappedHandle : json(vm, t),
|
|
375
377
|
false,
|
|
376
378
|
]);
|
|
377
|
-
const unmarshal =
|
|
379
|
+
const unmarshal = vi.fn((handle: QuickJSHandle) =>
|
|
378
380
|
wrappedHandle && eq(vm, handle, wrappedHandle) ? wrapped : vm.dump(handle)
|
|
379
381
|
);
|
|
380
|
-
const syncMode =
|
|
382
|
+
const syncMode = vi.fn((): SyncMode => "both");
|
|
381
383
|
|
|
382
384
|
const wrapped = wrap(
|
|
383
385
|
vm,
|
|
@@ -435,7 +437,7 @@ test("non object", async () => {
|
|
|
435
437
|
const proxyKeySymbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));
|
|
436
438
|
|
|
437
439
|
expect(
|
|
438
|
-
wrap(vm, target, proxyKeySymbol, proxyKeySymbolHandle,
|
|
440
|
+
wrap(vm, target, proxyKeySymbol, proxyKeySymbolHandle, vi.fn(), vi.fn())
|
|
439
441
|
).toBe(undefined);
|
|
440
442
|
|
|
441
443
|
expect(
|
|
@@ -444,8 +446,8 @@ test("non object", async () => {
|
|
|
444
446
|
handle,
|
|
445
447
|
proxyKeySymbol,
|
|
446
448
|
proxyKeySymbolHandle,
|
|
447
|
-
|
|
448
|
-
|
|
449
|
+
vi.fn(),
|
|
450
|
+
vi.fn()
|
|
449
451
|
)
|
|
450
452
|
).toEqual([undefined, false]);
|
|
451
453
|
|
package/dist/default.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { QuickJSVm, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
-
export default function marshalFunction(vm: QuickJSVm, target: unknown, marshal: (target: unknown) => QuickJSHandle, unmarshal: (handle: QuickJSHandle) => unknown, preMarshal: (target: unknown, handle: QuickJSHandle) => QuickJSHandle | undefined, preApply?: (target: Function, thisArg: unknown, args: unknown[]) => any): QuickJSHandle | undefined;
|
package/dist/marshal/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { QuickJSHandle, QuickJSVm } from "quickjs-emscripten";
|
|
2
|
-
export declare type Options = {
|
|
3
|
-
vm: QuickJSVm;
|
|
4
|
-
unmarshal: (handle: QuickJSHandle) => unknown;
|
|
5
|
-
isMarshalable?: (target: unknown) => boolean | "json";
|
|
6
|
-
find: (target: unknown) => QuickJSHandle | undefined;
|
|
7
|
-
pre: (target: unknown, handle: QuickJSHandle, mode: true | "json" | undefined) => QuickJSHandle | undefined;
|
|
8
|
-
preApply?: (target: Function, thisArg: unknown, args: unknown[]) => any;
|
|
9
|
-
};
|
|
10
|
-
export declare function marshal(target: unknown, options: Options): QuickJSHandle;
|
|
11
|
-
export default marshal;
|
package/dist/marshal/json.d.ts
DELETED
package/dist/marshal/object.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { QuickJSVm, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
-
export default function marshalObject(vm: QuickJSVm, target: unknown, marshal: (target: unknown) => QuickJSHandle, preMarshal: (target: unknown, handle: QuickJSHandle) => QuickJSHandle | undefined): QuickJSHandle | undefined;
|
package/dist/marshal/symbol.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function e(t,r){return e=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},e(t,r)}function t(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function r(n,o,i){return r=t()?Reflect.construct:function(t,r,n){var o=[null];o.push.apply(o,r);var i=new(Function.bind.apply(t,o));return n&&e(i,n.prototype),i},r.apply(null,arguments)}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function o(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=function(e){function t(e){var t=this;this.vm=void 0,this._map1=new Map,this._map2=new Map,this._map3=new Map,this._map4=new Map,this._counterMap=new Map,this._disposables=new Set,this._mapGet=void 0,this._mapSet=void 0,this._mapDelete=void 0,this._mapClear=void 0,this._counter=0,this.vm=e;var r=e.unwrapResult(e.evalCode('() => {\n const mapSym = new Map();\n let map = new WeakMap();\n let map2 = new WeakMap();\n const isObj = o => typeof o === "object" && o !== null || typeof o === "function";\n return {\n get: key => mapSym.get(key) ?? map.get(key) ?? map2.get(key) ?? -1,\n set: (key, value, key2) => {\n if (typeof key === "symbol") mapSym.set(key, value);\n if (isObj(key)) map.set(key, value);\n if (isObj(key2)) map2.set(key2, value);\n },\n delete: (key, key2) => {\n mapSym.delete(key);\n map.delete(key);\n map2.delete(key2);\n },\n clear: () => {\n mapSym.clear();\n map = new WeakMap();\n map2 = new WeakMap();\n }\n };\n }')).consume(function(e){return t._call(e,void 0)});this._mapGet=e.getProp(r,"get"),this._mapSet=e.getProp(r,"set"),this._mapDelete=e.getProp(r,"delete"),this._mapClear=e.getProp(r,"clear"),r.dispose(),this._disposables.add(this._mapGet),this._disposables.add(this._mapSet),this._disposables.add(this._mapDelete),this._disposables.add(this._mapClear)}var r,n=t.prototype;return n.set=function(e,t,r,n){var o,i=this;if(!t.alive||n&&!n.alive)return!1;var a=null!=(o=this.get(e))?o:this.get(r);if(a)return a===t||a===n;var s=this._counter++;return this._map1.set(e,s),this._map3.set(s,t),this._counterMap.set(s,e),r&&(this._map2.set(r,s),n&&this._map4.set(s,n)),this.vm.newNumber(s).consume(function(e){i._call(i._mapSet,void 0,t,e,null!=n?n:i.vm.undefined)}),!0},n.merge=function(e){if(e)for(var t,r=o(e);!(t=r()).done;){var n=t.value;n&&n[1]&&this.set(n[0],n[1],n[2],n[3])}},n.get=function(e){var t,r=null!=(t=this._map1.get(e))?t:this._map2.get(e),n="number"==typeof r?this._map3.get(r):void 0;if(n){if(n.alive)return n;this.delete(e)}},n.getByHandle=function(e){if(e.alive)return this._counterMap.get(this.vm.getNumber(this._call(this._mapGet,void 0,e)))},n.has=function(e){return!!this.get(e)},n.hasHandle=function(e){return void 0!==this.getByHandle(e)},n.delete=function(e,t){var r,n=null!=(r=this._map1.get(e))?r:this._map2.get(e);if(void 0!==n){var i=this._map3.get(n),a=this._map4.get(n);this._call.apply(this,[this._mapDelete,void 0].concat([i,a].filter(function(e){return!(null==e||!e.alive)}))),this._map1.delete(e),this._map2.delete(e),this._map3.delete(n),this._map4.delete(n);for(var s,u=o(this._map1);!(s=u()).done;){var l=s.value;if(l[1]===n){this._map1.delete(l[0]);break}}for(var p,c=o(this._map2);!(p=c()).done;){var f=p.value;if(f[1]===n){this._map2.delete(f[0]);break}}for(var v,d=o(this._counterMap);!(v=d()).done;){var y=v.value;if(y[1]===e){this._counterMap.delete(y[0]);break}}t&&(null!=i&&i.alive&&i.dispose(),null!=a&&a.alive&&a.dispose())}},n.deleteByHandle=function(e,t){var r=this.getByHandle(e);void 0!==r&&this.delete(r,t)},n.clear=function(){this._counter=0,this._map1.clear(),this._map2.clear(),this._map3.clear(),this._map4.clear(),this._counterMap.clear(),this._mapClear.alive&&this._call(this._mapClear,void 0)},n.dispose=function(){for(var e,t=o(this._disposables.values());!(e=t()).done;){var r=e.value;r.alive&&r.dispose()}for(var n,i=o(this._map3.values());!(n=i()).done;){var a=n.value;a.alive&&a.dispose()}for(var s,u=o(this._map4.values());!(s=u()).done;){var l=s.value;l.alive&&l.dispose()}this._disposables.clear(),this.clear()},n[e]=function(){var e=this,t=this._map1.keys();return{next:function(){for(;;){var r=t.next();if(r.done)return{value:void 0,done:!0};var n=e._map1.get(r.value);if(void 0!==n){var o=e._map3.get(n),i=e._map4.get(n);if(o){var a=e._get2(n);return{value:[r.value,o,a,i],done:!1}}}}}}},n._get2=function(e){for(var t,r=o(this._map2);!(t=r()).done;){var n=t.value;if(n[1]===e)return n[0]}},n._call=function(e,t){var r;return this.vm.unwrapResult((r=this.vm).callFunction.apply(r,[e,void 0===t?this.vm.undefined:t].concat([].slice.call(arguments,2))))},(r=[{key:"size",get:function(){return this._map1.size}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(t.prototype,r),t}(Symbol.iterator);function a(e){return"function"==typeof e&&/^class\s/.test(Function.prototype.toString.call(e))}function s(e){return"function"==typeof e||"object"==typeof e&&null!==e}function u(e,t){var r=new Set;return function e(n){if(s(n)&&!r.has(n)&&!1!==(null==t?void 0:t(n,r)))if(r.add(n),Array.isArray(n))for(var i,a=o(n);!(i=a()).done;)e(i.value);else{if("object"==typeof n){var u=Object.getPrototypeOf(n);u&&u!==Object.prototype&&e(u)}for(var l=0,p=Object.values(Object.getOwnPropertyDescriptors(n));l<p.length;l++){var c=p[l];"value"in c&&e(c.value),"get"in c&&e(c.get),"set"in c&&e(c.set)}}}(e),r}function l(e,t,r){var n=[].slice.call(arguments,3);return e.unwrapResult(e.evalCode(t)).consume(function(t){return void 0===r&&0===n.length?t:e.unwrapResult(e.callFunction.apply(e,[t,null!=r?r:e.undefined].concat(n)))})}function p(e,t,r){return e.dump(l(e,"Object.is",void 0,t,r))}function c(e,t){return e.dump(l(e,'a => typeof a === "object" && a !== null || typeof a === "function"',void 0,t))}function f(e,t){var r=JSON.stringify(t);return r?l(e,"JSON.parse",void 0,e.newString(r)):e.undefined}function v(e,t){try{return t(e)}finally{for(var r,n=o(e);!(r=n()).done;){var i=r.value;i.alive&&i.dispose()}}}function d(e,t){try{return t.apply(void 0,e.map(function(e){return e[0]}))}finally{for(var r,n=o(e);!(r=n()).done;){var i=r.value;i[1]&&i[0].dispose()}}}function y(e,t,r,n){var o=e.newObject(),i=function(t,r){var i=n(t),a=void 0===r.value?void 0:n(r.value),s=void 0===r.get?void 0:n(r.get),u=void 0===r.set?void 0:n(r.set);e.newObject().consume(function(t){Object.entries(r).forEach(function(r){var n=r[0],o="value"===n?a:"get"===n?s:"set"===n?u:r[1]?e.true:e.false;o&&e.setProp(t,n,o)}),e.setProp(o,i,t)})},a=Object.getOwnPropertyDescriptors(t);Object.entries(a).forEach(function(e){return i(e[0],e[1])}),Object.getOwnPropertySymbols(a).forEach(function(e){return i(e,a[e])}),l(e,"Object.defineProperties",void 0,r,o).dispose(),o.dispose()}function h(e,t){var n,o,i,u=t.vm,p=t.unmarshal,c=t.isMarshalable,v=t.find,d=t.pre,m=function(e,t){switch(typeof t){case"undefined":return e.undefined;case"number":return e.newNumber(t);case"string":return e.newString(t);case"boolean":return t?e.true:e.false;case"object":return null===t?e.null:void 0}}(u,e);if(m)return m;var _=v(e);if(_)return _;var b=null==c?void 0:c(e);if(!1===b)return u.undefined;var g=function(e,t){return d(e,t,b)};if("json"===b)return function(e,t,r){var n,o=f(e,t);return null!=(n=r(t,o))?n:o}(u,e,g);var w=function(e){return h(e,t)};return null!=(n=null!=(o=null!=(i=function(e,t,r){var n;if("symbol"==typeof t){var o=l(e,"d => Symbol(d)",void 0,t.description?e.newString(t.description):e.undefined);return null!=(n=r(t,o))?n:o}}(u,e,g))?i:function(e,t,n,o,i,u){var p;if("function"==typeof t){var c=e.newFunction(t.name,function(){var i=this,l=o(this),p=[].slice.call(arguments).map(function(e){return o(e)});if(a(t)&&s(l)){var c=r(t,p);return Object.entries(c).forEach(function(t){e.setProp(i,t[0],n(t[1]))}),this}return n(u?u(t,l,p):t.apply(l,p))}).consume(function(t){return l(e,"Cls => {\n const fn = function(...args) { return Cls.apply(this, args); };\n fn.name = Cls.name;\n fn.length = Cls.length;\n return fn;\n }",void 0,t)}),f=null!=(p=i(t,c))?p:c;return y(e,t,c,n),f}}(u,e,w,p,g,t.preApply))?o:function(e,t,r,n){var o;if("object"==typeof t&&null!==t){var i=Array.isArray(t)?e.newArray():e.newObject(),a=null!=(o=n(t,i))?o:i,s=Object.getPrototypeOf(t),u=s&&s!==Object.prototype&&s!==Array.prototype?r(s):void 0;return u&&l(e,"Object.setPrototypeOf",void 0,a,u).dispose(),y(e,t,i,r),a}}(u,e,w,g))?n:u.undefined}function m(e,t,r,n){e.newFunction("",function(t,o){var i=n(t)[0];if("string"==typeof i||"number"==typeof i||"symbol"==typeof i){var a=[["value",!0],["get",!0],["set",!0],["configurable",!1],["enumerable",!1],["writable",!1]].reduce(function(t,r){var i=r[0],a=r[1],s=e.getProp(o,i),u=e.typeof(s);if("undefined"===u)return t;if(!a&&"boolean"===u)return t[i]=e.dump(e.getProp(o,i)),t;var l=n(s),p=l[0];return l[1]&&s.dispose(),t[i]=p,t},{});Object.defineProperty(r,i,a)}}).consume(function(r){l(e,"(o, fn) => {\n const descs = Object.getOwnPropertyDescriptors(o);\n Object.entries(descs).forEach(([k, v]) => fn(k, v));\n Object.getOwnPropertySymbols(descs).forEach(k => fn(k, descs[k]));\n }",void 0,t,r).dispose()})}function _(e,t){return b(e,t)[0]}function b(e,t){var r,n,o=t.vm,i=t.marshal,a=t.find,s=t.pre,u=function(e,t){var r=e.typeof(t);return"undefined"===r||"number"===r||"string"===r||"boolean"===r?[e.dump(t),!0]:"object"===r&&e.unwrapResult(e.evalCode("a => a === null")).consume(function(r){return e.dump(e.unwrapResult(e.callFunction(r,e.undefined,t)))})?[null,!0]:[void 0,!1]}(o,e);if(u[1])return[u[0],!1];var p=a(e);if(p)return[p,!0];var c=function(e){return b(e,t)},f=null!=(r=null!=(n=function(e,t,r){var n;if("symbol"===e.typeof(t)){var o=e.getString(e.getProp(t,"description")),i=Symbol(o);return null!=(n=r(i,t))?n:i}}(o,e,s))?n:function(e,t,r,n,o){var i;if("function"===e.typeof(t)){var a=function o(){var i=this instanceof o?this.constructor:void 0,a=this;return d([r(this)].concat([].slice.call(arguments).map(function(e){return r(e)})),function(r){var o=[].slice.call(arguments,1);if(i){var s=n(l.apply(void 0,[e,"(Cls, ...args) => new Cls(...args)",r,t].concat(o)));return Object.defineProperties(a,Object.getOwnPropertyDescriptors(s[0])),a}var u=e.unwrapResult(e.callFunction.apply(e,[t,r].concat(o))),p=n(u),c=p[0];return p[1]&&u.dispose(),c})},s=null!=(i=o(a,t))?i:a;return m(e,t,a,n),s}}(o,e,i,c,s))?r:function(e,t,r,n){var o;if("object"===e.typeof(t)&&!e.unwrapResult(e.evalCode("o => o === null")).consume(function(r){return e.dump(e.unwrapResult(e.callFunction(r,e.undefined,t)))})){var i=l(e,"Array.isArray",void 0,t).consume(function(t){return e.dump(t)})?[]:{},a=null!=(o=n(i,t))?o:i,s=l(e,"o => {\n const p = Object.getPrototypeOf(o);\n return !p || p === Object.prototype || p === Array.prototype ? undefined : p;\n }",void 0,t).consume(function(t){if("undefined"!==e.typeof(t))return r(t)[0]});return"object"==typeof s&&Object.setPrototypeOf(a,s),m(e,t,i,r),a}}(o,e,c,s);return[f,!1]}function g(e,t){var r;return s(e)&&null!=(r=e[t])?r:e}function w(e,t,r){return j(e,t,r)?[e.getProp(t,r),!0]:[t,!1]}function j(e,t,r){return!!e.dump(l(e,'(a, s) => (typeof a === "object" && a !== null || typeof a === "function") && !!a[s]',void 0,t,r))}var S=[[Symbol,"Symbol"],[Symbol.prototype,"Symbol.prototype"],[Object,"Object"],[Object.prototype,"Object.prototype"],[Function,"Function"],[Function.prototype,"Function.prototype"],[Boolean,"Boolean"],[Boolean.prototype,"Boolean.prototype"],[Array,"Array"],[Array.prototype,"Array.prototype"],[Error,"Error"],[Error.prototype,"Error.prototype"],[EvalError,"EvalError"],[EvalError.prototype,"EvalError.prototype"],[RangeError,"RangeError"],[RangeError.prototype,"RangeError.prototype"],[ReferenceError,"ReferenceError"],[ReferenceError.prototype,"ReferenceError.prototype"],[SyntaxError,"SyntaxError"],[SyntaxError.prototype,"SyntaxError.prototype"],[TypeError,"TypeError"],[TypeError.prototype,"TypeError.prototype"],[URIError,"URIError"],[URIError.prototype,"URIError.prototype"]].concat(Object.getOwnPropertyNames(Symbol).filter(function(e){return"symbol"==typeof Symbol[e]}).map(function(e){return[Symbol[e],"Symbol."+e]}));exports.Arena=function(){function e(e,t){var r,n=this;this.vm=void 0,this._map=void 0,this._registeredMap=void 0,this._registeredMapDispose=new Set,this._sync=new Set,this._temporalSync=new Set,this._symbol=Symbol(),this._symbolHandle=void 0,this._options=void 0,this._isMarshalable=function(e){var t,r,o=null==(t=n._options)?void 0:t.isMarshalable;return null!=(r="function"==typeof o?o(n._unwrap(e)):o)?r:"json"},this._marshalFind=function(e){var t,r,o,i=n._unwrap(e);return null!=(t=null!=(r=null!=(o=n._registeredMap.get(e))?o:i!==e?n._registeredMap.get(i):void 0)?r:n._map.get(e))?t:i!==e?n._map.get(i):void 0},this._marshalPre=function(e,t,r){var o;if("json"!==r)return null==(o=n._register(e,t,n._map))?void 0:o[1]},this._marshalPreApply=function(e,t,r){var o=s(t)?n._unwrap(t):void 0;o&&n._temporalSync.add(o);try{return e.apply(t,r)}finally{o&&n._temporalSync.delete(o)}},this._marshal=function(e){var t,r=n._registeredMap.get(e);if(r)return[r,!1];var o=h(null!=(t=n._wrap(e))?t:e,{vm:n.vm,unmarshal:n._unmarshal,isMarshalable:n._isMarshalable,find:n._marshalFind,pre:n._marshalPre,preApply:n._marshalPreApply});return[o,!n._map.hasHandle(o)]},this._preUnmarshal=function(e,t){var r;return null==(r=n._register(e,t,void 0,!0))?void 0:r[0]},this._unmarshalFind=function(e){var t;return null!=(t=n._registeredMap.getByHandle(e))?t:n._map.getByHandle(e)},this._unmarshal=function(e){var t=n._registeredMap.getByHandle(e);if(void 0!==t)return t;var r=n._wrapHandle(e)[0];return _(null!=r?r:e,{vm:n.vm,marshal:n._marshal,find:n._unmarshalFind,pre:n._preUnmarshal})},this._syncMode=function(e){var t=n._unwrap(e);return n._sync.has(t)||n._temporalSync.has(t)?"both":void 0},this._unwrapIfNotSynced=function(e){var t=n._unwrap(e);return n._sync.has(t)?e:t},this.vm=e,this._options=t,this._symbolHandle=e.unwrapResult(e.evalCode("Symbol()")),this._map=new i(e),this._registeredMap=new i(e),this.registerAll(null!=(r=null==t?void 0:t.registeredObjects)?r:S)}var t=e.prototype;return t.dispose=function(){this._map.dispose(),this._registeredMap.dispose(),this._symbolHandle.dispose()},t.evalCode=function(e){var t=this.vm.evalCode(e);return this._unwrapResultAndUnmarshal(t)},t.executePendingJobs=function(e){var t=this.vm.executePendingJobs(e);if("value"in t)return t.value;throw this._unwrapIfNotSynced(t.error.consume(this._unmarshal))},t.expose=function(e){for(var t=this,r=0,n=Object.entries(e);r<n.length;r++)i=(o=n[r])[0],function(e,r){var n=e[0],o=e[1];try{!function(e){t.vm.setProp(t.vm.global,i,e)}(n)}finally{o&&n.dispose()}}(t._marshal(o[1]));var o,i},t.sync=function(e){var t=this,r=this._wrap(e);return void 0===r?e:(u(r,function(e){t._sync.add(t._unwrap(e))}),r)},t.register=function(e,t){if(!this._registeredMap.has(e)){var r="string"==typeof t?this._unwrapResult(this.vm.evalCode(t)):t;p(this.vm,r,this.vm.undefined)||("string"==typeof t&&this._registeredMapDispose.add(e),this._registeredMap.set(e,r))}},t.registerAll=function(e){for(var t,r=o(e);!(t=r()).done;){var n=t.value;this.register(n[0],n[1])}},t.unregister=function(e,t){this._registeredMap.delete(e,this._registeredMapDispose.has(e)||t),this._registeredMapDispose.delete(e)},t.unregisterAll=function(e,t){for(var r,n=o(e);!(r=n()).done;)this.unregister(r.value,t)},t.startSync=function(e){s(e)&&this._sync.add(this._unwrap(e))},t.endSync=function(e){this._sync.delete(this._unwrap(e))},t._unwrapResult=function(e){if("value"in e)return e.value;throw this._unwrapIfNotSynced(e.error.consume(this._unmarshal))},t._unwrapResultAndUnmarshal=function(e){if(e)return this._unwrapIfNotSynced(this._unwrapResult(e).consume(this._unmarshal))},t._register=function(e,t,r,n){if(void 0===r&&(r=this._map),!this._registeredMap.has(e)&&!this._registeredMap.hasHandle(t)){var o=this._wrap(e),i=this._wrapHandle(t)[0];if(o&&i){var a=this._unwrap(e),s=this._unwrapHandle(t),u=s[0],l=s[1];if(!r.set(o,i,a,u))throw l&&u.dispose(),new Error("already registered");return n&&this._sync.add(a),[o,i]}}},t._wrap=function(e){return function(e,t,r,n,o,i){if(s(t)){if(u=r,s(a=t)&&a[u])return t;var a,u,p=new Proxy(t,{get:function(e,t){return t===r?e:Reflect.get(e,t)},set:function(t,a,s,u){var l,p=g(s,r),c=null!=(l=null==i?void 0:i(u))?l:"host";return"vm"!==c&&!Reflect.set(t,a,p,u)||"host"===c||!e.alive||d([o(u),o(a),o(p)],function(t,r,o){var i=w(e,t,n),a=i[0];i[1]?a.consume(function(t){return e.setProp(t,r,o)}):e.setProp(a,r,o)}),!0},deleteProperty:function(t,r){var a,s=null!=(a=null==i?void 0:i(p))?a:"host";return d([o(p),o(r)],function(o,i){var a=w(e,o,n),u=a[0],p=a[1];if("vm"===s||Reflect.deleteProperty(t,r)){if("host"===s||!e.alive)return!0;p?u.consume(function(t){return l(e,"(a, b) => delete a[b]",void 0,t,i)}):l(e,"(a, b) => delete a[b]",void 0,u,i)}return!0})}});return p}}(this.vm,e,this._symbol,this._symbolHandle,this._marshal,this._syncMode)},t._unwrap=function(e){return g(e,this._symbol)},t._wrapHandle=function(e){return function(e,t,r,n,o,i){return c(e,t)?j(e,t,n)?[t,!1]:v([e.newFunction("getSyncMode",function(t){var r=null==i?void 0:i(o(t));return"string"==typeof r?e.newString(r):e.undefined}),e.newFunction("setter",function(e,t,n){var i=o(e);if(i){var a=o(t);if("__proto__"!==a){var s=o(n);g(i,r)[a]=s}}}),e.newFunction("deleter",function(e,t){var n=o(e);if(n){var i=o(t);delete g(n,r)[i]}})],function(r){return[l.apply(void 0,[e,'(target, sym, getSyncMode, setter, deleter) => {\n const rec = new Proxy(target, {\n get(obj, key, receiver) {\n return key === sym ? obj : Reflect.get(obj, key, receiver)\n },\n set(obj, key, value, receiver) {\n const v = typeof value === "object" && value !== null || typeof value === "function"\n ? value[sym] ?? value\n : value;\n const sync = getSyncMode(receiver) ?? "vm";\n if (sync === "host" || Reflect.set(obj, key, v, receiver)) {\n if (sync !== "vm") {\n setter(receiver, key, v);\n }\n }\n return true;\n },\n deleteProperty(obj, key) {\n const sync = getSyncMode(rec) ?? "vm";\n if (sync === "host" || Reflect.deleteProperty(obj, key)) {\n if (sync !== "vm") {\n deleter(rec, key);\n }\n }\n return true;\n },\n });\n return rec;\n }',void 0,t,n].concat(r)),!0]}):[void 0,!1]}(this.vm,e,this._symbol,this._symbolHandle,this._unmarshal,this._syncMode)},t._unwrapHandle=function(e){return w(this.vm,e,this._symbolHandle)},e}(),exports.VMMap=i,exports.call=l,exports.complexity=function(e,t){return u(e,t?function(e,r){return r.size<t}:void 0).size},exports.consumeAll=v,exports.defaultRegisteredObjects=S,exports.eq=p,exports.isES2015Class=a,exports.isHandleObject=c,exports.isObject=s,exports.json=f,exports.marshal=h,exports.unmarshal=_,exports.walkObject=u;
|
|
2
|
-
//# sourceMappingURL=quickjs-emscripten-sync.cjs.map
|