Complete Blob streaming and slicing support#209
Open
matthargett wants to merge 4 commits into
Open
Conversation
Vendor the ES5 web-streams-polyfill 4.3.0 ponyfill and expose an idempotent Streams initializer that preserves constructors supplied by the selected JavaScript engine. Cover readable, writable, transform, BYOB, error, tee, subclassing, and host-constructor behavior with focused ports from WPT plus Firefox and Chromium regression tests. Validate the implementation on JavaScriptCore under ASan/UBSan and QuickJS Release.
Implement iterable BlobPart conversion, MIME and endings normalization, zero-copy Blob composition and slicing, and lazy 64 KiB byte streams. Delegate File streaming and slicing to its backing Blob while preserving browser class identity.\n\nUse immutable shared segments so nested Blob and slice construction do not duplicate payload bytes. Add focused WPT, WebKit, and Firefox regression coverage for constructor ordering, iterator closure, UTF-8 decoding, BYOB reads, cancellation, lifetime safety, and large nested streams.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds full Blob composition/slicing/streaming support and wires in an optional WHATWG Web Streams ponyfill so Blob.stream() works consistently across engines.
Changes:
- Add
Babylon::Polyfills::Streamsmodule that installs missing Web Streams globals from a vendoredweb-streams-polyfillponyfill. - Extend the native
Blobpolyfill with iterableBlobParthandling, MIME/endings normalization,slice(), and chunked bytestream()support built on shared immutable segments. - Update
Fileto delegateslice()/stream()to its backing Blob and expand unit/regression tests for Streams + Blob/File behaviors.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/UnitTests/Shared/Shared.cpp | Initializes Streams in the JS test harness and adds a C++ Streams idempotence/preservation test. |
| Tests/UnitTests/Scripts/tests.ts | Adds focused Streams tests plus extensive Blob/File constructor, slice, and stream coverage. |
| Tests/UnitTests/CMakeLists.txt | Links the new Streams library into the unit test target. |
| Polyfills/Streams/ThirdParty/web-streams-polyfill/ponyfill.es5.js | Vendors the ES5 ponyfill bundle used to provide Streams globals. |
| Polyfills/Streams/ThirdParty/web-streams-polyfill/LICENSE | Adds upstream MIT license text for the vendored ponyfill. |
| Polyfills/Streams/Source/StreamsScripts.h.in | Generates an embedded JS source blob for the ponyfill at configure-time. |
| Polyfills/Streams/Source/Streams.cpp | Implements Streams::Initialize to conditionally install missing constructors. |
| Polyfills/Streams/README.md | Documents behavior and provenance of the Streams ponyfill integration. |
| Polyfills/Streams/Include/Babylon/Polyfills/Streams.h | Declares the Streams initialization API. |
| Polyfills/Streams/CMakeLists.txt | Builds Streams library and embeds the ponyfill source into a generated header. |
| Polyfills/File/Source/File.h | Adds slice()/stream() declarations to File’s native wrapper. |
| Polyfills/File/Source/File.cpp | Delegates File slicing/streaming to the backing Blob and sets [Symbol.toStringTag]. |
| Polyfills/CMakeLists.txt | Adds conditional build of the Streams polyfill module. |
| Polyfills/Blob/Source/Blob.h | Refactors Blob storage to shared immutable segments and declares slice()/stream(). |
| Polyfills/Blob/Source/Blob.cpp | Implements iterable parts, options normalization, slicing across segments, and chunked streaming. |
| Polyfills/Blob/README.md | Documents Blob streaming/slicing and the Streams dependency for stream(). |
| Polyfills/Blob/CMakeLists.txt | Includes Blob README in the build sources list. |
| CMakeLists.txt | Adds a build option to enable/disable the Streams polyfill. |
Files not reviewed (1)
- Polyfills/Streams/ThirdParty/web-streams-polyfill/ponyfill.es5.js: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace a partial or null host Streams surface as a complete constructor suite so stream products retain compatible instanceof relationships. Preserve a complete suite on repeated initialization.\n\nHarden the native initialization test so N-API failures complete the test promise instead of hanging, and cover partial host replacement plus null handling and cross-constructor compatibility.
Use ReadableByteStreamController.byobRequest views directly and respond with the produced byte count instead of allocating and enqueueing a 64 KiB intermediate chunk. Keep the existing bounded allocation path for default readers.\n\nAdd WPT-derived coverage for small offset BYOB views that cross immutable Blob segment boundaries.
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.
Depends on #208. The commits are kept separate so this PR can be rebased to only the Blob change after the Streams prerequisite lands. These are for the five deterministic screenshot test suite failures in scenes 66, 72, 73, 123, and 140, all explicitly blocked on real Blob.stream/Response/decompression support. Besides helping unblock more of the suite, this makes BabylonJS browser apps much more likely to "just work" in BabylonNative.
Adds iterable BlobPart handling, MIME/endings normalization,
slice(), and lazy bytestream()support. Blob composition and slicing share immutable native segments; stream reads allocate only the requested 64 KiB-or-smaller JavaScript chunk.Filedelegates the same APIs to its backing Blob.Focused regression coverage is adapted from WPT FileAPI Blob tests, WebKit Blob stream chunk/crash tests, and Firefox large
pipeTocoverage.Validated with: