* Wrap the existing IIFE-returning string in an ES module that exposes a * `fetch` handler. The child Worker's entrypoint runs the IIFE on each * invocation and returns the structured result as JSON.
(wrappedCode: string)
| 69 | * invocation and returns the structured result as JSON. |
| 70 | */ |
| 71 | function wrapAsSandboxModule(wrappedCode: string): string { |
| 72 | return ` |
| 73 | export default { |
| 74 | async fetch() { |
| 75 | const __result = await ${wrappedCode}; |
| 76 | return new Response(JSON.stringify(__result), { |
| 77 | headers: { 'Content-Type': 'application/json' }, |
| 78 | }); |
| 79 | } |
| 80 | }; |
| 81 | ` |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Execute code in a freshly loaded child Worker isolate. |