Add support for request-time WebAssembly compilation - #6938
Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This PR adds a request_time_webassembly_compilation experimental compat flag that enables request-time WebAssembly.compile(), byte-based instantiate(), and new Module() by wrapping them with a shim that snapshots input bytes before compilation and records them via embedder hooks.
Overall this is well-structured: the compat flag is correctly $experimental with no enable date, the JS shim captures trusted intrinsics to prevent tampering, the C++ callback properly bridges V8/KJ exceptions, and the shim layering with wasm-instantiate-shim.js composes correctly. Two findings:
- [MEDIUM] Hardcoded limit in error message may drift from the production implementation.
- [LOW]
originalCompileis captured but never used in the JS shim.
This review was generated by an AI assistant and may contain inaccuracies.
|
I'm Bonk, and I've done a quick review of your PR. This PR adds a What looks good:
Two findings posted as inline review comments:
|
|
The generated output of Full Type Diffdiff -r types/generated-snapshot/index.d.ts bazel-bin/types/definitions/index.d.ts
266c266,271
< abstract class Module {
---
> interface CompileOptions {
> builtins?: string[];
> importedStringConstants?: string;
> }
> class Module {
> constructor(bytes: BufferSource, options?: CompileOptions);
283a289,301
> interface WebAssemblyInstantiatedSource {
> instance: Instance;
> module: Module;
> }
> function compile(
> bytes: BufferSource,
> options?: CompileOptions,
> ): Promise<Module>;
> function instantiate(
> bytes: BufferSource,
> imports?: Imports,
> options?: CompileOptions,
> ): Promise<WebAssemblyInstantiatedSource>;
diff -r types/generated-snapshot/index.ts bazel-bin/types/definitions/index.ts
266c266,271
< abstract class Module {
---
> interface CompileOptions {
> builtins?: string[];
> importedStringConstants?: string;
> }
> class Module {
> constructor(bytes: BufferSource, options?: CompileOptions);
283a289,301
> interface WebAssemblyInstantiatedSource {
> instance: Instance;
> module: Module;
> }
> function compile(
> bytes: BufferSource,
> options?: CompileOptions,
> ): Promise<Module>;
> function instantiate(
> bytes: BufferSource,
> imports?: Imports,
> options?: CompileOptions,
> ): Promise<WebAssemblyInstantiatedSource>; |
c7dc9e0 to
513bc91
Compare
Add the request_time_webassembly_compilation compatibility flag and keep the feature disabled by default. Wrap WebAssembly.compile(), byte-based instantiate(), and Module() to snapshot exact input bytes before compilation. Await retention for promise APIs and queue best-effort retention for the synchronous constructor. Expose embedder upload hooks and per-request admission accounting while keeping eval() and Function() disabled. Preserve startup compilation and existing WebAssembly API behavior.
513bc91 to
b8462ed
Compare
Add the request_time_webassembly_compilation compatibility flag and keep the feature disabled by default.
Wrap WebAssembly.compile(), byte-based instantiate(), and Module() to snapshot exact input bytes before compilation.
Await retention for promise APIs and queue best-effort retention for the synchronous constructor.
Expose embedder upload hooks and per-request admission accounting while keeping eval() and Function() disabled. Preserve startup compilation and existing WebAssembly API behavior.