( code, sourcePathname, globals = [], staticContentManifest, kvNamespaces )
| 16 | * @param {import('../kv.js').KVNamespaceInit[]} kvNamespaces Workers KV namespaces. |
| 17 | */ |
| 18 | export 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 |
no test coverage detected