-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wrangler] fix: make sure
getPlatformProxy
's ctx
methods throw il…
…legal invocation errors like workerd (#6199)
- Loading branch information
1 parent
286cdd6
commit 88313e5
Showing
3 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: make sure `getPlatformProxy`'s `ctx` methods throw illegal invocation errors like workerd | ||
|
||
in workerd detaching the `waitUntil` and `passThroughOnException` methods from the `ExecutionContext` | ||
object results in them throwing `illegal invocation` errors, such as for example: | ||
|
||
```js | ||
export default { | ||
async fetch(_request, _env, { waitUntil }) { | ||
waitUntil(() => {}); // <-- throws an illegal invocation error | ||
return new Response("Hello World!"); | ||
}, | ||
}; | ||
``` | ||
|
||
make sure that the same behavior is applied to the `ctx` object returned by `getPlatformProxy` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
packages/wrangler/src/api/integrations/platform/executionContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
export class ExecutionContext { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, unused-imports/no-unused-vars | ||
waitUntil(promise: Promise<any>): void {} | ||
passThroughOnException(): void {} | ||
waitUntil(promise: Promise<any>): void { | ||
if (!(this instanceof ExecutionContext)) { | ||
throw new Error("Illegal invocation"); | ||
} | ||
} | ||
passThroughOnException(): void { | ||
if (!(this instanceof ExecutionContext)) { | ||
throw new Error("Illegal invocation"); | ||
} | ||
} | ||
} |