UNPKG

@sebastianwessel/quickjs

Version:

A typescript package to execute JavaScript and TypeScript code in a WebAssembly QuickJS sandbox

17 lines (16 loc) 515 B
export const call = (ctx, fileName, code, that, ...args) => { const fnHandle = ctx.unwrapResult(ctx.evalCode(code, fileName)); try { const callHandle = ctx.unwrapResult(ctx.callFunction(fnHandle, that || ctx.undefined, ...args)); return callHandle; } catch (error) { console.error(error); const e = new Error(error.message ?? 'Function call failed in serialization'); e.cause = error; throw e; } finally { fnHandle.dispose(); } };