Skip to content

Add optional WHATWG Streams polyfill#208

Open
matthargett wants to merge 2 commits into
BabylonJS:mainfrom
rebeckerspecialties:web-streams-polyfill
Open

Add optional WHATWG Streams polyfill#208
matthargett wants to merge 2 commits into
BabylonJS:mainfrom
rebeckerspecialties:web-streams-polyfill

Conversation

@matthargett

@matthargett matthargett commented Jul 22, 2026

Copy link
Copy Markdown

What

Adds optional WHATWG ReadableStream, WritableStream, TransformStream, BYOB, controller, reader/writer, and queuing-strategy globals. The implementation pins the ES5 web-streams-polyfill 4.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.

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

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 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 Streams polyfill library that embeds and evaluates a pinned web-streams-polyfill ponyfill 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.

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