Add optional WHATWG Streams polyfill#208
Open
matthargett wants to merge 2 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.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new optional Web Streams polyfill module to JsRuntimeHost, embedding the ES5 web-streams-polyfill ponyfill at build time and initializing it only when required, plus adds unit coverage for core Streams behaviors.
Changes:
- Introduces a new
Streamspolyfill library that embeds and evaluates a pinnedweb-streams-polyfillponyfill bundle. - Adds a new CMake option (
JSRUNTIMEHOST_POLYFILL_STREAMS) and wires the Streams target into the build and unit tests. - Adds C++ and TypeScript unit tests covering constructor presence and selected Streams semantics (queueing, tee, backpressure, BYOB, subclassing, invalid enqueues).
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/UnitTests/Shared/Shared.cpp | Initializes Streams polyfill in the JS test runtime and adds a C++ idempotence/constructor-preservation test. |
| Tests/UnitTests/Scripts/tests.ts | Adds focused Web Streams behavior tests adapted from WPT and browser regressions. |
| Tests/UnitTests/CMakeLists.txt | Links the new Streams polyfill library into the UnitTests target. |
| Polyfills/Streams/ThirdParty/web-streams-polyfill/ponyfill.es5.js | Vendors the pinned ES5 ponyfill bundle. |
| Polyfills/Streams/ThirdParty/web-streams-polyfill/LICENSE | Adds upstream MIT license text. |
| Polyfills/Streams/Source/StreamsScripts.h.in | Generates embedded JS source storage with compile-time concatenation. |
| Polyfills/Streams/Source/Streams.cpp | Implements Streams::Initialize to conditionally evaluate and install globals. |
| Polyfills/Streams/README.md | Documents the Streams polyfill scope and pinned upstream revisions. |
| Polyfills/Streams/Include/Babylon/Polyfills/Streams.h | Public header exposing Streams::Initialize. |
| Polyfills/Streams/CMakeLists.txt | Adds Streams library build rules and embeds the JS ponyfill at configure time. |
| Polyfills/CMakeLists.txt | Conditionally adds the Streams subdirectory based on the new option. |
| CMakeLists.txt | Adds JSRUNTIMEHOST_POLYFILL_STREAMS option. |
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.
This was referenced Jul 22, 2026
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.
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.
What
Adds optional WHATWG
ReadableStream,WritableStream,TransformStream, BYOB, controller, reader/writer, and queuing-strategy globals. The implementation pins the ES5web-streams-polyfill4.3.0 ponyfill, based on the WHATWG reference implementation, and only fills constructors the selected engine does not supply.This is 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.
The embedded source is assembled at compile time into read-only storage; initialization does not build or retain a second native script buffer.
Coverage
Focused tests cover queue ordering, pull failures, tee, backpressure, byte/BYOB streams, subclassing, invalid transform enqueues, idempotence, and preserving host constructors. They are adapted from Streams WPT plus Firefox and Chromium regressions; the vendored release also runs the Streams WPT corpus at its pinned revision.
Validated with 217 JavaScript tests plus native tests on JavaScriptCore under ASan/UBSan and QuickJS Release.