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.
Files changed (51) hide show
  1. package/README.md +60 -37
  2. package/dist/index.d.ts +29 -22
  3. package/dist/quickjs-emscripten-sync.mjs +842 -0
  4. package/dist/quickjs-emscripten-sync.umd.js +15 -15
  5. package/package.json +12 -21
  6. package/src/default.ts +2 -2
  7. package/src/index.test.ts +159 -65
  8. package/src/index.ts +67 -66
  9. package/src/marshal/custom.test.ts +50 -0
  10. package/src/marshal/custom.ts +36 -0
  11. package/src/marshal/function.test.ts +60 -72
  12. package/src/marshal/function.ts +15 -18
  13. package/src/marshal/index.test.ts +88 -84
  14. package/src/marshal/index.ts +16 -18
  15. package/src/marshal/json.test.ts +32 -38
  16. package/src/marshal/json.ts +5 -7
  17. package/src/marshal/object.test.ts +52 -79
  18. package/src/marshal/object.ts +8 -15
  19. package/src/marshal/primitive.test.ts +16 -21
  20. package/src/marshal/primitive.ts +11 -10
  21. package/src/marshal/promise.test.ts +21 -22
  22. package/src/marshal/promise.ts +6 -13
  23. package/src/marshal/properties.test.ts +21 -26
  24. package/src/marshal/properties.ts +15 -17
  25. package/src/unmarshal/custom.test.ts +50 -0
  26. package/src/unmarshal/custom.ts +31 -0
  27. package/src/unmarshal/function.test.ts +52 -74
  28. package/src/unmarshal/function.ts +13 -22
  29. package/src/unmarshal/index.test.ts +58 -50
  30. package/src/unmarshal/index.ts +12 -13
  31. package/src/unmarshal/object.test.ts +37 -43
  32. package/src/unmarshal/object.ts +16 -20
  33. package/src/unmarshal/primitive.test.ts +15 -15
  34. package/src/unmarshal/primitive.ts +11 -18
  35. package/src/unmarshal/promise.test.ts +13 -13
  36. package/src/unmarshal/promise.ts +10 -19
  37. package/src/unmarshal/properties.test.ts +8 -8
  38. package/src/unmarshal/properties.ts +44 -45
  39. package/src/util.test.ts +2 -7
  40. package/src/util.ts +3 -8
  41. package/src/vmmap.test.ts +72 -88
  42. package/src/vmmap.ts +26 -44
  43. package/src/vmutil.test.ts +73 -89
  44. package/src/vmutil.ts +24 -47
  45. package/src/wrapper.test.ts +108 -148
  46. package/src/wrapper.ts +59 -62
  47. package/dist/quickjs-emscripten-sync.es.js +0 -951
  48. package/src/marshal/symbol.test.ts +0 -24
  49. package/src/marshal/symbol.ts +0 -20
  50. package/src/unmarshal/symbol.test.ts +0 -25
  51. 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 vm = (await getQuickJS()).createVm();
8
- const pre = vi.fn();
9
- const sym = Symbol("foobar");
10
-
11
- expect(marshalSymbol(vm, {}, pre)).toBe(undefined);
12
- expect(pre).toBeCalledTimes(0);
13
-
14
- const handle = marshalSymbol(vm, sym, pre);
15
- if (!handle) throw new Error("handle is undefined");
16
- expect(vm.typeof(handle)).toBe("symbol");
17
- expect(vm.getString(vm.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
- vm.dispose();
24
- });
@@ -1,20 +0,0 @@
1
- import { QuickJSVm, QuickJSHandle } from "quickjs-emscripten";
2
- import { call } from "../vmutil";
3
-
4
- export default function marshalSymbol(
5
- vm: QuickJSVm,
6
- target: unknown,
7
- preMarshal: (
8
- target: unknown,
9
- handle: QuickJSHandle
10
- ) => QuickJSHandle | undefined
11
- ): QuickJSHandle | undefined {
12
- if (typeof target !== "symbol") return;
13
- const handle = call(
14
- vm,
15
- "d => Symbol(d)",
16
- undefined,
17
- target.description ? vm.newString(target.description) : vm.undefined
18
- );
19
- return preMarshal(target, handle) ?? handle;
20
- }
@@ -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 vm = (await getQuickJS()).createVm();
8
- const pre = vi.fn();
9
- const obj = vm.newObject();
10
- const handle = vm.unwrapResult(vm.evalCode(`Symbol("foobar")`));
11
-
12
- expect(unmarshalSymbol(vm, obj, pre)).toBe(undefined);
13
- expect(pre).toBeCalledTimes(0);
14
-
15
- const sym = unmarshalSymbol(vm, 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
- vm.dispose();
25
- });
@@ -1,12 +0,0 @@
1
- import { QuickJSVm, QuickJSHandle } from "quickjs-emscripten";
2
-
3
- export default function unmarshalSymbol(
4
- vm: QuickJSVm,
5
- handle: QuickJSHandle,
6
- preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined
7
- ): symbol | undefined {
8
- if (vm.typeof(handle) !== "symbol") return;
9
- const desc = vm.getString(vm.getProp(handle, "description"));
10
- const sym = Symbol(desc);
11
- return preUnmarshal(sym, handle) ?? sym;
12
- }