Make blob: URLs cross‑realm and allow file‑backed Blob cloning#63103
Open
jimmywarting wants to merge 1 commit intonodejs:mainfrom
Open
Make blob: URLs cross‑realm and allow file‑backed Blob cloning#63103jimmywarting wants to merge 1 commit intonodejs:mainfrom
jimmywarting wants to merge 1 commit intonodejs:mainfrom
Conversation
Detailed description: - Add a global native blob URL registry so blob: URLs created in one realm are resolvable in another (e.g. main → worker). Registry entries store the DataQueue and metadata, are mutex‑protected, and are cleaned up via Environment cleanup hooks to avoid teardown races. - Extend the DataQueue / Entry reader API to accept an optional `Environment*`, and update `FdEntry` reader creation so file handles and reader resources are created in the target environment/realm. This enables structured cloning / transferring of file‑backed Blobs across workers. - Remove the JS-side prohibition on cloning file‑backed blobs so `structuredClone()` succeeds for file‑backed Blobs. - Wire up Blob native bindings to use the new registry when storing/getting/revoking blob URLs; ensure Blob::GetDataObject constructs the Blob in the receiving environment. - Add/update regression tests covering URL resolution in workers and cloning of file‑backed Blobs. Files changed (high level): - **node_blob.cc**: add global blob URL registry, Store/Get/Revoke helpers, env cleanup hook integration, Blob::StoreDataObject/GetDataObject/RevokeObjectURL wiring. - **queue.h**, **queue.cc**: add optional `Environment*` parameter to `Entry::get_reader`, propagate env through DataQueue, implement `FdEntry::ReaderImpl::Create(entry, env)` to open file handles in the reader env. - **blob.js**: remove `kNotCloneable` flag for file‑backed Blobs so they can be cloned/ transferred. - **test-blob-url-worker.js**: new/updated regression test validating `resolveObjectURL` in a worker for a URL created on the main thread. - **test-blob-file-backed.js**: update test to assert `structuredClone()` succeeds for file‑backed Blobs and that cloned content/metadata match. Rationale and tests: - These changes fix two related issues: blob URLs that only worked per‑realm, and file‑backed Blobs that were prevented from being cloned/transferred. Both were blocking cross‑realm Blob usage (main ↔ worker). All added/updated tests pass in the local test harness used during development.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63103 +/- ##
==========================================
- Coverage 89.65% 89.63% -0.02%
==========================================
Files 712 712
Lines 220512 220841 +329
Branches 42289 42374 +85
==========================================
+ Hits 197690 197953 +263
- Misses 14663 14706 +43
- Partials 8159 8182 +23
🚀 New features to boost your workflow:
|
Contributor
|
Can you address the linter failure and fix the commit message please? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Detailed description:
Environment*, and updateFdEntryreader creation so file handles and reader resources are created in the target environment/realm. This enables structured cloning / transferring of file‑backed Blobs across workers.structuredClone()succeeds for file‑backed Blobs.Files changed (high level):
Environment*parameter toEntry::get_reader, propagate env through DataQueue, implementFdEntry::ReaderImpl::Create(entry, env)to open file handles in the reader env.kNotCloneableflag for file‑backed Blobs so they can be cloned/ transferred.resolveObjectURLin a worker for a URL created on the main thread.structuredClone()succeeds for file‑backed Blobs and that cloned content/metadata match.Rationale and tests: