({
script,
context,
}: {
script: string;
context: RequestContext;
})
| 126 | }; |
| 127 | |
| 128 | export const runScriptInQuickJs = async ({ |
| 129 | script, |
| 130 | context, |
| 131 | }: { |
| 132 | script: string; |
| 133 | context: RequestContext; |
| 134 | }): Promise<RequestContext> => { |
| 135 | // The worker and the pending entry are set up before awaiting the token, so a crash during the |
| 136 | // token round trip still rejects this call through the `error` listener rather than hanging. |
| 137 | const instance = getWorker(); |
| 138 | const id = `quickjs-${Date.now()}-${Math.random().toString(36).slice(2)}`; |
| 139 | const result = new Promise<RequestContext>((resolve, reject) => { |
| 140 | pending.set(id, { resolve, reject, instance }); |
| 141 | }); |
| 142 | |
| 143 | const authToken = await getTemplatingDbAuthToken(); |
| 144 | instance.postMessage({ id, script, context, authToken }); |
| 145 | |
| 146 | return result; |
| 147 | }; |
no test coverage detected