Skip to content

Complete Blob streaming and slicing support#209

Open
matthargett wants to merge 4 commits into
BabylonJS:mainfrom
rebeckerspecialties:blob-stream-polyfill
Open

Complete Blob streaming and slicing support#209
matthargett wants to merge 4 commits into
BabylonJS:mainfrom
rebeckerspecialties:blob-stream-polyfill

Conversation

@matthargett

@matthargett matthargett commented Jul 22, 2026

Copy link
Copy Markdown

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 byte stream() support. Blob composition and slicing share immutable native segments; stream reads allocate only the requested 64 KiB-or-smaller JavaScript chunk. File delegates 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 pipeTo coverage.

Validated with:

  • JavaScriptCore ASan/UBSan: 235 JS cases plus native tests
  • JavaScriptCore TSan: 235 JS cases plus native tests
  • QuickJS Release: 235 JS cases plus native tests

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.
Copilot AI review requested due to automatic review settings July 22, 2026 05:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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::Streams module that installs missing Web Streams globals from a vendored web-streams-polyfill ponyfill.
  • Extend the native Blob polyfill with iterable BlobPart handling, MIME/endings normalization, slice(), and chunked byte stream() support built on shared immutable segments.
  • Update File to delegate slice()/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.

Comment thread Polyfills/Blob/Source/Blob.cpp Outdated
Comment thread Polyfills/Streams/Source/Streams.cpp
Comment thread Tests/UnitTests/Shared/Shared.cpp Outdated
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.
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