quickjs-emscripten-sync 1.4.0 → 1.5.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/README.md +28 -7
- package/dist/index.d.ts +12 -7
- package/dist/quickjs-emscripten-sync.mjs +842 -0
- package/dist/quickjs-emscripten-sync.umd.js +15 -15
- package/package.json +9 -18
- package/src/default.ts +2 -2
- package/src/index.test.ts +21 -13
- package/src/index.ts +30 -43
- package/src/marshal/custom.test.ts +50 -0
- package/src/marshal/custom.ts +36 -0
- package/src/marshal/function.test.ts +17 -37
- package/src/marshal/function.ts +8 -12
- package/src/marshal/index.test.ts +35 -39
- package/src/marshal/index.ts +6 -9
- package/src/marshal/json.test.ts +9 -15
- package/src/marshal/json.ts +1 -4
- package/src/marshal/object.test.ts +19 -51
- package/src/marshal/object.ts +3 -11
- package/src/marshal/primitive.test.ts +4 -13
- package/src/marshal/primitive.ts +1 -1
- package/src/marshal/promise.test.ts +9 -10
- package/src/marshal/promise.ts +4 -11
- package/src/marshal/properties.test.ts +7 -14
- package/src/marshal/properties.ts +6 -9
- package/src/unmarshal/custom.test.ts +50 -0
- package/src/unmarshal/custom.ts +31 -0
- package/src/unmarshal/function.test.ts +20 -44
- package/src/unmarshal/function.ts +7 -17
- package/src/unmarshal/index.test.ts +30 -23
- package/src/unmarshal/index.ts +4 -6
- package/src/unmarshal/object.test.ts +9 -17
- package/src/unmarshal/object.ts +7 -12
- package/src/unmarshal/primitive.test.ts +1 -4
- package/src/unmarshal/primitive.ts +3 -10
- package/src/unmarshal/promise.test.ts +3 -3
- package/src/unmarshal/promise.ts +3 -10
- package/src/unmarshal/properties.test.ts +2 -2
- package/src/unmarshal/properties.ts +4 -8
- package/src/util.test.ts +1 -7
- package/src/util.ts +3 -8
- package/src/vmmap.ts +13 -31
- package/src/vmutil.test.ts +15 -29
- package/src/vmutil.ts +12 -39
- package/src/wrapper.test.ts +27 -90
- package/src/wrapper.ts +43 -50
- package/dist/quickjs-emscripten-sync.es.js +0 -962
- package/src/marshal/symbol.test.ts +0 -24
- package/src/marshal/symbol.ts +0 -21
- package/src/unmarshal/symbol.test.ts +0 -25
- package/src/unmarshal/symbol.ts +0 -12
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { getQuickJS } from "quickjs-emscripten";
|
|
2
|
-
import { expect, test, vi } from "vitest";
|
|
3
|
-
|
|
4
|
-
import marshalSymbol from "./symbol";
|
|
5
|
-
|
|
6
|
-
test("works", async () => {
|
|
7
|
-
const ctx = (await getQuickJS()).newContext();
|
|
8
|
-
const pre = vi.fn();
|
|
9
|
-
const sym = Symbol("foobar");
|
|
10
|
-
|
|
11
|
-
expect(marshalSymbol(ctx, {}, pre)).toBe(undefined);
|
|
12
|
-
expect(pre).toBeCalledTimes(0);
|
|
13
|
-
|
|
14
|
-
const handle = marshalSymbol(ctx, sym, pre);
|
|
15
|
-
if (!handle) throw new Error("handle is undefined");
|
|
16
|
-
expect(ctx.typeof(handle)).toBe("symbol");
|
|
17
|
-
expect(ctx.getString(ctx.getProp(handle, "description"))).toBe("foobar");
|
|
18
|
-
expect(pre).toReturnTimes(1);
|
|
19
|
-
expect(pre.mock.calls[0][0]).toBe(sym);
|
|
20
|
-
expect(pre.mock.calls[0][1] === handle).toBe(true);
|
|
21
|
-
|
|
22
|
-
handle.dispose();
|
|
23
|
-
ctx.dispose();
|
|
24
|
-
});
|
package/src/marshal/symbol.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { QuickJSContext, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
-
|
|
3
|
-
import { call } from "../vmutil";
|
|
4
|
-
|
|
5
|
-
export default function marshalSymbol(
|
|
6
|
-
ctx: QuickJSContext,
|
|
7
|
-
target: unknown,
|
|
8
|
-
preMarshal: (
|
|
9
|
-
target: unknown,
|
|
10
|
-
handle: QuickJSHandle
|
|
11
|
-
) => QuickJSHandle | undefined
|
|
12
|
-
): QuickJSHandle | undefined {
|
|
13
|
-
if (typeof target !== "symbol") return;
|
|
14
|
-
const handle = call(
|
|
15
|
-
ctx,
|
|
16
|
-
"d => Symbol(d)",
|
|
17
|
-
undefined,
|
|
18
|
-
target.description ? ctx.newString(target.description) : ctx.undefined
|
|
19
|
-
);
|
|
20
|
-
return preMarshal(target, handle) ?? handle;
|
|
21
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { getQuickJS } from "quickjs-emscripten";
|
|
2
|
-
import { expect, test, vi } from "vitest";
|
|
3
|
-
|
|
4
|
-
import unmarshalSymbol from "./symbol";
|
|
5
|
-
|
|
6
|
-
test("works", async () => {
|
|
7
|
-
const ctx = (await getQuickJS()).newContext();
|
|
8
|
-
const pre = vi.fn();
|
|
9
|
-
const obj = ctx.newObject();
|
|
10
|
-
const handle = ctx.unwrapResult(ctx.evalCode(`Symbol("foobar")`));
|
|
11
|
-
|
|
12
|
-
expect(unmarshalSymbol(ctx, obj, pre)).toBe(undefined);
|
|
13
|
-
expect(pre).toBeCalledTimes(0);
|
|
14
|
-
|
|
15
|
-
const sym = unmarshalSymbol(ctx, handle, pre);
|
|
16
|
-
expect(typeof sym).toBe("symbol");
|
|
17
|
-
expect((sym as any).description).toBe("foobar");
|
|
18
|
-
expect(pre).toReturnTimes(1);
|
|
19
|
-
expect(pre.mock.calls[0][0]).toBe(sym);
|
|
20
|
-
expect(pre.mock.calls[0][1] === handle).toBe(true);
|
|
21
|
-
|
|
22
|
-
handle.dispose();
|
|
23
|
-
obj.dispose();
|
|
24
|
-
ctx.dispose();
|
|
25
|
-
});
|
package/src/unmarshal/symbol.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { QuickJSContext, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
-
|
|
3
|
-
export default function unmarshalSymbol(
|
|
4
|
-
ctx: QuickJSContext,
|
|
5
|
-
handle: QuickJSHandle,
|
|
6
|
-
preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined
|
|
7
|
-
): symbol | undefined {
|
|
8
|
-
if (ctx.typeof(handle) !== "symbol") return;
|
|
9
|
-
const desc = ctx.getString(ctx.getProp(handle, "description"));
|
|
10
|
-
const sym = Symbol(desc);
|
|
11
|
-
return preUnmarshal(sym, handle) ?? sym;
|
|
12
|
-
}
|