Skip to content

Add optional WHATWG Streams polyfill - #208

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

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

Conversation

@matthargett

@matthargett matthargett commented Jul 22, 2026 •

Copy link
Copy Markdown

Optional WHATWG Streams polyfill: ReadableStream, WritableStream, TransformStream, BYOB, controllers, readers/writers and queuing strategies.

  • 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.
  • The embedded source is assembled at compile time into read-only storage; initialization does not build or retain a second native script buffer.
  • Motivation: five deterministic screenshot failures in BabylonNative's validation suite (scenes 66, 72, 73, 123, 140) are blocked on real Blob.stream, Response and decompression support, and browser-targeted Babylon.js apps become more likely to just work.

Tests

  • Queue ordering, pull failures, tee, backpressure, byte/BYOB streams, subclassing, invalid transform enqueues, idempotence and host-constructor preservation, adapted from the Streams WPT plus Firefox and Chromium regressions (the vendored release also runs the Streams WPT corpus at its pinned revision).
  • tests.streams.ts and Tests.Streams.cpp; validated on JavaScriptCore under ASan/UBSan and on QuickJS Release.

Stack

First of the polyfill series: this → #211 Compression and #209 Blob streaming → #210 Headers/Response → #212 data: fetch → #258 Worker. Current with main @ 62818ee (#257's per-feature test layout).

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 Outdated
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.
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.
…nto the Android test host

MSVC caps a single string literal at 16,380 bytes (C2026) and a concatenated one at
65,535; the 71 KB bundle was emitted as two 60,000/11,188-byte raw strings, so every
Windows and UWP job failed at "Build Solution". CMake now emits consecutive parts of
at most 16,000 bytes, abutting with no separator (the split stays byte-transparent),
and a variadic consteval Join reassembles them into the same std::array as before.

The desktop UnitTests target links Streams for the Shared.cpp coverage but the
Android UnitTestsJNI host did not, so the Android build failed on the include.
…abylonJS#257)

The Streams suite moves from the monolithic tests.ts to Source/Scripts/tests.streams.ts, the native
idempotency test to Source/Tests.Streams.cpp, and the JavaScript suite initializes Streams before
Blob/File (Blob.stream() and Response bodies build on it) in Source/Tests.JavaScript.cpp.
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