MCPcopy
hub / github.com/cloudflare/capnweb / apply

Method apply

src/map.ts:250–277  ·  view source on GitHub ↗
(instructions: unknown[])

Source from the content-addressed store, hash-verified

248 }
249
250 apply(instructions: unknown[]): RpcPayload {
251 try {
252 if (instructions.length < 1) {
253 throw new Error("Invalid empty mapper function.");
254 }
255
256 for (let instruction of instructions.slice(0, -1)) {
257 let payload = new Evaluator(this).evaluateCopy(instruction);
258
259 // The payload almost always contains a single stub. As an optimization, unwrap it.
260 if (payload.value instanceof RpcStub) {
261 let hook = unwrapStubNoProperties(payload.value);
262 if (hook) {
263 this.variables.push(hook);
264 continue;
265 }
266 }
267
268 this.variables.push(new PayloadStubHook(payload));
269 }
270
271 return new Evaluator(this).evaluateCopy(instructions[instructions.length - 1]);
272 } finally {
273 for (let variable of this.variables) {
274 variable.dispose();
275 }
276 }
277 }
278
279 importStub(idx: ImportId): StubHook {
280 // This implies we saw an "export" appear inside the body of a mapper function. This should be

Callers 5

applyMapToElementFunction · 0.95
getFunction · 0.80
applyFunction · 0.80
callValidatedThenFunction · 0.80
wrapPrototypeMethodsFunction · 0.80

Calls 3

unwrapStubNoPropertiesFunction · 0.85
evaluateCopyMethod · 0.80
disposeMethod · 0.65

Tested by

no test coverage detected