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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quickjs-emscripten-sync.module.js","sources":["../src/vmmap.ts","../src/util.ts","../src/vmutil.ts","../src/marshal/properties.ts","../src/marshal/index.ts","../src/marshal/primitive.ts","../src/marshal/json.ts","../src/marshal/symbol.ts","../src/marshal/function.ts","../src/marshal/object.ts","../src/unmarshal/properties.ts","../src/unmarshal/index.ts","../src/unmarshal/primitive.ts","../src/unmarshal/symbol.ts","../src/unmarshal/function.ts","../src/unmarshal/object.ts","../src/wrapper.ts","../src/default.ts","../src/index.ts"],"sourcesContent":["import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\n\nexport default class VMMap {\n vm: QuickJSVm;\n _map1: Map<any, number> = new Map();\n _map2: Map<any, number> = new Map();\n _map3: Map<number, QuickJSHandle> = new Map();\n _map4: Map<number, QuickJSHandle> = new Map();\n _counterMap: Map<number, any> = new Map();\n _disposables: Set<QuickJSHandle> = new Set();\n _mapGet: QuickJSHandle;\n _mapSet: QuickJSHandle;\n _mapDelete: QuickJSHandle;\n _mapClear: QuickJSHandle;\n _counter = 0;\n\n constructor(vm: QuickJSVm) {\n this.vm = vm;\n\n const result = vm\n .unwrapResult(\n vm.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 }`)\n )\n .consume((fn) => this._call(fn, undefined));\n\n this._mapGet = vm.getProp(result, \"get\");\n this._mapSet = vm.getProp(result, \"set\");\n this._mapDelete = vm.getProp(result, \"delete\");\n this._mapClear = vm.getProp(result, \"clear\");\n\n result.dispose();\n\n this._disposables.add(this._mapGet);\n this._disposables.add(this._mapSet);\n this._disposables.add(this._mapDelete);\n this._disposables.add(this._mapClear);\n }\n\n set(\n key: any,\n handle: QuickJSHandle,\n key2?: any,\n handle2?: QuickJSHandle\n ): boolean {\n if (!handle.alive || (handle2 && !handle2.alive)) return false;\n\n const v = this.get(key) ?? this.get(key2);\n if (v) {\n // handle and handle2 are unused so they should be disposed\n return v === handle || v === handle2;\n }\n\n const counter = this._counter++;\n this._map1.set(key, counter);\n this._map3.set(counter, handle);\n this._counterMap.set(counter, key);\n if (key2) {\n this._map2.set(key2, counter);\n if (handle2) {\n this._map4.set(counter, handle2);\n }\n }\n\n this.vm.newNumber(counter).consume((c) => {\n this._call(\n this._mapSet,\n undefined,\n handle,\n c,\n handle2 ?? this.vm.undefined\n );\n });\n\n return true;\n }\n\n merge(\n iteratable:\n | Iterable<\n | [any, QuickJSHandle | undefined]\n | [any, QuickJSHandle | undefined, any, QuickJSHandle | undefined]\n >\n | undefined\n ) {\n if (!iteratable) return;\n for (const iter of iteratable) {\n if (!iter) continue;\n if (iter[1]) {\n this.set(iter[0], iter[1], iter[2], iter[3]);\n }\n }\n }\n\n get(key: any) {\n const num = this._map1.get(key) ?? this._map2.get(key);\n const handle = typeof num === \"number\" ? this._map3.get(num) : undefined;\n\n if (!handle) return;\n if (!handle.alive) {\n this.delete(key);\n return;\n }\n\n return handle;\n }\n\n getByHandle(handle: QuickJSHandle) {\n if (!handle.alive) {\n return;\n }\n return this._counterMap.get(\n this.vm.getNumber(this._call(this._mapGet, undefined, handle))\n );\n }\n\n has(key: any) {\n return !!this.get(key);\n }\n\n hasHandle(handle: QuickJSHandle) {\n return typeof this.getByHandle(handle) !== \"undefined\";\n }\n\n delete(key: any, dispose?: boolean) {\n const num = this._map1.get(key) ?? this._map2.get(key);\n if (typeof num === \"undefined\") return;\n\n const handle = this._map3.get(num);\n const handle2 = this._map4.get(num);\n this._call(\n this._mapDelete,\n undefined,\n ...[handle, handle2].filter((h): h is QuickJSHandle => !!h?.alive)\n );\n\n this._map1.delete(key);\n this._map2.delete(key);\n this._map3.delete(num);\n this._map4.delete(num);\n\n for (const [k, v] of this._map1) {\n if (v === num) {\n this._map1.delete(k);\n break;\n }\n }\n\n for (const [k, v] of this._map2) {\n if (v === num) {\n this._map2.delete(k);\n break;\n }\n }\n\n for (const [k, v] of this._counterMap) {\n if (v === key) {\n this._counterMap.delete(k);\n break;\n }\n }\n\n if (dispose) {\n if (handle?.alive) handle.dispose();\n if (handle2?.alive) handle2.dispose();\n }\n }\n\n deleteByHandle(handle: QuickJSHandle, dispose?: boolean) {\n const key = this.getByHandle(handle);\n if (typeof key !== \"undefined\") {\n this.delete(key, dispose);\n }\n }\n\n clear() {\n this._counter = 0;\n this._map1.clear();\n this._map2.clear();\n this._map3.clear();\n this._map4.clear();\n this._counterMap.clear();\n if (this._mapClear.alive) {\n this._call(this._mapClear, undefined);\n }\n }\n\n dispose() {\n for (const v of this._disposables.values()) {\n if (v.alive) {\n v.dispose();\n }\n }\n for (const v of this._map3.values()) {\n if (v.alive) {\n v.dispose();\n }\n }\n for (const v of this._map4.values()) {\n if (v.alive) {\n v.dispose();\n }\n }\n this._disposables.clear();\n this.clear();\n }\n\n get size() {\n return this._map1.size;\n }\n\n [Symbol.iterator](): Iterator<\n [any, QuickJSHandle, any, QuickJSHandle | undefined]\n > {\n const keys = this._map1.keys();\n return {\n next: () => {\n while (true) {\n const k1 = keys.next();\n if (k1.done) return { value: undefined, done: true };\n const n = this._map1.get(k1.value);\n if (typeof n === \"undefined\") continue;\n const v1 = this._map3.get(n);\n const v2 = this._map4.get(n);\n if (!v1) continue;\n const k2 = this._get2(n);\n return { value: [k1.value, v1, k2, v2], done: false };\n }\n },\n };\n }\n\n _get2(num: number) {\n for (const [k, v] of this._map2) {\n if (v === num) return k;\n }\n }\n\n _call(\n fn: QuickJSHandle,\n thisArg: QuickJSHandle | undefined,\n ...args: QuickJSHandle[]\n ) {\n return this.vm.unwrapResult(\n this.vm.callFunction(\n fn,\n typeof thisArg === \"undefined\" ? this.vm.undefined : thisArg,\n ...args\n )\n );\n }\n}\n","export function isES2015Class(cls: any): cls is new (...args: any[]) => any {\n return (\n typeof cls === \"function\" &&\n /^class\\s/.test(Function.prototype.toString.call(cls))\n );\n}\n\nexport function isObject(value: any): value is object | Function {\n return (\n typeof value === \"function\" || (typeof value === \"object\" && value !== null)\n );\n}\n\nexport function walkObject(\n value: any,\n callback?: (target: any, set: Set<any>) => boolean | void\n): Set<any> {\n const set = new Set<any>();\n const walk = (v: any) => {\n if (!isObject(v) || set.has(v) || callback?.(v, set) === false) return;\n set.add(v);\n\n if (Array.isArray(v)) {\n for (const e of v) {\n walk(e);\n }\n return;\n }\n\n if (typeof v === \"object\") {\n const proto = Object.getPrototypeOf(v);\n if (proto && proto !== Object.prototype) {\n walk(proto);\n }\n }\n\n for (const d of Object.values(Object.getOwnPropertyDescriptors(v))) {\n if (\"value\" in d) walk(d.value);\n if (\"get\" in d) walk(d.get);\n if (\"set\" in d) walk(d.set);\n }\n };\n\n walk(value);\n return set;\n}\n\n/**\n * 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.\n */\nexport function complexity(value: any, max?: number): number {\n return walkObject(value, max ? (_, set) => set.size < max : undefined).size;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\n\nexport function call(\n vm: QuickJSVm,\n code: string,\n thisArg?: QuickJSHandle,\n ...args: QuickJSHandle[]\n): QuickJSHandle {\n return vm.unwrapResult(vm.evalCode(code)).consume((f) => {\n if (typeof thisArg === \"undefined\" && args.length === 0) return f;\n return vm.unwrapResult(\n vm.callFunction(f, thisArg ?? vm.undefined, ...args)\n );\n });\n}\n\nexport function eq(vm: QuickJSVm, a: QuickJSHandle, b: QuickJSHandle): boolean {\n return vm.dump(call(vm, \"Object.is\", undefined, a, b));\n}\n\nexport function instanceOf(\n vm: QuickJSVm,\n a: QuickJSHandle,\n b: QuickJSHandle\n): boolean {\n return vm.dump(call(vm, \"(a, b) => a instanceof b\", undefined, a, b));\n}\n\nexport function isHandleObject(vm: QuickJSVm, a: QuickJSHandle): boolean {\n return vm.dump(\n call(\n vm,\n `a => typeof a === \"object\" && a !== null || typeof a === \"function\"`,\n undefined,\n a\n )\n );\n}\n\nexport function json(vm: QuickJSVm, target: any): QuickJSHandle {\n const json = JSON.stringify(target);\n if (!json) return vm.undefined;\n return call(vm, `JSON.parse`, undefined, vm.newString(json));\n}\n\nexport function consumeAll<T extends QuickJSHandle[], K>(\n handles: T,\n cb: (handles: T) => K\n): K {\n try {\n return cb(handles);\n } finally {\n for (const h of handles) {\n if (h.alive) h.dispose();\n }\n }\n}\n\nexport function mayConsume<T>(\n [handle, shouldBeDisposed]: [QuickJSHandle, boolean],\n fn: (h: QuickJSHandle) => T\n) {\n try {\n return fn(handle);\n } finally {\n if (shouldBeDisposed) {\n handle.dispose();\n }\n }\n}\n\nexport function mayConsumeAll<T, H extends QuickJSHandle[]>(\n handles: { [P in keyof H]: [QuickJSHandle, boolean] },\n fn: (...args: H) => T\n) {\n try {\n return fn(...(handles.map((h) => h[0]) as H));\n } finally {\n for (const [handle, shouldBeDisposed] of handles) {\n if (shouldBeDisposed) {\n handle.dispose();\n }\n }\n }\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { call } from \"../vmutil\";\n\nexport default function marshalProperties(\n vm: QuickJSVm,\n target: object | Function,\n handle: QuickJSHandle,\n marshal: (target: unknown) => QuickJSHandle\n): void {\n const descs = vm.newObject();\n const cb = (key: string | number | symbol, desc: PropertyDescriptor) => {\n const keyHandle = marshal(key);\n const valueHandle =\n typeof desc.value === \"undefined\" ? undefined : marshal(desc.value);\n const getHandle =\n typeof desc.get === \"undefined\" ? undefined : marshal(desc.get);\n const setHandle =\n typeof desc.set === \"undefined\" ? undefined : marshal(desc.set);\n\n vm.newObject().consume((descObj) => {\n Object.entries(desc).forEach(([k, v]) => {\n const v2 =\n k === \"value\"\n ? valueHandle\n : k === \"get\"\n ? getHandle\n : k === \"set\"\n ? setHandle\n : v\n ? vm.true\n : vm.false;\n if (v2) {\n vm.setProp(descObj, k, v2);\n }\n });\n vm.setProp(descs, keyHandle, descObj);\n });\n };\n\n const desc = Object.getOwnPropertyDescriptors(target);\n Object.entries(desc).forEach(([k, v]) => cb(k, v));\n Object.getOwnPropertySymbols(desc).forEach((k) => cb(k, (desc as any)[k]));\n\n call(vm, `Object.defineProperties`, undefined, handle, descs).dispose();\n\n descs.dispose();\n}\n","import { QuickJSHandle, QuickJSVm } from \"quickjs-emscripten\";\nimport marshalFunction from \"./function\";\nimport marshalObject from \"./object\";\nimport marshalPrimitive from \"./primitive\";\nimport marshalSymbol from \"./symbol\";\nimport marshalJSON from \"./json\";\n\nexport type Options = {\n vm: QuickJSVm;\n unmarshal: (handle: QuickJSHandle) => unknown;\n isMarshalable?: (target: unknown) => boolean | \"json\";\n find: (target: unknown) => QuickJSHandle | undefined;\n pre: (\n target: unknown,\n handle: QuickJSHandle,\n mode: true | \"json\" | undefined\n ) => QuickJSHandle | undefined;\n preApply?: (target: Function, thisArg: unknown, args: unknown[]) => any;\n};\n\nexport function marshal(target: unknown, options: Options): QuickJSHandle {\n const { vm, unmarshal, isMarshalable, find, pre } = options;\n\n {\n const primitive = marshalPrimitive(vm, target);\n if (primitive) {\n return primitive;\n }\n }\n\n {\n const handle = find(target);\n if (handle) return handle;\n }\n\n const marshalable = isMarshalable?.(target);\n if (marshalable === false) {\n return vm.undefined;\n }\n\n const pre2 = (target: any, handle: QuickJSHandle) =>\n pre(target, handle, marshalable);\n if (marshalable === \"json\") {\n return marshalJSON(vm, target, pre2);\n }\n\n const marshal2 = (t: unknown) => marshal(t, options);\n return (\n marshalSymbol(vm, target, pre2) ??\n marshalFunction(vm, target, marshal2, unmarshal, pre2, options.preApply) ??\n marshalObject(vm, target, marshal2, pre2) ??\n vm.undefined\n );\n}\n\nexport default marshal;\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\n// import { call } from \"../vmutil\";\n\nexport default function marshalPrimitive(\n vm: QuickJSVm,\n target: unknown\n): QuickJSHandle | undefined {\n switch (typeof target) {\n case \"undefined\":\n return vm.undefined;\n case \"number\":\n return vm.newNumber(target);\n case \"string\":\n return vm.newString(target);\n case \"boolean\":\n return target ? vm.true : vm.false;\n case \"object\":\n return target === null ? vm.null : undefined;\n\n // BigInt is not supported by quickjs-emscripten\n // case \"bigint\":\n // return call(\n // vm,\n // `s => BigInt(s)`,\n // undefined,\n // vm.newString(target.toString())\n // );\n }\n\n return undefined;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { json } from \"../vmutil\";\n\nexport default function marshalJSON(\n vm: QuickJSVm,\n target: unknown,\n preMarshal: (\n target: unknown,\n handle: QuickJSHandle\n ) => QuickJSHandle | undefined\n): QuickJSHandle {\n const raw = json(vm, target);\n const handle = preMarshal(target, raw) ?? raw;\n return handle;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { call } from \"../vmutil\";\n\nexport default function marshalSymbol(\n vm: QuickJSVm,\n target: unknown,\n preMarshal: (\n target: unknown,\n handle: QuickJSHandle\n ) => QuickJSHandle | undefined\n): QuickJSHandle | undefined {\n if (typeof target !== \"symbol\") return;\n const handle = call(\n vm,\n \"d => Symbol(d)\",\n undefined,\n target.description ? vm.newString(target.description) : vm.undefined\n );\n return preMarshal(target, handle) ?? handle;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { isES2015Class, isObject } from \"../util\";\nimport { call } from \"../vmutil\";\nimport marshalProperties from \"./properties\";\n\nexport default function marshalFunction(\n vm: QuickJSVm,\n target: unknown,\n marshal: (target: unknown) => QuickJSHandle,\n unmarshal: (handle: QuickJSHandle) => unknown,\n preMarshal: (\n target: unknown,\n handle: QuickJSHandle\n ) => QuickJSHandle | undefined,\n preApply?: (target: Function, thisArg: unknown, args: unknown[]) => any\n): QuickJSHandle | undefined {\n if (typeof target !== \"function\") return;\n\n const raw = vm\n .newFunction(target.name, function (...argHandles) {\n const that = unmarshal(this);\n const args = argHandles.map((a) => unmarshal(a));\n\n if (isES2015Class(target) && isObject(that)) {\n // Class constructors cannot be invoked without new expression, and new.target is not changed\n const result = new target(...args);\n Object.entries(result).forEach(([key, value]) => {\n vm.setProp(this, key, marshal(value));\n });\n return this;\n }\n\n return marshal(\n preApply ? preApply(target, that, args) : target.apply(that, args)\n );\n })\n .consume((handle2) =>\n // fucntions created by vm.newFunction are not callable as a class constrcutor\n call(\n vm,\n `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 }`,\n undefined,\n handle2\n )\n );\n\n const handle = preMarshal(target, raw) ?? raw;\n marshalProperties(vm, target, raw, marshal);\n\n return handle;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { call } from \"../vmutil\";\nimport marshalProperties from \"./properties\";\n\nexport default function marshalObject(\n vm: QuickJSVm,\n target: unknown,\n marshal: (target: unknown) => QuickJSHandle,\n preMarshal: (\n target: unknown,\n handle: QuickJSHandle\n ) => QuickJSHandle | undefined\n): QuickJSHandle | undefined {\n if (typeof target !== \"object\" || target === null) return;\n\n const raw = Array.isArray(target) ? vm.newArray() : vm.newObject();\n const handle = preMarshal(target, raw) ?? raw;\n\n // prototype\n const prototype = Object.getPrototypeOf(target);\n const prototypeHandle =\n prototype && prototype !== Object.prototype && prototype !== Array.prototype\n ? marshal(prototype)\n : undefined;\n if (prototypeHandle) {\n call(\n vm,\n \"Object.setPrototypeOf\",\n undefined,\n handle,\n prototypeHandle\n ).dispose();\n }\n\n marshalProperties(vm, target, raw, marshal);\n\n return handle;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { call } from \"../vmutil\";\n\nexport default function unmarshalProperties(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n target: object | Function,\n unmarshal: (handle: QuickJSHandle) => [unknown, boolean]\n) {\n vm.newFunction(\"\", (key, value) => {\n const [keyName] = unmarshal(key);\n if (\n typeof keyName !== \"string\" &&\n typeof keyName !== \"number\" &&\n typeof keyName !== \"symbol\"\n )\n return;\n\n const desc = (\n [\n [\"value\", true],\n [\"get\", true],\n [\"set\", true],\n [\"configurable\", false],\n [\"enumerable\", false],\n [\"writable\", false],\n ] as const\n ).reduce<PropertyDescriptor>((desc, [key, unmarshable]) => {\n const h = vm.getProp(value, key);\n const ty = vm.typeof(h);\n\n if (ty === \"undefined\") return desc;\n if (!unmarshable && ty === \"boolean\") {\n desc[key] = vm.dump(vm.getProp(value, key));\n return desc;\n }\n\n const [v, alreadyExists] = unmarshal(h);\n if (alreadyExists) {\n h.dispose();\n }\n desc[key] = v;\n\n return desc;\n }, {});\n\n Object.defineProperty(target, keyName, desc);\n }).consume((fn) => {\n call(\n vm,\n `(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 }`,\n undefined,\n handle,\n fn\n ).dispose();\n });\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport unmarshalFunction from \"./function\";\nimport unmarshalObject from \"./object\";\nimport unmarshalPrimitive from \"./primitive\";\nimport unmarshalSymbol from \"./symbol\";\n\nexport type Options = {\n vm: QuickJSVm;\n // marshal returns handle and boolean indicates that the handle should be disposed after use\n marshal: (target: unknown) => [QuickJSHandle, boolean];\n find: (handle: QuickJSHandle) => unknown | undefined;\n pre: <T>(target: T, handle: QuickJSHandle) => T | undefined;\n};\n\nexport function unmarshal(handle: QuickJSHandle, options: Options): any {\n const [result] = unmarshalInner(handle, options);\n return result;\n}\n\nfunction unmarshalInner(\n handle: QuickJSHandle,\n options: Options\n): [any, boolean] {\n const { vm, marshal, find, pre } = options;\n\n {\n const [target, ok] = unmarshalPrimitive(vm, handle);\n if (ok) return [target, false];\n }\n\n {\n const target = find(handle);\n if (target) {\n return [target, true];\n }\n }\n\n const unmarshal2 = (h: QuickJSHandle) => unmarshalInner(h, options);\n\n const result =\n unmarshalSymbol(vm, handle, pre) ??\n unmarshalFunction(vm, handle, marshal, unmarshal2, pre) ??\n unmarshalObject(vm, handle, unmarshal2, pre);\n\n return [result, false];\n}\n\nexport default unmarshal;\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\n\nexport default function unmarshalPrimitive(\n vm: QuickJSVm,\n handle: QuickJSHandle\n): [any, boolean] {\n const ty = vm.typeof(handle);\n if (\n ty === \"undefined\" ||\n ty === \"number\" ||\n ty === \"string\" ||\n ty === \"boolean\"\n ) {\n return [vm.dump(handle), true];\n } else if (ty === \"object\") {\n const isNull = vm\n .unwrapResult(vm.evalCode(\"a => a === null\"))\n .consume((n) =>\n vm.dump(vm.unwrapResult(vm.callFunction(n, vm.undefined, handle)))\n );\n if (isNull) {\n return [null, true];\n }\n }\n\n // BigInt is not supported by quickjs-emscripten\n // if (ty === \"bigint\") {\n // const str = vm\n // .getProp(handle, \"toString\")\n // .consume(toString => vm.unwrapResult(vm.callFunction(toString, handle)))\n // .consume(str => vm.getString(str));\n // const bi = BigInt(str);\n // return [bi, true];\n // }\n\n return [undefined, false];\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\n\nexport default function unmarshalSymbol(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined\n): symbol | undefined {\n if (vm.typeof(handle) !== \"symbol\") return;\n const desc = vm.getString(vm.getProp(handle, \"description\"));\n const sym = Symbol(desc);\n return preUnmarshal(sym, handle) ?? sym;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { call, mayConsumeAll } from \"../vmutil\";\nimport unmarshalProperties from \"./properties\";\n\nexport default function unmarshalFunction(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n // marshal returns handle and boolean indicates that the handle should be disposed after use\n marshal: (value: unknown) => [QuickJSHandle, boolean],\n unmarshal: (handle: QuickJSHandle) => [unknown, boolean],\n preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined\n): Function | undefined {\n if (vm.typeof(handle) !== \"function\") return;\n\n const raw = function (this: any, ...args: any[]) {\n return mayConsumeAll(\n [marshal(this), ...args.map((a) => marshal(a))],\n (thisHandle, ...argHandles) => {\n if (new.target) {\n const [instance] = unmarshal(\n call(\n vm,\n `(Cls, ...args) => new Cls(...args)`,\n thisHandle,\n handle,\n ...argHandles\n )\n );\n Object.defineProperties(\n this,\n Object.getOwnPropertyDescriptors(instance)\n );\n return this;\n }\n\n const resultHandle = vm.unwrapResult(\n vm.callFunction(handle, thisHandle, ...argHandles)\n );\n\n const [result, alreadyExists] = unmarshal(resultHandle);\n if (alreadyExists) resultHandle.dispose();\n\n return result;\n }\n );\n };\n\n const func = preUnmarshal(raw, handle) ?? raw;\n unmarshalProperties(vm, handle, raw, unmarshal);\n\n return func;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport unmarshalProperties from \"./properties\";\nimport { call } from \"../vmutil\";\n\nexport default function unmarshalObject(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n unmarshal: (handle: QuickJSHandle) => [unknown, boolean],\n preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined\n): object | undefined {\n if (\n vm.typeof(handle) !== \"object\" ||\n // null check\n vm\n .unwrapResult(vm.evalCode(\"o => o === null\"))\n .consume((n) =>\n vm.dump(vm.unwrapResult(vm.callFunction(n, vm.undefined, handle)))\n )\n )\n return;\n\n const raw = call(vm, \"Array.isArray\", undefined, handle).consume((r) =>\n vm.dump(r)\n )\n ? []\n : {};\n const obj = preUnmarshal(raw, handle) ?? raw;\n\n const prototype = call(\n vm,\n `o => {\n const p = Object.getPrototypeOf(o);\n return !p || p === Object.prototype || p === Array.prototype ? undefined : p;\n }`,\n undefined,\n handle\n ).consume((prototype) => {\n if (vm.typeof(prototype) === \"undefined\") return;\n const [proto] = unmarshal(prototype);\n return proto;\n });\n if (typeof prototype === \"object\") {\n Object.setPrototypeOf(obj, prototype);\n }\n\n unmarshalProperties(vm, handle, raw, unmarshal);\n\n return obj;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { isObject } from \"./util\";\nimport { call, isHandleObject, consumeAll, mayConsumeAll } from \"./vmutil\";\n\nexport type SyncMode = \"both\" | \"vm\" | \"host\";\n\nexport type Wrapped<T> = T & { __qes_wrapped: never };\n\nexport function wrap<T = any>(\n vm: QuickJSVm,\n target: T,\n proxyKeySymbol: symbol,\n proxyKeySymbolHandle: QuickJSHandle,\n marshal: (target: any) => [QuickJSHandle, boolean],\n syncMode?: (target: T) => SyncMode | undefined\n): Wrapped<T> | undefined {\n if (!isObject(target)) return undefined;\n if (isWrapped(target, proxyKeySymbol)) return target;\n\n const rec = new Proxy(target as any, {\n get(obj, key) {\n return key === proxyKeySymbol ? obj : Reflect.get(obj, key);\n },\n set(obj, key, value, receiver) {\n const v = unwrap(value, proxyKeySymbol);\n const sync = syncMode?.(receiver) ?? \"host\";\n if (\n (sync !== \"vm\" && !Reflect.set(obj, key, v, receiver)) ||\n sync === \"host\" ||\n !vm.alive\n )\n return true;\n\n mayConsumeAll(\n [marshal(receiver), marshal(key), marshal(v)],\n (receiverHandle, keyHandle, valueHandle) => {\n const [handle2, unwrapped] = unwrapHandle(\n vm,\n receiverHandle,\n proxyKeySymbolHandle\n );\n if (unwrapped) {\n handle2.consume((h) => vm.setProp(h, keyHandle, valueHandle));\n } else {\n vm.setProp(handle2, keyHandle, valueHandle);\n }\n }\n );\n\n return true;\n },\n deleteProperty(obj, key) {\n const sync = syncMode?.(rec) ?? \"host\";\n return mayConsumeAll(\n [marshal(rec), marshal(key)],\n (recHandle, keyHandle) => {\n const [handle2, unwrapped] = unwrapHandle(\n vm,\n recHandle,\n proxyKeySymbolHandle\n );\n\n if (sync === \"vm\" || Reflect.deleteProperty(obj, key)) {\n if (sync === \"host\" || !vm.alive) return true;\n\n if (unwrapped) {\n handle2.consume((h) =>\n call(vm, `(a, b) => delete a[b]`, undefined, h, keyHandle)\n );\n } else {\n call(vm, `(a, b) => delete a[b]`, undefined, handle2, keyHandle);\n }\n }\n return true;\n }\n );\n },\n }) as Wrapped<T>;\n return rec;\n}\n\nexport function wrapHandle(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n proxyKeySymbol: symbol,\n proxyKeySymbolHandle: QuickJSHandle,\n unmarshal: (handle: QuickJSHandle) => any,\n syncMode?: (target: QuickJSHandle) => SyncMode | undefined\n): [Wrapped<QuickJSHandle> | undefined, boolean] {\n if (!isHandleObject(vm, handle)) return [undefined, false];\n if (isHandleWrapped(vm, handle, proxyKeySymbolHandle)) return [handle, false];\n\n return consumeAll(\n [\n vm.newFunction(\"getSyncMode\", (h) => {\n const res = syncMode?.(unmarshal(h));\n if (typeof res === \"string\") return vm.newString(res);\n return vm.undefined;\n }),\n vm.newFunction(\"setter\", (h, keyHandle, valueHandle) => {\n const target = unmarshal(h);\n if (!target) return;\n const key = unmarshal(keyHandle);\n if (key === \"__proto__\") return; // for security\n const value = unmarshal(valueHandle);\n unwrap(target, proxyKeySymbol)[key] = value;\n }),\n vm.newFunction(\"deleter\", (h, keyHandle) => {\n const target = unmarshal(h);\n if (!target) return;\n const key = unmarshal(keyHandle);\n delete unwrap(target, proxyKeySymbol)[key];\n }),\n ],\n (args) => [\n call(\n vm,\n `(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 }`,\n undefined,\n handle,\n proxyKeySymbolHandle,\n ...args\n ) as Wrapped<QuickJSHandle>,\n true,\n ]\n );\n}\n\nexport function unwrap<T>(obj: T, key: string | symbol): T {\n return isObject(obj) ? ((obj as any)[key] as T) ?? obj : obj;\n}\n\nexport function unwrapHandle(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n key: QuickJSHandle\n): [QuickJSHandle, boolean] {\n if (!isHandleWrapped(vm, handle, key)) return [handle, false];\n return [vm.getProp(handle, key), true];\n}\n\nexport function isWrapped<T>(obj: T, key: string | symbol): obj is Wrapped<T> {\n return isObject(obj) && !!(obj as any)[key];\n}\n\nexport function isHandleWrapped(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n key: QuickJSHandle\n): handle is Wrapped<QuickJSHandle> {\n return !!vm.dump(\n call(\n vm,\n `(a, s) => (typeof a === \"object\" && a !== null || typeof a === \"function\") && !!a[s]`,\n undefined,\n handle,\n key\n )\n );\n}\n","/**\n * Default value of registeredObjects option of the Arena class constructor.\n */\nexport const defaultRegisteredObjects: [any, string][] = [\n // basic objects\n [Symbol, \"Symbol\"],\n [Symbol.prototype, \"Symbol.prototype\"],\n [Object, \"Object\"],\n [Object.prototype, \"Object.prototype\"],\n [Function, \"Function\"],\n [Function.prototype, \"Function.prototype\"],\n [Boolean, \"Boolean\"],\n [Boolean.prototype, \"Boolean.prototype\"],\n [Array, \"Array\"],\n [Array.prototype, \"Array.prototype\"],\n // [BigInt, \"BigInt\"],\n // [BigInt.prototype, \"BigInt.prototype\"],\n // errors\n [Error, \"Error\"],\n [Error.prototype, \"Error.prototype\"],\n [EvalError, \"EvalError\"],\n [EvalError.prototype, \"EvalError.prototype\"],\n [RangeError, \"RangeError\"],\n [RangeError.prototype, \"RangeError.prototype\"],\n [ReferenceError, \"ReferenceError\"],\n [ReferenceError.prototype, \"ReferenceError.prototype\"],\n [SyntaxError, \"SyntaxError\"],\n [SyntaxError.prototype, \"SyntaxError.prototype\"],\n [TypeError, \"TypeError\"],\n [TypeError.prototype, \"TypeError.prototype\"],\n [URIError, \"URIError\"],\n [URIError.prototype, \"URIError.prototype\"],\n // built-in symbols\n ...Object.getOwnPropertyNames(Symbol)\n .filter((k) => typeof (Symbol as any)[k] === \"symbol\")\n .map<[any, string]>((k) => [(Symbol as any)[k], `Symbol.${k}`]),\n];\n","import { QuickJSHandle, QuickJSVm } from \"quickjs-emscripten\";\nimport {\n SuccessOrFail,\n VmCallResult,\n} from \"quickjs-emscripten/dist/vm-interface\";\n\nimport VMMap from \"./vmmap\";\nimport marshal from \"./marshal\";\nimport unmarshal from \"./unmarshal\";\nimport { wrap, wrapHandle, unwrap, unwrapHandle, Wrapped } from \"./wrapper\";\nimport { complexity, isES2015Class, isObject, walkObject } from \"./util\";\nimport {\n call,\n eq,\n isHandleObject,\n json,\n consumeAll,\n mayConsume,\n} from \"./vmutil\";\nimport { defaultRegisteredObjects } from \"./default\";\n\nexport {\n VMMap,\n defaultRegisteredObjects,\n marshal,\n unmarshal,\n complexity,\n isES2015Class,\n isObject,\n walkObject,\n call,\n eq,\n isHandleObject,\n json,\n consumeAll,\n};\n\nexport type Options = {\n /** 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. */\n isMarshalable?: boolean | \"json\" | ((target: any) => boolean | \"json\");\n /** You can pre-register a pair 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`.\n *\n * 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.\n */\n registeredObjects?: Iterable<[any, QuickJSHandle | string]>;\n};\n\n/**\n * The Arena class manages all generated handles at once by quickjs-emscripten and automatically converts objects between the host and the QuickJS VM.\n */\nexport class Arena {\n vm: QuickJSVm;\n _map: VMMap;\n _registeredMap: VMMap;\n _registeredMapDispose: Set<any> = new Set();\n _sync: Set<any> = new Set();\n _temporalSync: Set<any> = new Set();\n _symbol = Symbol();\n _symbolHandle: QuickJSHandle;\n _options?: Options;\n\n /** Constructs a new Arena instance. It requires a quickjs-emscripten VM initialized with `quickjs.createVM()`. */\n constructor(vm: QuickJSVm, options?: Options) {\n this.vm = vm;\n this._options = options;\n this._symbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));\n this._map = new VMMap(vm);\n this._registeredMap = new VMMap(vm);\n this.registerAll(options?.registeredObjects ?? defaultRegisteredObjects);\n }\n\n /**\n * Dispose of the arena and managed handles. This method won't dispose the VM itself, so the VM has to be disposed of manually.\n */\n dispose() {\n this._map.dispose();\n this._registeredMap.dispose();\n this._symbolHandle.dispose();\n }\n\n /**\n * Evaluate JS code in the VM 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.\n */\n evalCode<T = any>(code: string): T {\n const handle = this.vm.evalCode(code);\n return this._unwrapResultAndUnmarshal(handle);\n }\n\n /**\n * Almost same as `vm.executePendingJobs()`, but it converts and re-throws error objects when an error is thrown during evaluation.\n */\n executePendingJobs(maxJobsToExecute?: number): number {\n const result = this.vm.executePendingJobs(maxJobsToExecute);\n if (\"value\" in result) {\n return result.value;\n }\n throw this._unwrapIfNotSynced(result.error.consume(this._unmarshal));\n }\n\n /**\n * Expose objects as global objects in the VM.\n *\n * By default, exposed objects are not synchronized between the host and the VM.\n * If you want to sync an objects, first wrap the object with sync method, and then expose the wrapped object.\n */\n expose(obj: { [k: string]: any }) {\n for (const [key, value] of Object.entries(obj)) {\n mayConsume(this._marshal(value), (handle) => {\n this.vm.setProp(this.vm.global, key, handle);\n });\n }\n }\n\n /**\n * Enables sync for the object between the host and the VM and returns objects wrapped with proxies.\n *\n * The return value is necessary in order to reflect changes to the object from the host to the VM. Please note that setting a value in the field or deleting a field in the original object will not synchronize it.\n */\n sync<T>(target: T): T {\n const wrapped = this._wrap(target);\n if (typeof wrapped === \"undefined\") return target;\n walkObject(wrapped, (v) => {\n this._sync.add(this._unwrap(v));\n });\n return wrapped;\n }\n\n /**\n * Register a pair of objects that will be considered the same between the host and the QuickJS VM.\n *\n * Instead of a string, you can also pass a QuickJSHandle directly. In that case, however, when you have to dispose them manually when destroying the VM.\n */\n register(target: any, handleOrCode: QuickJSHandle | string) {\n if (this._registeredMap.has(target)) return;\n const handle =\n typeof handleOrCode === \"string\"\n ? this._unwrapResult(this.vm.evalCode(handleOrCode))\n : handleOrCode;\n if (eq(this.vm, handle, this.vm.undefined)) return;\n if (typeof handleOrCode === \"string\") {\n this._registeredMapDispose.add(target);\n }\n this._registeredMap.set(target, handle);\n }\n\n /**\n * Execute `register` methods for each pair.\n */\n registerAll(map: Iterable<[any, QuickJSHandle | string]>) {\n for (const [k, v] of map) {\n this.register(k, v);\n }\n }\n\n /**\n * Unregister a pair of objects that were registered with `registeredObjects` option and `register` method.\n */\n unregister(target: any, dispose?: boolean) {\n this._registeredMap.delete(\n target,\n this._registeredMapDispose.has(target) || dispose\n );\n this._registeredMapDispose.delete(target);\n }\n\n /**\n * Execute `unregister` methods for each target.\n */\n unregisterAll(targets: Iterable<any>, dispose?: boolean) {\n for (const t of targets) {\n this.unregister(t, dispose);\n }\n }\n\n startSync(target: any) {\n if (!isObject(target)) return;\n this._sync.add(this._unwrap(target));\n }\n\n endSync(target: any) {\n this._sync.delete(this._unwrap(target));\n }\n\n _unwrapResult<T>(result: SuccessOrFail<T, QuickJSHandle>): T {\n if (\"value\" in result) {\n return result.value;\n }\n throw this._unwrapIfNotSynced(result.error.consume(this._unmarshal));\n }\n\n _unwrapResultAndUnmarshal(\n result: VmCallResult<QuickJSHandle> | undefined\n ): any {\n if (!result) return;\n return this._unwrapIfNotSynced(\n this._unwrapResult(result).consume(this._unmarshal)\n );\n }\n\n _isMarshalable = (t: unknown): boolean | \"json\" => {\n const im = this._options?.isMarshalable;\n return (typeof im === \"function\" ? im(this._unwrap(t)) : im) ?? \"json\";\n };\n\n _marshalFind = (t: unknown) => {\n const unwrappedT = this._unwrap(t);\n const handle =\n this._registeredMap.get(t) ??\n (unwrappedT !== t ? this._registeredMap.get(unwrappedT) : undefined) ??\n this._map.get(t) ??\n (unwrappedT !== t ? this._map.get(unwrappedT) : undefined);\n return handle;\n };\n\n _marshalPre = (\n t: unknown,\n h: QuickJSHandle,\n mode: true | \"json\" | undefined\n ): Wrapped<QuickJSHandle> | undefined => {\n if (mode === \"json\") return;\n return this._register(t, h, this._map)?.[1];\n };\n\n _marshalPreApply = (\n target: Function,\n that: unknown,\n args: unknown[]\n ): void => {\n const unwrapped = isObject(that) ? this._unwrap(that) : undefined;\n // override sync mode of this object while calling the function\n if (unwrapped) this._temporalSync.add(unwrapped);\n try {\n return target.apply(that, args);\n } finally {\n // restore sync mode\n if (unwrapped) this._temporalSync.delete(unwrapped);\n }\n };\n\n _marshal = (target: any): [QuickJSHandle, boolean] => {\n const registered = this._registeredMap.get(target);\n if (registered) {\n return [registered, false];\n }\n\n const handle = marshal(this._wrap(target) ?? target, {\n vm: this.vm,\n unmarshal: this._unmarshal,\n isMarshalable: this._isMarshalable,\n find: this._marshalFind,\n pre: this._marshalPre,\n preApply: this._marshalPreApply,\n });\n\n return [handle, !this._map.hasHandle(handle)];\n };\n\n _preUnmarshal = (t: any, h: QuickJSHandle): Wrapped<any> => {\n return this._register(t, h, undefined, true)?.[0];\n };\n\n _unmarshalFind = (h: QuickJSHandle): unknown => {\n return this._registeredMap.getByHandle(h) ?? this._map.getByHandle(h);\n };\n\n _unmarshal = (handle: QuickJSHandle): any => {\n const registered = this._registeredMap.getByHandle(handle);\n if (typeof registered !== \"undefined\") {\n return registered;\n }\n\n const [wrappedHandle] = this._wrapHandle(handle);\n return unmarshal(wrappedHandle ?? handle, {\n vm: this.vm,\n marshal: this._marshal,\n find: this._unmarshalFind,\n pre: this._preUnmarshal,\n });\n };\n\n _register(\n t: any,\n h: QuickJSHandle,\n map: VMMap = this._map,\n sync?: boolean\n ): [Wrapped<any>, Wrapped<QuickJSHandle>] | undefined {\n if (this._registeredMap.has(t) || this._registeredMap.hasHandle(h)) {\n return;\n }\n\n const wrappedT = this._wrap(t);\n const [wrappedH] = this._wrapHandle(h);\n if (!wrappedT || !wrappedH) return; // t or h is not an object\n\n const unwrappedT = this._unwrap(t);\n const [unwrappedH, unwrapped] = this._unwrapHandle(h);\n\n const res = map.set(wrappedT, wrappedH, unwrappedT, unwrappedH);\n if (!res) {\n // already registered\n if (unwrapped) unwrappedH.dispose();\n throw new Error(\"already registered\");\n } else if (sync) {\n this._sync.add(unwrappedT);\n }\n\n return [wrappedT, wrappedH];\n }\n\n _syncMode = (obj: any): \"both\" | undefined => {\n const obj2 = this._unwrap(obj);\n return this._sync.has(obj2) || this._temporalSync.has(obj2)\n ? \"both\"\n : undefined;\n };\n\n _wrap<T>(target: T): Wrapped<T> | undefined {\n return wrap(\n this.vm,\n target,\n this._symbol,\n this._symbolHandle,\n this._marshal,\n this._syncMode\n );\n }\n\n _unwrap<T>(target: T): T {\n return unwrap(target, this._symbol);\n }\n\n _unwrapIfNotSynced = <T>(target: T): T => {\n const unwrapped = this._unwrap(target);\n return this._sync.has(unwrapped) ? target : unwrapped;\n };\n\n _wrapHandle(\n handle: QuickJSHandle\n ): [Wrapped<QuickJSHandle> | undefined, boolean] {\n return wrapHandle(\n this.vm,\n handle,\n this._symbol,\n this._symbolHandle,\n this._unmarshal,\n this._syncMode\n );\n }\n\n _unwrapHandle(target: QuickJSHandle): [QuickJSHandle, boolean] {\n return unwrapHandle(this.vm, target, this._symbolHandle);\n }\n}\n"],"names":["VMMap","vm","_map1","Map","_map2","_map3","_map4","_counterMap","_disposables","Set","_mapGet","_mapSet","_mapDelete","_mapClear","_counter","this","result","unwrapResult","evalCode","consume","fn","_this","_call","undefined","getProp","dispose","add","set","key","handle","key2","handle2","alive","v","get","counter","newNumber","c","_this2","merge","iteratable","iter","num","getByHandle","getNumber","has","hasHandle","filter","h","deleteByHandle","clear","values","keys","next","k1","done","value","n","_this3","v1","v2","k2","_get2","thisArg","callFunction","size","Symbol","iterator","isES2015Class","cls","test","Function","prototype","toString","call","isObject","walkObject","callback","walk","Array","isArray","proto","Object","getPrototypeOf","getOwnPropertyDescriptors","d","complexity","max","_","code","args","f","length","eq","a","b","dump","isHandleObject","json","target","JSON","stringify","newString","consumeAll","handles","cb","mayConsumeAll","map","marshalProperties","marshal","descs","newObject","desc","keyHandle","valueHandle","getHandle","setHandle","descObj","entries","forEach","k","setProp","getOwnPropertySymbols","options","unmarshal","isMarshalable","find","pre","primitive","marshalPrimitive","marshalable","pre2","preMarshal","raw","marshalJSON","marshal2","t","description","marshalSymbol","preApply","newFunction","name","that","apply","marshalFunction","newArray","prototypeHandle","marshalObject","unmarshalProperties","keyName","reduce","unmarshable","ty","defineProperty","unmarshalInner","unmarshalPrimitive","unmarshal2","preUnmarshal","getString","sym","unmarshalSymbol","thisHandle","argHandles","_newtarget","defineProperties","resultHandle","func","unmarshalFunction","r","obj","setPrototypeOf","unmarshalObject","unwrap","unwrapHandle","isHandleWrapped","defaultRegisteredObjects","Boolean","Error","EvalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError","getOwnPropertyNames","Arena","_map","_registeredMap","_registeredMapDispose","_sync","_temporalSync","_symbol","_symbolHandle","_options","_isMarshalable","im","_this$_options","_unwrap","_marshalFind","unwrappedT","_marshalPre","mode","_register","_this$_register","_marshalPreApply","unwrapped","_marshal","registered","_wrap","_unmarshal","_preUnmarshal","_this$_register2","_unmarshalFind","wrappedHandle","_wrapHandle","_syncMode","obj2","_unwrapIfNotSynced","registerAll","registeredObjects","_unwrapResultAndUnmarshal","executePendingJobs","maxJobsToExecute","error","expose","shouldBeDisposed","global","mayConsume","sync","wrapped","register","handleOrCode","_unwrapResult","unregister","unregisterAll","targets","startSync","endSync","wrappedT","wrappedH","_unwrapHandle","unwrappedH","proxyKeySymbol","proxyKeySymbolHandle","syncMode","rec","Proxy","Reflect","receiver","receiverHandle","deleteProperty","recHandle","wrap","res","wrapHandle"],"mappings":"80CAEqBA,cAcnB,WAAYC,mBAbZA,eACAC,MAA0B,IAAIC,SAC9BC,MAA0B,IAAID,SAC9BE,MAAoC,IAAIF,SACxCG,MAAoC,IAAIH,SACxCI,YAAgC,IAAIJ,SACpCK,aAAmC,IAAIC,SACvCC,oBACAC,oBACAC,uBACAC,sBACAC,SAAW,EAGTC,KAAKd,GAAKA,EAEV,IAAMe,EAASf,EACZgB,aACChB,EAAGiB,w0BAyBJC,QAAQ,SAACC,UAAOC,EAAKC,MAAMF,OAAIG,KAElCR,KAAKL,QAAUT,EAAGuB,QAAQR,EAAQ,OAClCD,KAAKJ,QAAUV,EAAGuB,QAAQR,EAAQ,OAClCD,KAAKH,WAAaX,EAAGuB,QAAQR,EAAQ,UACrCD,KAAKF,UAAYZ,EAAGuB,QAAQR,EAAQ,SAEpCA,EAAOS,UAEPV,KAAKP,aAAakB,IAAIX,KAAKL,SAC3BK,KAAKP,aAAakB,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E,GACzB,GAAKmD,EAAL,CACA,IAAMvE,EAAMgG,EAAUX,UACf2D,EAAOzE,EAAQ+I,GAAgBtN,OAG1C,SAAC8D,SAAS,CACRhB,gBACEzE,ylCA8BAsB,EACAM,EACAsN,UACGzJ,KAEL,KA9DoC,MAACnE,GAAW,GE0P3CuO,CACL/O,KAAKd,GACL4B,EACAd,KAAKgL,QACLhL,KAAKiL,cACLjL,KAAKkM,WACLlM,KAAKwM,cAITyB,cAAA,SAAc7I,GACZ,OAAO0E,EAAa9J,KAAKd,GAAIkG,EAAQpF,KAAKiL"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quickjs-emscripten-sync.umd.js","sources":["../src/vmmap.ts","../src/util.ts","../src/vmutil.ts","../src/marshal/properties.ts","../src/marshal/index.ts","../src/marshal/primitive.ts","../src/marshal/json.ts","../src/marshal/symbol.ts","../src/marshal/function.ts","../src/marshal/object.ts","../src/unmarshal/properties.ts","../src/unmarshal/index.ts","../src/unmarshal/primitive.ts","../src/unmarshal/symbol.ts","../src/unmarshal/function.ts","../src/unmarshal/object.ts","../src/wrapper.ts","../src/default.ts","../src/index.ts"],"sourcesContent":["import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\n\nexport default class VMMap {\n vm: QuickJSVm;\n _map1: Map<any, number> = new Map();\n _map2: Map<any, number> = new Map();\n _map3: Map<number, QuickJSHandle> = new Map();\n _map4: Map<number, QuickJSHandle> = new Map();\n _counterMap: Map<number, any> = new Map();\n _disposables: Set<QuickJSHandle> = new Set();\n _mapGet: QuickJSHandle;\n _mapSet: QuickJSHandle;\n _mapDelete: QuickJSHandle;\n _mapClear: QuickJSHandle;\n _counter = 0;\n\n constructor(vm: QuickJSVm) {\n this.vm = vm;\n\n const result = vm\n .unwrapResult(\n vm.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 }`)\n )\n .consume((fn) => this._call(fn, undefined));\n\n this._mapGet = vm.getProp(result, \"get\");\n this._mapSet = vm.getProp(result, \"set\");\n this._mapDelete = vm.getProp(result, \"delete\");\n this._mapClear = vm.getProp(result, \"clear\");\n\n result.dispose();\n\n this._disposables.add(this._mapGet);\n this._disposables.add(this._mapSet);\n this._disposables.add(this._mapDelete);\n this._disposables.add(this._mapClear);\n }\n\n set(\n key: any,\n handle: QuickJSHandle,\n key2?: any,\n handle2?: QuickJSHandle\n ): boolean {\n if (!handle.alive || (handle2 && !handle2.alive)) return false;\n\n const v = this.get(key) ?? this.get(key2);\n if (v) {\n // handle and handle2 are unused so they should be disposed\n return v === handle || v === handle2;\n }\n\n const counter = this._counter++;\n this._map1.set(key, counter);\n this._map3.set(counter, handle);\n this._counterMap.set(counter, key);\n if (key2) {\n this._map2.set(key2, counter);\n if (handle2) {\n this._map4.set(counter, handle2);\n }\n }\n\n this.vm.newNumber(counter).consume((c) => {\n this._call(\n this._mapSet,\n undefined,\n handle,\n c,\n handle2 ?? this.vm.undefined\n );\n });\n\n return true;\n }\n\n merge(\n iteratable:\n | Iterable<\n | [any, QuickJSHandle | undefined]\n | [any, QuickJSHandle | undefined, any, QuickJSHandle | undefined]\n >\n | undefined\n ) {\n if (!iteratable) return;\n for (const iter of iteratable) {\n if (!iter) continue;\n if (iter[1]) {\n this.set(iter[0], iter[1], iter[2], iter[3]);\n }\n }\n }\n\n get(key: any) {\n const num = this._map1.get(key) ?? this._map2.get(key);\n const handle = typeof num === \"number\" ? this._map3.get(num) : undefined;\n\n if (!handle) return;\n if (!handle.alive) {\n this.delete(key);\n return;\n }\n\n return handle;\n }\n\n getByHandle(handle: QuickJSHandle) {\n if (!handle.alive) {\n return;\n }\n return this._counterMap.get(\n this.vm.getNumber(this._call(this._mapGet, undefined, handle))\n );\n }\n\n has(key: any) {\n return !!this.get(key);\n }\n\n hasHandle(handle: QuickJSHandle) {\n return typeof this.getByHandle(handle) !== \"undefined\";\n }\n\n delete(key: any, dispose?: boolean) {\n const num = this._map1.get(key) ?? this._map2.get(key);\n if (typeof num === \"undefined\") return;\n\n const handle = this._map3.get(num);\n const handle2 = this._map4.get(num);\n this._call(\n this._mapDelete,\n undefined,\n ...[handle, handle2].filter((h): h is QuickJSHandle => !!h?.alive)\n );\n\n this._map1.delete(key);\n this._map2.delete(key);\n this._map3.delete(num);\n this._map4.delete(num);\n\n for (const [k, v] of this._map1) {\n if (v === num) {\n this._map1.delete(k);\n break;\n }\n }\n\n for (const [k, v] of this._map2) {\n if (v === num) {\n this._map2.delete(k);\n break;\n }\n }\n\n for (const [k, v] of this._counterMap) {\n if (v === key) {\n this._counterMap.delete(k);\n break;\n }\n }\n\n if (dispose) {\n if (handle?.alive) handle.dispose();\n if (handle2?.alive) handle2.dispose();\n }\n }\n\n deleteByHandle(handle: QuickJSHandle, dispose?: boolean) {\n const key = this.getByHandle(handle);\n if (typeof key !== \"undefined\") {\n this.delete(key, dispose);\n }\n }\n\n clear() {\n this._counter = 0;\n this._map1.clear();\n this._map2.clear();\n this._map3.clear();\n this._map4.clear();\n this._counterMap.clear();\n if (this._mapClear.alive) {\n this._call(this._mapClear, undefined);\n }\n }\n\n dispose() {\n for (const v of this._disposables.values()) {\n if (v.alive) {\n v.dispose();\n }\n }\n for (const v of this._map3.values()) {\n if (v.alive) {\n v.dispose();\n }\n }\n for (const v of this._map4.values()) {\n if (v.alive) {\n v.dispose();\n }\n }\n this._disposables.clear();\n this.clear();\n }\n\n get size() {\n return this._map1.size;\n }\n\n [Symbol.iterator](): Iterator<\n [any, QuickJSHandle, any, QuickJSHandle | undefined]\n > {\n const keys = this._map1.keys();\n return {\n next: () => {\n while (true) {\n const k1 = keys.next();\n if (k1.done) return { value: undefined, done: true };\n const n = this._map1.get(k1.value);\n if (typeof n === \"undefined\") continue;\n const v1 = this._map3.get(n);\n const v2 = this._map4.get(n);\n if (!v1) continue;\n const k2 = this._get2(n);\n return { value: [k1.value, v1, k2, v2], done: false };\n }\n },\n };\n }\n\n _get2(num: number) {\n for (const [k, v] of this._map2) {\n if (v === num) return k;\n }\n }\n\n _call(\n fn: QuickJSHandle,\n thisArg: QuickJSHandle | undefined,\n ...args: QuickJSHandle[]\n ) {\n return this.vm.unwrapResult(\n this.vm.callFunction(\n fn,\n typeof thisArg === \"undefined\" ? this.vm.undefined : thisArg,\n ...args\n )\n );\n }\n}\n","export function isES2015Class(cls: any): cls is new (...args: any[]) => any {\n return (\n typeof cls === \"function\" &&\n /^class\\s/.test(Function.prototype.toString.call(cls))\n );\n}\n\nexport function isObject(value: any): value is object | Function {\n return (\n typeof value === \"function\" || (typeof value === \"object\" && value !== null)\n );\n}\n\nexport function walkObject(\n value: any,\n callback?: (target: any, set: Set<any>) => boolean | void\n): Set<any> {\n const set = new Set<any>();\n const walk = (v: any) => {\n if (!isObject(v) || set.has(v) || callback?.(v, set) === false) return;\n set.add(v);\n\n if (Array.isArray(v)) {\n for (const e of v) {\n walk(e);\n }\n return;\n }\n\n if (typeof v === \"object\") {\n const proto = Object.getPrototypeOf(v);\n if (proto && proto !== Object.prototype) {\n walk(proto);\n }\n }\n\n for (const d of Object.values(Object.getOwnPropertyDescriptors(v))) {\n if (\"value\" in d) walk(d.value);\n if (\"get\" in d) walk(d.get);\n if (\"set\" in d) walk(d.set);\n }\n };\n\n walk(value);\n return set;\n}\n\n/**\n * 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.\n */\nexport function complexity(value: any, max?: number): number {\n return walkObject(value, max ? (_, set) => set.size < max : undefined).size;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\n\nexport function call(\n vm: QuickJSVm,\n code: string,\n thisArg?: QuickJSHandle,\n ...args: QuickJSHandle[]\n): QuickJSHandle {\n return vm.unwrapResult(vm.evalCode(code)).consume((f) => {\n if (typeof thisArg === \"undefined\" && args.length === 0) return f;\n return vm.unwrapResult(\n vm.callFunction(f, thisArg ?? vm.undefined, ...args)\n );\n });\n}\n\nexport function eq(vm: QuickJSVm, a: QuickJSHandle, b: QuickJSHandle): boolean {\n return vm.dump(call(vm, \"Object.is\", undefined, a, b));\n}\n\nexport function instanceOf(\n vm: QuickJSVm,\n a: QuickJSHandle,\n b: QuickJSHandle\n): boolean {\n return vm.dump(call(vm, \"(a, b) => a instanceof b\", undefined, a, b));\n}\n\nexport function isHandleObject(vm: QuickJSVm, a: QuickJSHandle): boolean {\n return vm.dump(\n call(\n vm,\n `a => typeof a === \"object\" && a !== null || typeof a === \"function\"`,\n undefined,\n a\n )\n );\n}\n\nexport function json(vm: QuickJSVm, target: any): QuickJSHandle {\n const json = JSON.stringify(target);\n if (!json) return vm.undefined;\n return call(vm, `JSON.parse`, undefined, vm.newString(json));\n}\n\nexport function consumeAll<T extends QuickJSHandle[], K>(\n handles: T,\n cb: (handles: T) => K\n): K {\n try {\n return cb(handles);\n } finally {\n for (const h of handles) {\n if (h.alive) h.dispose();\n }\n }\n}\n\nexport function mayConsume<T>(\n [handle, shouldBeDisposed]: [QuickJSHandle, boolean],\n fn: (h: QuickJSHandle) => T\n) {\n try {\n return fn(handle);\n } finally {\n if (shouldBeDisposed) {\n handle.dispose();\n }\n }\n}\n\nexport function mayConsumeAll<T, H extends QuickJSHandle[]>(\n handles: { [P in keyof H]: [QuickJSHandle, boolean] },\n fn: (...args: H) => T\n) {\n try {\n return fn(...(handles.map((h) => h[0]) as H));\n } finally {\n for (const [handle, shouldBeDisposed] of handles) {\n if (shouldBeDisposed) {\n handle.dispose();\n }\n }\n }\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { call } from \"../vmutil\";\n\nexport default function marshalProperties(\n vm: QuickJSVm,\n target: object | Function,\n handle: QuickJSHandle,\n marshal: (target: unknown) => QuickJSHandle\n): void {\n const descs = vm.newObject();\n const cb = (key: string | number | symbol, desc: PropertyDescriptor) => {\n const keyHandle = marshal(key);\n const valueHandle =\n typeof desc.value === \"undefined\" ? undefined : marshal(desc.value);\n const getHandle =\n typeof desc.get === \"undefined\" ? undefined : marshal(desc.get);\n const setHandle =\n typeof desc.set === \"undefined\" ? undefined : marshal(desc.set);\n\n vm.newObject().consume((descObj) => {\n Object.entries(desc).forEach(([k, v]) => {\n const v2 =\n k === \"value\"\n ? valueHandle\n : k === \"get\"\n ? getHandle\n : k === \"set\"\n ? setHandle\n : v\n ? vm.true\n : vm.false;\n if (v2) {\n vm.setProp(descObj, k, v2);\n }\n });\n vm.setProp(descs, keyHandle, descObj);\n });\n };\n\n const desc = Object.getOwnPropertyDescriptors(target);\n Object.entries(desc).forEach(([k, v]) => cb(k, v));\n Object.getOwnPropertySymbols(desc).forEach((k) => cb(k, (desc as any)[k]));\n\n call(vm, `Object.defineProperties`, undefined, handle, descs).dispose();\n\n descs.dispose();\n}\n","import { QuickJSHandle, QuickJSVm } from \"quickjs-emscripten\";\nimport marshalFunction from \"./function\";\nimport marshalObject from \"./object\";\nimport marshalPrimitive from \"./primitive\";\nimport marshalSymbol from \"./symbol\";\nimport marshalJSON from \"./json\";\n\nexport type Options = {\n vm: QuickJSVm;\n unmarshal: (handle: QuickJSHandle) => unknown;\n isMarshalable?: (target: unknown) => boolean | \"json\";\n find: (target: unknown) => QuickJSHandle | undefined;\n pre: (\n target: unknown,\n handle: QuickJSHandle,\n mode: true | \"json\" | undefined\n ) => QuickJSHandle | undefined;\n preApply?: (target: Function, thisArg: unknown, args: unknown[]) => any;\n};\n\nexport function marshal(target: unknown, options: Options): QuickJSHandle {\n const { vm, unmarshal, isMarshalable, find, pre } = options;\n\n {\n const primitive = marshalPrimitive(vm, target);\n if (primitive) {\n return primitive;\n }\n }\n\n {\n const handle = find(target);\n if (handle) return handle;\n }\n\n const marshalable = isMarshalable?.(target);\n if (marshalable === false) {\n return vm.undefined;\n }\n\n const pre2 = (target: any, handle: QuickJSHandle) =>\n pre(target, handle, marshalable);\n if (marshalable === \"json\") {\n return marshalJSON(vm, target, pre2);\n }\n\n const marshal2 = (t: unknown) => marshal(t, options);\n return (\n marshalSymbol(vm, target, pre2) ??\n marshalFunction(vm, target, marshal2, unmarshal, pre2, options.preApply) ??\n marshalObject(vm, target, marshal2, pre2) ??\n vm.undefined\n );\n}\n\nexport default marshal;\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\n// import { call } from \"../vmutil\";\n\nexport default function marshalPrimitive(\n vm: QuickJSVm,\n target: unknown\n): QuickJSHandle | undefined {\n switch (typeof target) {\n case \"undefined\":\n return vm.undefined;\n case \"number\":\n return vm.newNumber(target);\n case \"string\":\n return vm.newString(target);\n case \"boolean\":\n return target ? vm.true : vm.false;\n case \"object\":\n return target === null ? vm.null : undefined;\n\n // BigInt is not supported by quickjs-emscripten\n // case \"bigint\":\n // return call(\n // vm,\n // `s => BigInt(s)`,\n // undefined,\n // vm.newString(target.toString())\n // );\n }\n\n return undefined;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { json } from \"../vmutil\";\n\nexport default function marshalJSON(\n vm: QuickJSVm,\n target: unknown,\n preMarshal: (\n target: unknown,\n handle: QuickJSHandle\n ) => QuickJSHandle | undefined\n): QuickJSHandle {\n const raw = json(vm, target);\n const handle = preMarshal(target, raw) ?? raw;\n return handle;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { call } from \"../vmutil\";\n\nexport default function marshalSymbol(\n vm: QuickJSVm,\n target: unknown,\n preMarshal: (\n target: unknown,\n handle: QuickJSHandle\n ) => QuickJSHandle | undefined\n): QuickJSHandle | undefined {\n if (typeof target !== \"symbol\") return;\n const handle = call(\n vm,\n \"d => Symbol(d)\",\n undefined,\n target.description ? vm.newString(target.description) : vm.undefined\n );\n return preMarshal(target, handle) ?? handle;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { isES2015Class, isObject } from \"../util\";\nimport { call } from \"../vmutil\";\nimport marshalProperties from \"./properties\";\n\nexport default function marshalFunction(\n vm: QuickJSVm,\n target: unknown,\n marshal: (target: unknown) => QuickJSHandle,\n unmarshal: (handle: QuickJSHandle) => unknown,\n preMarshal: (\n target: unknown,\n handle: QuickJSHandle\n ) => QuickJSHandle | undefined,\n preApply?: (target: Function, thisArg: unknown, args: unknown[]) => any\n): QuickJSHandle | undefined {\n if (typeof target !== \"function\") return;\n\n const raw = vm\n .newFunction(target.name, function (...argHandles) {\n const that = unmarshal(this);\n const args = argHandles.map((a) => unmarshal(a));\n\n if (isES2015Class(target) && isObject(that)) {\n // Class constructors cannot be invoked without new expression, and new.target is not changed\n const result = new target(...args);\n Object.entries(result).forEach(([key, value]) => {\n vm.setProp(this, key, marshal(value));\n });\n return this;\n }\n\n return marshal(\n preApply ? preApply(target, that, args) : target.apply(that, args)\n );\n })\n .consume((handle2) =>\n // fucntions created by vm.newFunction are not callable as a class constrcutor\n call(\n vm,\n `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 }`,\n undefined,\n handle2\n )\n );\n\n const handle = preMarshal(target, raw) ?? raw;\n marshalProperties(vm, target, raw, marshal);\n\n return handle;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { call } from \"../vmutil\";\nimport marshalProperties from \"./properties\";\n\nexport default function marshalObject(\n vm: QuickJSVm,\n target: unknown,\n marshal: (target: unknown) => QuickJSHandle,\n preMarshal: (\n target: unknown,\n handle: QuickJSHandle\n ) => QuickJSHandle | undefined\n): QuickJSHandle | undefined {\n if (typeof target !== \"object\" || target === null) return;\n\n const raw = Array.isArray(target) ? vm.newArray() : vm.newObject();\n const handle = preMarshal(target, raw) ?? raw;\n\n // prototype\n const prototype = Object.getPrototypeOf(target);\n const prototypeHandle =\n prototype && prototype !== Object.prototype && prototype !== Array.prototype\n ? marshal(prototype)\n : undefined;\n if (prototypeHandle) {\n call(\n vm,\n \"Object.setPrototypeOf\",\n undefined,\n handle,\n prototypeHandle\n ).dispose();\n }\n\n marshalProperties(vm, target, raw, marshal);\n\n return handle;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { call } from \"../vmutil\";\n\nexport default function unmarshalProperties(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n target: object | Function,\n unmarshal: (handle: QuickJSHandle) => [unknown, boolean]\n) {\n vm.newFunction(\"\", (key, value) => {\n const [keyName] = unmarshal(key);\n if (\n typeof keyName !== \"string\" &&\n typeof keyName !== \"number\" &&\n typeof keyName !== \"symbol\"\n )\n return;\n\n const desc = (\n [\n [\"value\", true],\n [\"get\", true],\n [\"set\", true],\n [\"configurable\", false],\n [\"enumerable\", false],\n [\"writable\", false],\n ] as const\n ).reduce<PropertyDescriptor>((desc, [key, unmarshable]) => {\n const h = vm.getProp(value, key);\n const ty = vm.typeof(h);\n\n if (ty === \"undefined\") return desc;\n if (!unmarshable && ty === \"boolean\") {\n desc[key] = vm.dump(vm.getProp(value, key));\n return desc;\n }\n\n const [v, alreadyExists] = unmarshal(h);\n if (alreadyExists) {\n h.dispose();\n }\n desc[key] = v;\n\n return desc;\n }, {});\n\n Object.defineProperty(target, keyName, desc);\n }).consume((fn) => {\n call(\n vm,\n `(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 }`,\n undefined,\n handle,\n fn\n ).dispose();\n });\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport unmarshalFunction from \"./function\";\nimport unmarshalObject from \"./object\";\nimport unmarshalPrimitive from \"./primitive\";\nimport unmarshalSymbol from \"./symbol\";\n\nexport type Options = {\n vm: QuickJSVm;\n // marshal returns handle and boolean indicates that the handle should be disposed after use\n marshal: (target: unknown) => [QuickJSHandle, boolean];\n find: (handle: QuickJSHandle) => unknown | undefined;\n pre: <T>(target: T, handle: QuickJSHandle) => T | undefined;\n};\n\nexport function unmarshal(handle: QuickJSHandle, options: Options): any {\n const [result] = unmarshalInner(handle, options);\n return result;\n}\n\nfunction unmarshalInner(\n handle: QuickJSHandle,\n options: Options\n): [any, boolean] {\n const { vm, marshal, find, pre } = options;\n\n {\n const [target, ok] = unmarshalPrimitive(vm, handle);\n if (ok) return [target, false];\n }\n\n {\n const target = find(handle);\n if (target) {\n return [target, true];\n }\n }\n\n const unmarshal2 = (h: QuickJSHandle) => unmarshalInner(h, options);\n\n const result =\n unmarshalSymbol(vm, handle, pre) ??\n unmarshalFunction(vm, handle, marshal, unmarshal2, pre) ??\n unmarshalObject(vm, handle, unmarshal2, pre);\n\n return [result, false];\n}\n\nexport default unmarshal;\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\n\nexport default function unmarshalPrimitive(\n vm: QuickJSVm,\n handle: QuickJSHandle\n): [any, boolean] {\n const ty = vm.typeof(handle);\n if (\n ty === \"undefined\" ||\n ty === \"number\" ||\n ty === \"string\" ||\n ty === \"boolean\"\n ) {\n return [vm.dump(handle), true];\n } else if (ty === \"object\") {\n const isNull = vm\n .unwrapResult(vm.evalCode(\"a => a === null\"))\n .consume((n) =>\n vm.dump(vm.unwrapResult(vm.callFunction(n, vm.undefined, handle)))\n );\n if (isNull) {\n return [null, true];\n }\n }\n\n // BigInt is not supported by quickjs-emscripten\n // if (ty === \"bigint\") {\n // const str = vm\n // .getProp(handle, \"toString\")\n // .consume(toString => vm.unwrapResult(vm.callFunction(toString, handle)))\n // .consume(str => vm.getString(str));\n // const bi = BigInt(str);\n // return [bi, true];\n // }\n\n return [undefined, false];\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\n\nexport default function unmarshalSymbol(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined\n): symbol | undefined {\n if (vm.typeof(handle) !== \"symbol\") return;\n const desc = vm.getString(vm.getProp(handle, \"description\"));\n const sym = Symbol(desc);\n return preUnmarshal(sym, handle) ?? sym;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { call, mayConsumeAll } from \"../vmutil\";\nimport unmarshalProperties from \"./properties\";\n\nexport default function unmarshalFunction(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n // marshal returns handle and boolean indicates that the handle should be disposed after use\n marshal: (value: unknown) => [QuickJSHandle, boolean],\n unmarshal: (handle: QuickJSHandle) => [unknown, boolean],\n preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined\n): Function | undefined {\n if (vm.typeof(handle) !== \"function\") return;\n\n const raw = function (this: any, ...args: any[]) {\n return mayConsumeAll(\n [marshal(this), ...args.map((a) => marshal(a))],\n (thisHandle, ...argHandles) => {\n if (new.target) {\n const [instance] = unmarshal(\n call(\n vm,\n `(Cls, ...args) => new Cls(...args)`,\n thisHandle,\n handle,\n ...argHandles\n )\n );\n Object.defineProperties(\n this,\n Object.getOwnPropertyDescriptors(instance)\n );\n return this;\n }\n\n const resultHandle = vm.unwrapResult(\n vm.callFunction(handle, thisHandle, ...argHandles)\n );\n\n const [result, alreadyExists] = unmarshal(resultHandle);\n if (alreadyExists) resultHandle.dispose();\n\n return result;\n }\n );\n };\n\n const func = preUnmarshal(raw, handle) ?? raw;\n unmarshalProperties(vm, handle, raw, unmarshal);\n\n return func;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport unmarshalProperties from \"./properties\";\nimport { call } from \"../vmutil\";\n\nexport default function unmarshalObject(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n unmarshal: (handle: QuickJSHandle) => [unknown, boolean],\n preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined\n): object | undefined {\n if (\n vm.typeof(handle) !== \"object\" ||\n // null check\n vm\n .unwrapResult(vm.evalCode(\"o => o === null\"))\n .consume((n) =>\n vm.dump(vm.unwrapResult(vm.callFunction(n, vm.undefined, handle)))\n )\n )\n return;\n\n const raw = call(vm, \"Array.isArray\", undefined, handle).consume((r) =>\n vm.dump(r)\n )\n ? []\n : {};\n const obj = preUnmarshal(raw, handle) ?? raw;\n\n const prototype = call(\n vm,\n `o => {\n const p = Object.getPrototypeOf(o);\n return !p || p === Object.prototype || p === Array.prototype ? undefined : p;\n }`,\n undefined,\n handle\n ).consume((prototype) => {\n if (vm.typeof(prototype) === \"undefined\") return;\n const [proto] = unmarshal(prototype);\n return proto;\n });\n if (typeof prototype === \"object\") {\n Object.setPrototypeOf(obj, prototype);\n }\n\n unmarshalProperties(vm, handle, raw, unmarshal);\n\n return obj;\n}\n","import { QuickJSVm, QuickJSHandle } from \"quickjs-emscripten\";\nimport { isObject } from \"./util\";\nimport { call, isHandleObject, consumeAll, mayConsumeAll } from \"./vmutil\";\n\nexport type SyncMode = \"both\" | \"vm\" | \"host\";\n\nexport type Wrapped<T> = T & { __qes_wrapped: never };\n\nexport function wrap<T = any>(\n vm: QuickJSVm,\n target: T,\n proxyKeySymbol: symbol,\n proxyKeySymbolHandle: QuickJSHandle,\n marshal: (target: any) => [QuickJSHandle, boolean],\n syncMode?: (target: T) => SyncMode | undefined\n): Wrapped<T> | undefined {\n if (!isObject(target)) return undefined;\n if (isWrapped(target, proxyKeySymbol)) return target;\n\n const rec = new Proxy(target as any, {\n get(obj, key) {\n return key === proxyKeySymbol ? obj : Reflect.get(obj, key);\n },\n set(obj, key, value, receiver) {\n const v = unwrap(value, proxyKeySymbol);\n const sync = syncMode?.(receiver) ?? \"host\";\n if (\n (sync !== \"vm\" && !Reflect.set(obj, key, v, receiver)) ||\n sync === \"host\" ||\n !vm.alive\n )\n return true;\n\n mayConsumeAll(\n [marshal(receiver), marshal(key), marshal(v)],\n (receiverHandle, keyHandle, valueHandle) => {\n const [handle2, unwrapped] = unwrapHandle(\n vm,\n receiverHandle,\n proxyKeySymbolHandle\n );\n if (unwrapped) {\n handle2.consume((h) => vm.setProp(h, keyHandle, valueHandle));\n } else {\n vm.setProp(handle2, keyHandle, valueHandle);\n }\n }\n );\n\n return true;\n },\n deleteProperty(obj, key) {\n const sync = syncMode?.(rec) ?? \"host\";\n return mayConsumeAll(\n [marshal(rec), marshal(key)],\n (recHandle, keyHandle) => {\n const [handle2, unwrapped] = unwrapHandle(\n vm,\n recHandle,\n proxyKeySymbolHandle\n );\n\n if (sync === \"vm\" || Reflect.deleteProperty(obj, key)) {\n if (sync === \"host\" || !vm.alive) return true;\n\n if (unwrapped) {\n handle2.consume((h) =>\n call(vm, `(a, b) => delete a[b]`, undefined, h, keyHandle)\n );\n } else {\n call(vm, `(a, b) => delete a[b]`, undefined, handle2, keyHandle);\n }\n }\n return true;\n }\n );\n },\n }) as Wrapped<T>;\n return rec;\n}\n\nexport function wrapHandle(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n proxyKeySymbol: symbol,\n proxyKeySymbolHandle: QuickJSHandle,\n unmarshal: (handle: QuickJSHandle) => any,\n syncMode?: (target: QuickJSHandle) => SyncMode | undefined\n): [Wrapped<QuickJSHandle> | undefined, boolean] {\n if (!isHandleObject(vm, handle)) return [undefined, false];\n if (isHandleWrapped(vm, handle, proxyKeySymbolHandle)) return [handle, false];\n\n return consumeAll(\n [\n vm.newFunction(\"getSyncMode\", (h) => {\n const res = syncMode?.(unmarshal(h));\n if (typeof res === \"string\") return vm.newString(res);\n return vm.undefined;\n }),\n vm.newFunction(\"setter\", (h, keyHandle, valueHandle) => {\n const target = unmarshal(h);\n if (!target) return;\n const key = unmarshal(keyHandle);\n if (key === \"__proto__\") return; // for security\n const value = unmarshal(valueHandle);\n unwrap(target, proxyKeySymbol)[key] = value;\n }),\n vm.newFunction(\"deleter\", (h, keyHandle) => {\n const target = unmarshal(h);\n if (!target) return;\n const key = unmarshal(keyHandle);\n delete unwrap(target, proxyKeySymbol)[key];\n }),\n ],\n (args) => [\n call(\n vm,\n `(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 }`,\n undefined,\n handle,\n proxyKeySymbolHandle,\n ...args\n ) as Wrapped<QuickJSHandle>,\n true,\n ]\n );\n}\n\nexport function unwrap<T>(obj: T, key: string | symbol): T {\n return isObject(obj) ? ((obj as any)[key] as T) ?? obj : obj;\n}\n\nexport function unwrapHandle(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n key: QuickJSHandle\n): [QuickJSHandle, boolean] {\n if (!isHandleWrapped(vm, handle, key)) return [handle, false];\n return [vm.getProp(handle, key), true];\n}\n\nexport function isWrapped<T>(obj: T, key: string | symbol): obj is Wrapped<T> {\n return isObject(obj) && !!(obj as any)[key];\n}\n\nexport function isHandleWrapped(\n vm: QuickJSVm,\n handle: QuickJSHandle,\n key: QuickJSHandle\n): handle is Wrapped<QuickJSHandle> {\n return !!vm.dump(\n call(\n vm,\n `(a, s) => (typeof a === \"object\" && a !== null || typeof a === \"function\") && !!a[s]`,\n undefined,\n handle,\n key\n )\n );\n}\n","/**\n * Default value of registeredObjects option of the Arena class constructor.\n */\nexport const defaultRegisteredObjects: [any, string][] = [\n // basic objects\n [Symbol, \"Symbol\"],\n [Symbol.prototype, \"Symbol.prototype\"],\n [Object, \"Object\"],\n [Object.prototype, \"Object.prototype\"],\n [Function, \"Function\"],\n [Function.prototype, \"Function.prototype\"],\n [Boolean, \"Boolean\"],\n [Boolean.prototype, \"Boolean.prototype\"],\n [Array, \"Array\"],\n [Array.prototype, \"Array.prototype\"],\n // [BigInt, \"BigInt\"],\n // [BigInt.prototype, \"BigInt.prototype\"],\n // errors\n [Error, \"Error\"],\n [Error.prototype, \"Error.prototype\"],\n [EvalError, \"EvalError\"],\n [EvalError.prototype, \"EvalError.prototype\"],\n [RangeError, \"RangeError\"],\n [RangeError.prototype, \"RangeError.prototype\"],\n [ReferenceError, \"ReferenceError\"],\n [ReferenceError.prototype, \"ReferenceError.prototype\"],\n [SyntaxError, \"SyntaxError\"],\n [SyntaxError.prototype, \"SyntaxError.prototype\"],\n [TypeError, \"TypeError\"],\n [TypeError.prototype, \"TypeError.prototype\"],\n [URIError, \"URIError\"],\n [URIError.prototype, \"URIError.prototype\"],\n // built-in symbols\n ...Object.getOwnPropertyNames(Symbol)\n .filter((k) => typeof (Symbol as any)[k] === \"symbol\")\n .map<[any, string]>((k) => [(Symbol as any)[k], `Symbol.${k}`]),\n];\n","import { QuickJSHandle, QuickJSVm } from \"quickjs-emscripten\";\nimport {\n SuccessOrFail,\n VmCallResult,\n} from \"quickjs-emscripten/dist/vm-interface\";\n\nimport VMMap from \"./vmmap\";\nimport marshal from \"./marshal\";\nimport unmarshal from \"./unmarshal\";\nimport { wrap, wrapHandle, unwrap, unwrapHandle, Wrapped } from \"./wrapper\";\nimport { complexity, isES2015Class, isObject, walkObject } from \"./util\";\nimport {\n call,\n eq,\n isHandleObject,\n json,\n consumeAll,\n mayConsume,\n} from \"./vmutil\";\nimport { defaultRegisteredObjects } from \"./default\";\n\nexport {\n VMMap,\n defaultRegisteredObjects,\n marshal,\n unmarshal,\n complexity,\n isES2015Class,\n isObject,\n walkObject,\n call,\n eq,\n isHandleObject,\n json,\n consumeAll,\n};\n\nexport type Options = {\n /** 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. */\n isMarshalable?: boolean | \"json\" | ((target: any) => boolean | \"json\");\n /** You can pre-register a pair 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`.\n *\n * 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.\n */\n registeredObjects?: Iterable<[any, QuickJSHandle | string]>;\n};\n\n/**\n * The Arena class manages all generated handles at once by quickjs-emscripten and automatically converts objects between the host and the QuickJS VM.\n */\nexport class Arena {\n vm: QuickJSVm;\n _map: VMMap;\n _registeredMap: VMMap;\n _registeredMapDispose: Set<any> = new Set();\n _sync: Set<any> = new Set();\n _temporalSync: Set<any> = new Set();\n _symbol = Symbol();\n _symbolHandle: QuickJSHandle;\n _options?: Options;\n\n /** Constructs a new Arena instance. It requires a quickjs-emscripten VM initialized with `quickjs.createVM()`. */\n constructor(vm: QuickJSVm, options?: Options) {\n this.vm = vm;\n this._options = options;\n this._symbolHandle = vm.unwrapResult(vm.evalCode(`Symbol()`));\n this._map = new VMMap(vm);\n this._registeredMap = new VMMap(vm);\n this.registerAll(options?.registeredObjects ?? defaultRegisteredObjects);\n }\n\n /**\n * Dispose of the arena and managed handles. This method won't dispose the VM itself, so the VM has to be disposed of manually.\n */\n dispose() {\n this._map.dispose();\n this._registeredMap.dispose();\n this._symbolHandle.dispose();\n }\n\n /**\n * Evaluate JS code in the VM 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.\n */\n evalCode<T = any>(code: string): T {\n const handle = this.vm.evalCode(code);\n return this._unwrapResultAndUnmarshal(handle);\n }\n\n /**\n * Almost same as `vm.executePendingJobs()`, but it converts and re-throws error objects when an error is thrown during evaluation.\n */\n executePendingJobs(maxJobsToExecute?: number): number {\n const result = this.vm.executePendingJobs(maxJobsToExecute);\n if (\"value\" in result) {\n return result.value;\n }\n throw this._unwrapIfNotSynced(result.error.consume(this._unmarshal));\n }\n\n /**\n * Expose objects as global objects in the VM.\n *\n * By default, exposed objects are not synchronized between the host and the VM.\n * If you want to sync an objects, first wrap the object with sync method, and then expose the wrapped object.\n */\n expose(obj: { [k: string]: any }) {\n for (const [key, value] of Object.entries(obj)) {\n mayConsume(this._marshal(value), (handle) => {\n this.vm.setProp(this.vm.global, key, handle);\n });\n }\n }\n\n /**\n * Enables sync for the object between the host and the VM and returns objects wrapped with proxies.\n *\n * The return value is necessary in order to reflect changes to the object from the host to the VM. Please note that setting a value in the field or deleting a field in the original object will not synchronize it.\n */\n sync<T>(target: T): T {\n const wrapped = this._wrap(target);\n if (typeof wrapped === \"undefined\") return target;\n walkObject(wrapped, (v) => {\n this._sync.add(this._unwrap(v));\n });\n return wrapped;\n }\n\n /**\n * Register a pair of objects that will be considered the same between the host and the QuickJS VM.\n *\n * Instead of a string, you can also pass a QuickJSHandle directly. In that case, however, when you have to dispose them manually when destroying the VM.\n */\n register(target: any, handleOrCode: QuickJSHandle | string) {\n if (this._registeredMap.has(target)) return;\n const handle =\n typeof handleOrCode === \"string\"\n ? this._unwrapResult(this.vm.evalCode(handleOrCode))\n : handleOrCode;\n if (eq(this.vm, handle, this.vm.undefined)) return;\n if (typeof handleOrCode === \"string\") {\n this._registeredMapDispose.add(target);\n }\n this._registeredMap.set(target, handle);\n }\n\n /**\n * Execute `register` methods for each pair.\n */\n registerAll(map: Iterable<[any, QuickJSHandle | string]>) {\n for (const [k, v] of map) {\n this.register(k, v);\n }\n }\n\n /**\n * Unregister a pair of objects that were registered with `registeredObjects` option and `register` method.\n */\n unregister(target: any, dispose?: boolean) {\n this._registeredMap.delete(\n target,\n this._registeredMapDispose.has(target) || dispose\n );\n this._registeredMapDispose.delete(target);\n }\n\n /**\n * Execute `unregister` methods for each target.\n */\n unregisterAll(targets: Iterable<any>, dispose?: boolean) {\n for (const t of targets) {\n this.unregister(t, dispose);\n }\n }\n\n startSync(target: any) {\n if (!isObject(target)) return;\n this._sync.add(this._unwrap(target));\n }\n\n endSync(target: any) {\n this._sync.delete(this._unwrap(target));\n }\n\n _unwrapResult<T>(result: SuccessOrFail<T, QuickJSHandle>): T {\n if (\"value\" in result) {\n return result.value;\n }\n throw this._unwrapIfNotSynced(result.error.consume(this._unmarshal));\n }\n\n _unwrapResultAndUnmarshal(\n result: VmCallResult<QuickJSHandle> | undefined\n ): any {\n if (!result) return;\n return this._unwrapIfNotSynced(\n this._unwrapResult(result).consume(this._unmarshal)\n );\n }\n\n _isMarshalable = (t: unknown): boolean | \"json\" => {\n const im = this._options?.isMarshalable;\n return (typeof im === \"function\" ? im(this._unwrap(t)) : im) ?? \"json\";\n };\n\n _marshalFind = (t: unknown) => {\n const unwrappedT = this._unwrap(t);\n const handle =\n this._registeredMap.get(t) ??\n (unwrappedT !== t ? this._registeredMap.get(unwrappedT) : undefined) ??\n this._map.get(t) ??\n (unwrappedT !== t ? this._map.get(unwrappedT) : undefined);\n return handle;\n };\n\n _marshalPre = (\n t: unknown,\n h: QuickJSHandle,\n mode: true | \"json\" | undefined\n ): Wrapped<QuickJSHandle> | undefined => {\n if (mode === \"json\") return;\n return this._register(t, h, this._map)?.[1];\n };\n\n _marshalPreApply = (\n target: Function,\n that: unknown,\n args: unknown[]\n ): void => {\n const unwrapped = isObject(that) ? this._unwrap(that) : undefined;\n // override sync mode of this object while calling the function\n if (unwrapped) this._temporalSync.add(unwrapped);\n try {\n return target.apply(that, args);\n } finally {\n // restore sync mode\n if (unwrapped) this._temporalSync.delete(unwrapped);\n }\n };\n\n _marshal = (target: any): [QuickJSHandle, boolean] => {\n const registered = this._registeredMap.get(target);\n if (registered) {\n return [registered, false];\n }\n\n const handle = marshal(this._wrap(target) ?? target, {\n vm: this.vm,\n unmarshal: this._unmarshal,\n isMarshalable: this._isMarshalable,\n find: this._marshalFind,\n pre: this._marshalPre,\n preApply: this._marshalPreApply,\n });\n\n return [handle, !this._map.hasHandle(handle)];\n };\n\n _preUnmarshal = (t: any, h: QuickJSHandle): Wrapped<any> => {\n return this._register(t, h, undefined, true)?.[0];\n };\n\n _unmarshalFind = (h: QuickJSHandle): unknown => {\n return this._registeredMap.getByHandle(h) ?? this._map.getByHandle(h);\n };\n\n _unmarshal = (handle: QuickJSHandle): any => {\n const registered = this._registeredMap.getByHandle(handle);\n if (typeof registered !== \"undefined\") {\n return registered;\n }\n\n const [wrappedHandle] = this._wrapHandle(handle);\n return unmarshal(wrappedHandle ?? handle, {\n vm: this.vm,\n marshal: this._marshal,\n find: this._unmarshalFind,\n pre: this._preUnmarshal,\n });\n };\n\n _register(\n t: any,\n h: QuickJSHandle,\n map: VMMap = this._map,\n sync?: boolean\n ): [Wrapped<any>, Wrapped<QuickJSHandle>] | undefined {\n if (this._registeredMap.has(t) || this._registeredMap.hasHandle(h)) {\n return;\n }\n\n const wrappedT = this._wrap(t);\n const [wrappedH] = this._wrapHandle(h);\n if (!wrappedT || !wrappedH) return; // t or h is not an object\n\n const unwrappedT = this._unwrap(t);\n const [unwrappedH, unwrapped] = this._unwrapHandle(h);\n\n const res = map.set(wrappedT, wrappedH, unwrappedT, unwrappedH);\n if (!res) {\n // already registered\n if (unwrapped) unwrappedH.dispose();\n throw new Error(\"already registered\");\n } else if (sync) {\n this._sync.add(unwrappedT);\n }\n\n return [wrappedT, wrappedH];\n }\n\n _syncMode = (obj: any): \"both\" | undefined => {\n const obj2 = this._unwrap(obj);\n return this._sync.has(obj2) || this._temporalSync.has(obj2)\n ? \"both\"\n : undefined;\n };\n\n _wrap<T>(target: T): Wrapped<T> | undefined {\n return wrap(\n this.vm,\n target,\n this._symbol,\n this._symbolHandle,\n this._marshal,\n this._syncMode\n );\n }\n\n _unwrap<T>(target: T): T {\n return unwrap(target, this._symbol);\n }\n\n _unwrapIfNotSynced = <T>(target: T): T => {\n const unwrapped = this._unwrap(target);\n return this._sync.has(unwrapped) ? target : unwrapped;\n };\n\n _wrapHandle(\n handle: QuickJSHandle\n ): [Wrapped<QuickJSHandle> | undefined, boolean] {\n return wrapHandle(\n this.vm,\n handle,\n this._symbol,\n this._symbolHandle,\n this._unmarshal,\n this._syncMode\n );\n }\n\n _unwrapHandle(target: QuickJSHandle): [QuickJSHandle, boolean] {\n return unwrapHandle(this.vm, target, this._symbolHandle);\n }\n}\n"],"names":["VMMap","vm","_map1","Map","_map2","_map3","_map4","_counterMap","_disposables","Set","_mapGet","_mapSet","_mapDelete","_mapClear","_counter","this","result","unwrapResult","evalCode","consume","fn","_this","_call","undefined","getProp","dispose","add","set","key","handle","key2","handle2","alive","v","get","counter","newNumber","c","_this2","merge","iteratable","iter","num","getByHandle","getNumber","has","hasHandle","filter","h","deleteByHandle","clear","values","keys","next","k1","done","value","n","_this3","v1","v2","k2","_get2","thisArg","callFunction","size","Symbol","iterator","isES2015Class","cls","test","Function","prototype","toString","call","isObject","walkObject","callback","walk","Array","isArray","proto","Object","getPrototypeOf","getOwnPropertyDescriptors","d","code","args","f","length","eq","a","b","dump","isHandleObject","json","target","JSON","stringify","newString","consumeAll","handles","cb","mayConsumeAll","map","marshalProperties","marshal","descs","newObject","desc","keyHandle","valueHandle","getHandle","setHandle","descObj","entries","forEach","k","setProp","getOwnPropertySymbols","options","unmarshal","isMarshalable","find","pre","primitive","marshalPrimitive","marshalable","pre2","preMarshal","raw","marshalJSON","marshal2","t","description","marshalSymbol","preApply","newFunction","name","that","apply","marshalFunction","newArray","prototypeHandle","marshalObject","unmarshalProperties","keyName","reduce","unmarshable","ty","defineProperty","unmarshalInner","unmarshalPrimitive","unmarshal2","preUnmarshal","getString","sym","unmarshalSymbol","thisHandle","argHandles","_newtarget","defineProperties","resultHandle","func","unmarshalFunction","r","obj","setPrototypeOf","unmarshalObject","unwrap","unwrapHandle","isHandleWrapped","defaultRegisteredObjects","Boolean","Error","EvalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError","getOwnPropertyNames","_map","_registeredMap","_registeredMapDispose","_sync","_temporalSync","_symbol","_symbolHandle","_options","_isMarshalable","im","_this$_options","_unwrap","_marshalFind","unwrappedT","_marshalPre","mode","_register","_this$_register","_marshalPreApply","unwrapped","_marshal","registered","_wrap","_unmarshal","_preUnmarshal","_this$_register2","_unmarshalFind","wrappedHandle","_wrapHandle","_syncMode","obj2","_unwrapIfNotSynced","registerAll","registeredObjects","_unwrapResultAndUnmarshal","executePendingJobs","maxJobsToExecute","error","expose","shouldBeDisposed","global","mayConsume","sync","wrapped","register","handleOrCode","_unwrapResult","unregister","unregisterAll","targets","startSync","endSync","wrappedT","wrappedH","_unwrapHandle","unwrappedH","proxyKeySymbol","proxyKeySymbolHandle","syncMode","rec","Proxy","Reflect","receiver","receiverHandle","deleteProperty","recHandle","wrap","res","wrapHandle","max","_"],"mappings":"6jDAEqBA,cAcnB,WAAYC,mBAbZA,eACAC,MAA0B,IAAIC,SAC9BC,MAA0B,IAAID,SAC9BE,MAAoC,IAAIF,SACxCG,MAAoC,IAAIH,SACxCI,YAAgC,IAAIJ,SACpCK,aAAmC,IAAIC,SACvCC,oBACAC,oBACAC,uBACAC,sBACAC,SAAW,EAGTC,KAAKd,GAAKA,EAEV,IAAMe,EAASf,EACZgB,aACChB,EAAGiB,w0BAyBJC,QAAQ,SAACC,UAAOC,EAAKC,MAAMF,OAAIG,KAElCR,KAAKL,QAAUT,EAAGuB,QAAQR,EAAQ,OAClCD,KAAKJ,QAAUV,EAAGuB,QAAQR,EAAQ,OAClCD,KAAKH,WAAaX,EAAGuB,QAAQR,EAAQ,UACrCD,KAAKF,UAAYZ,EAAGuB,QAAQR,EAAQ,SAEpCA,EAAOS,UAEPV,KAAKP,aAAakB,IAAIX,KAAKL,SAC3BK,KAAKP,aAAakB,IAAIX,KAAKJ,SAC3BI,KAAKP,aAAakB,IAAIX,KAAKH,YAC3BG,KAAKP,aAAakB,IAAIX,KAAKF,wCAG7Bc,IAAA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ACL7K,KAAK8L,WACL9L,KAAKoM,cAITyB,cAAA,SAAc5I,GACZ,OAAO0E,EAAa3J,KAAKd,GAAI+F,EAAQjF,KAAK6K,8DjB5SnBpI,EAAYmM,GACrC,OAAO/K,EAAWpB,EAAOmM,EAAM,SAACC,EAAGjO,UAAQA,EAAIsC,KAAO0L,QAAMpO,GAAW0C"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { QuickJSVm, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
-
export default function unmarshalFunction(vm: QuickJSVm, handle: QuickJSHandle, marshal: (value: unknown) => [QuickJSHandle, boolean], unmarshal: (handle: QuickJSHandle) => [unknown, boolean], preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined): Function | undefined;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { QuickJSVm, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
-
export declare type Options = {
|
|
3
|
-
vm: QuickJSVm;
|
|
4
|
-
marshal: (target: unknown) => [QuickJSHandle, boolean];
|
|
5
|
-
find: (handle: QuickJSHandle) => unknown | undefined;
|
|
6
|
-
pre: <T>(target: T, handle: QuickJSHandle) => T | undefined;
|
|
7
|
-
};
|
|
8
|
-
export declare function unmarshal(handle: QuickJSHandle, options: Options): any;
|
|
9
|
-
export default unmarshal;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { QuickJSVm, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
-
export default function unmarshalObject(vm: QuickJSVm, handle: QuickJSHandle, unmarshal: (handle: QuickJSHandle) => [unknown, boolean], preUnmarshal: <T>(target: T, handle: QuickJSHandle) => T | undefined): object | undefined;
|
package/dist/util.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare function isES2015Class(cls: any): cls is new (...args: any[]) => any;
|
|
2
|
-
export declare function isObject(value: any): value is object | Function;
|
|
3
|
-
export declare function walkObject(value: any, callback?: (target: any, set: Set<any>) => boolean | void): Set<any>;
|
|
4
|
-
/**
|
|
5
|
-
* 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.
|
|
6
|
-
*/
|
|
7
|
-
export declare function complexity(value: any, max?: number): number;
|
package/dist/vmmap.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { QuickJSVm, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
-
export default class VMMap {
|
|
3
|
-
vm: QuickJSVm;
|
|
4
|
-
_map1: Map<any, number>;
|
|
5
|
-
_map2: Map<any, number>;
|
|
6
|
-
_map3: Map<number, QuickJSHandle>;
|
|
7
|
-
_map4: Map<number, QuickJSHandle>;
|
|
8
|
-
_counterMap: Map<number, any>;
|
|
9
|
-
_disposables: Set<QuickJSHandle>;
|
|
10
|
-
_mapGet: QuickJSHandle;
|
|
11
|
-
_mapSet: QuickJSHandle;
|
|
12
|
-
_mapDelete: QuickJSHandle;
|
|
13
|
-
_mapClear: QuickJSHandle;
|
|
14
|
-
_counter: number;
|
|
15
|
-
constructor(vm: QuickJSVm);
|
|
16
|
-
set(key: any, handle: QuickJSHandle, key2?: any, handle2?: QuickJSHandle): boolean;
|
|
17
|
-
merge(iteratable: Iterable<[any, QuickJSHandle | undefined] | [any, QuickJSHandle | undefined, any, QuickJSHandle | undefined]> | undefined): void;
|
|
18
|
-
get(key: any): QuickJSHandle | undefined;
|
|
19
|
-
getByHandle(handle: QuickJSHandle): any;
|
|
20
|
-
has(key: any): boolean;
|
|
21
|
-
hasHandle(handle: QuickJSHandle): boolean;
|
|
22
|
-
delete(key: any, dispose?: boolean): void;
|
|
23
|
-
deleteByHandle(handle: QuickJSHandle, dispose?: boolean): void;
|
|
24
|
-
clear(): void;
|
|
25
|
-
dispose(): void;
|
|
26
|
-
get size(): number;
|
|
27
|
-
[Symbol.iterator](): Iterator<[
|
|
28
|
-
any,
|
|
29
|
-
QuickJSHandle,
|
|
30
|
-
any,
|
|
31
|
-
QuickJSHandle | undefined
|
|
32
|
-
]>;
|
|
33
|
-
_get2(num: number): any;
|
|
34
|
-
_call(fn: QuickJSHandle, thisArg: QuickJSHandle | undefined, ...args: QuickJSHandle[]): QuickJSHandle;
|
|
35
|
-
}
|
package/dist/vmutil.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { QuickJSVm, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
-
export declare function call(vm: QuickJSVm, code: string, thisArg?: QuickJSHandle, ...args: QuickJSHandle[]): QuickJSHandle;
|
|
3
|
-
export declare function eq(vm: QuickJSVm, a: QuickJSHandle, b: QuickJSHandle): boolean;
|
|
4
|
-
export declare function instanceOf(vm: QuickJSVm, a: QuickJSHandle, b: QuickJSHandle): boolean;
|
|
5
|
-
export declare function isHandleObject(vm: QuickJSVm, a: QuickJSHandle): boolean;
|
|
6
|
-
export declare function json(vm: QuickJSVm, target: any): QuickJSHandle;
|
|
7
|
-
export declare function consumeAll<T extends QuickJSHandle[], K>(handles: T, cb: (handles: T) => K): K;
|
|
8
|
-
export declare function mayConsume<T>([handle, shouldBeDisposed]: [QuickJSHandle, boolean], fn: (h: QuickJSHandle) => T): T;
|
|
9
|
-
export declare function mayConsumeAll<T, H extends QuickJSHandle[]>(handles: {
|
|
10
|
-
[P in keyof H]: [QuickJSHandle, boolean];
|
|
11
|
-
}, fn: (...args: H) => T): T;
|
package/dist/wrapper.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { QuickJSVm, QuickJSHandle } from "quickjs-emscripten";
|
|
2
|
-
export declare type SyncMode = "both" | "vm" | "host";
|
|
3
|
-
export declare type Wrapped<T> = T & {
|
|
4
|
-
__qes_wrapped: never;
|
|
5
|
-
};
|
|
6
|
-
export declare function wrap<T = any>(vm: QuickJSVm, target: T, proxyKeySymbol: symbol, proxyKeySymbolHandle: QuickJSHandle, marshal: (target: any) => [QuickJSHandle, boolean], syncMode?: (target: T) => SyncMode | undefined): Wrapped<T> | undefined;
|
|
7
|
-
export declare function wrapHandle(vm: QuickJSVm, handle: QuickJSHandle, proxyKeySymbol: symbol, proxyKeySymbolHandle: QuickJSHandle, unmarshal: (handle: QuickJSHandle) => any, syncMode?: (target: QuickJSHandle) => SyncMode | undefined): [Wrapped<QuickJSHandle> | undefined, boolean];
|
|
8
|
-
export declare function unwrap<T>(obj: T, key: string | symbol): T;
|
|
9
|
-
export declare function unwrapHandle(vm: QuickJSVm, handle: QuickJSHandle, key: QuickJSHandle): [QuickJSHandle, boolean];
|
|
10
|
-
export declare function isWrapped<T>(obj: T, key: string | symbol): obj is Wrapped<T>;
|
|
11
|
-
export declare function isHandleWrapped(vm: QuickJSVm, handle: QuickJSHandle, key: QuickJSHandle): handle is Wrapped<QuickJSHandle>;
|