Skip to content

Add CompressionStream and DecompressionStream polyfills#211

Open
matthargett wants to merge 3 commits into
BabylonJS:mainfrom
rebeckerspecialties:compression-stream-polyfill
Open

Add CompressionStream and DecompressionStream polyfills#211
matthargett wants to merge 3 commits into
BabylonJS:mainfrom
rebeckerspecialties:compression-stream-polyfill

Conversation

@matthargett

@matthargett matthargett commented Jul 22, 2026

Copy link
Copy Markdown

Summary

  • add optional CompressionStream and DecompressionStream polyfills for gzip, deflate, and deflate-raw
  • preserve host-provided constructors and initialize WHATWG Streams as the only polyfill dependency
  • use the platform/existing zlib target when available, with a pinned zlib 1.3.1 fallback

Depends on #208.

Ownership

Input BufferSource views are borrowed only during a synchronous zlib call. Output is buffered before any enqueue callback can run JavaScript, then copied once into exact-size JS-owned Uint8Arrays. Each active codec reuses one 64 KiB native scratch buffer and releases zlib/scratch storage immediately on completion or error.

Coverage

Focused tests cover the WPT compression suite, including constructor conversion, BufferSource variants and offsets, split/empty chunks, large flush output, corrupt/truncated input, trailing data, and Uint8Array output. They also exercise the input-invalidation safeguard documented by Chromium's transformer, Firefox's output-before-extra-input-error ordering, and WebKit's BufferSource validation path.

Validated with:

  • JavaScriptCore ASan/UBSan: 229 JS cases plus native tests
  • QuickJS Release: 229 JS cases plus native tests
  • JavaScriptCore TSan: 229 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.
Add optional CompressionStream and DecompressionStream polyfills for gzip, deflate, and raw deflate on top of WHATWG Streams. Reuse one native output buffer per active codec, borrow input views only synchronously, and defer JavaScript enqueue callbacks until zlib has finished consuming each input.

Cover constructor and BufferSource behavior, split and empty chunks, large flushes, corrupt/truncated/trailing input, reentrant input mutation, and repeated stream teardown with focused WPT and browser-engine regression tests. Preserve host constructors and use platform zlib where available with a pinned fallback.
Copilot AI review requested due to automatic review settings July 22, 2026 06:13

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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