Repository navigation
Improve management of bundled sources - #8387
Conversation
A non-ASCII character in a shipped source is read as its UTF-8 bytes by the per-isolate bootstrap, and in a module makes V8 store the file as two-byte. vectorize-api.ts logged a garbled ellipsis for this reason; the rest are em dashes and arrows in comments.
api::node::ModuleSource becomes jsg::ModuleSource. The legacy registry's addBuiltinBundle(), the new registry's getBuiltInBundleFromCapnp() and runPerIsolateBootstrap() accept one, and the cloudflare bundle is registered with it. Worker::Api gains getModuleSource() so the bootstrap can be served the same way.
There was a problem hiding this comment.
💬 Approved with comments — A clean refactor that leaves the default (no ModuleSource) paths as they were. The only notes are informational: no test covers a non-null ModuleSource, nothing keeps the shipped sources ASCII, and the new hook is not documented.
Findings: 3 info (3 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 2 info
No logic errors. No test covers a non-null ModuleSource, and nothing keeps the shipped sources ASCII.
Recommendation: 💬 Optional Nits
- [INFO] No test exercises the non-null
ModuleSourcebranch in the bootstrap or in the module registries. (src/workerd/api/per-isolate-bootstrap.c++:795) - [INFO] Nothing enforces that bundled sources stay ASCII; the next non-ASCII character would be garbled again on the bootstrap path without a ModuleSource. (
src/cloudflare/internal/vectorize-api.ts:327)
View full review
The ModuleSource plumbing is consistent across the per-isolate bootstrap, the legacy registry (addBuiltinModule / addBuiltinBundle), the new registry (getBuiltInBundleFromCapnp) and Worker::Api::getModuleSource(). With a null pointer, each of these behaves as before.
- Nothing in the repository supplies a non-null
ModuleSource, so the new branches never run in its tests. - The ASCII requirement for the bootstrap path without a
ModuleSourceis kept by hand. Nothing rejects a stray non-ASCII character that a later change adds.
📝 Documentation: 💬 1 info
The new embedder hook is not described in the module-registry documentation.
Recommendation: 💬 Optional Nits
- [INFO] The
ModuleSource/getModuleSource()embedder hook is not described indocs/jsg.md. (src/workerd/io/worker.h:668)
View full review
docs/jsg.md documents how built-in modules are registered and says ESM source must live for the whole process. It does not mention that an embedder can supply other source storage through jsg::ModuleSource and Worker::Api::getModuleSource().
✅ All other checks passed
🔒 Security: ✅ LGTM
No security problems found. With a null ModuleSource, the code takes the same path as before. A non-null one serves sources from storage the embedder controls, and jsg/module-source.h states the lifetime requirement.
📖 AGENTS.md: ✅ LGTM
No problems in the changed lines.
⚡ Performance: ✅ LGTM
No performance concerns.
Reviewed commit: 039ec757
The sources that we provide need special treatment and should also be
ASCII so we don't have to transcode to UTF-16. This was already the
case for node, but these two commits do the same for the other ones.