Skip to content

Improve management of bundled sources - #8387

Merged
erikcorry merged 2 commits into
mainfrom
erikcorry/manage-own-sources
Nov 12, 2026
Merged

erikcorry merged 2 commits into
mainfrom
erikcorry/manage-own-sources

Conversation

@erikcorry

Copy link
Copy Markdown
Contributor

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.

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.
@erikcorry
erikcorry requested review from a team as code owners November 12, 2026 09:46
@erikcorry
erikcorry requested a review from floitsch November 12, 2026 09:47

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 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 ModuleSource branch 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 ModuleSource is 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 in docs/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

Comment thread src/workerd/io/worker.h Resolved
@erikcorry
erikcorry merged commit 1074b58 into main Nov 12, 2026
50 of 53 checks passed
@erikcorry
erikcorry deleted the erikcorry/manage-own-sources branch November 12, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants