MCPcopy Create free account
hub / github.com/cfworker/cfworker / executeWorkerScript

Function executeWorkerScript

packages/dev/src/runtime/index.js:18–39  ·  view source on GitHub ↗
(
  code,
  sourcePathname,
  globals = [],
  staticContentManifest,
  kvNamespaces
)

Source from the content-addressed store, hash-verified

16 * @param {import('../kv.js').KVNamespaceInit[]} kvNamespaces Workers KV namespaces.
17 */
18export async function executeWorkerScript(
19 code,
20 sourcePathname,
21 globals = [],
22 staticContentManifest,
23 kvNamespaces
24) {
25 resetFetchHandler();
26 const scope = new ServiceWorkerGlobalScope(
27 globals,
28 staticContentManifest,
29 kvNamespaces
30 );
31 await scope.init();
32 const guardedScope = new Proxy(scope, scopeGuard);
33 const sourceUrl = `//# sourceURL=${location.origin}${sourcePathname}`;
34 const fn = new AsyncFunction(
35 '__guardedScope__',
36 `with(__guardedScope__) {\n${code}\n}\n${sourceUrl}`
37 );
38 fn(guardedScope);
39}
40
41/**
42 * @param {string} url

Callers 1

setWorkerCodeMethod · 0.85

Calls 2

initMethod · 0.95
resetFetchHandlerFunction · 0.90

Tested by

no test coverage detected