MCPcopy Create free account
hub / github.com/Kong/insomnia / runScriptInQuickJs

Function runScriptInQuickJs

packages/insomnia/src/scripting/run-script-quickjs.ts:128–147  ·  view source on GitHub ↗
({
  script,
  context,
}: {
  script: string;
  context: RequestContext;
})

Source from the content-addressed store, hash-verified

126};
127
128export 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};

Callers 2

asyncWorkerFunction · 0.90

Calls 5

getWorkerFunction · 0.85
getTemplatingDbAuthTokenFunction · 0.70
toStringMethod · 0.45
setMethod · 0.45
postMessageMethod · 0.45

Tested by

no test coverage detected