TextDecoder: support UTF-16LE and UTF-16BE - #230
Merged
bkaradzic-microsoft merged 2 commits intoAug 27, 2026
Conversation
Emscripten's UTF16ToString does `new TextDecoder('utf-16le')` at module
scope, so the constructor threw before any decoding was attempted and the
whole module failed to load. This blocks any EXPORT_ES6 Emscripten build,
which is how Babylon.js ships Gaussian Splatting SPZ and CSG2/manifold.
Adds the WHATWG utf-16le and utf-16be label sets and decodes them to
UTF-16 code units, including the leading BOM strip the spec requires.
A trailing odd byte is dropped rather than emitting U+FFFD.
Two existing tests used "utf-16" as their example of an unsupported
encoding; they now use "iso-8859-2".
Contributor
There was a problem hiding this comment.
Pull request overview
Adds UTF-16 decoding support to the native TextDecoder polyfill so Emscripten-generated code (which constructs new TextDecoder('utf-16le') at module scope) no longer fails during module initialization.
Changes:
- Extend
TextDecoderto recognize WHATWG UTF-16LE/UTF-16BE label sets (including aliases) in addition to UTF-8. - Implement UTF-16LE/BE byte-to-code-unit decoding with required leading BOM stripping.
- Update unit tests to use a truly-unsupported encoding label and add coverage for UTF-16LE/BE, aliases, BOM stripping, surrogate pairs, and embedded NULs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Tests/UnitTests/Scripts/tests.ts | Adjusts unsupported-encoding tests and adds new UTF-16 decoding test coverage. |
| Polyfills/TextDecoder/Source/TextDecoder.cpp | Adds UTF-16 label handling and implements UTF-16LE/BE decode path with BOM stripping. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
CedricGuillemet
approved these changes
Aug 27, 2026
bkaradzic-microsoft
added a commit
to BabylonJS/BabylonNative
that referenced
this pull request
Aug 27, 2026
## Summary Update JsRuntimeHost from [`cb988baa`](BabylonJS/JsRuntimeHost@cb988ba) to [`0d263627`](BabylonJS/JsRuntimeHost@0d26362), picking up three fixes merged since the current pin: - [BabylonJS/JsRuntimeHost#220](BabylonJS/JsRuntimeHost#220) — prevent zero-delay `setInterval` from flooding and starving the JS dispatch queue. In BN this could indefinitely delay async shader-compilation continuations and hang scene readiness. - [BabylonJS/JsRuntimeHost#230](BabylonJS/JsRuntimeHost#230) — support UTF-16LE/UTF-16BE in `TextDecoder`, needed by Emscripten `EXPORT_ES6` modules such as SPZ and CSG2/manifold. - [BabylonJS/JsRuntimeHost#231](BabylonJS/JsRuntimeHost#231) — preserve embedded NUL bytes in XHR string responses, needed for Emscripten modules with inline WASM payloads. ## Validation - Configured Win32 x64 against the updated dependency and confirmed FetchContent resolved the exact pinned SHA. - Built the Debug Playground target successfully. - Ran the `Nested BBG` validation test, which exercises the timer-starvation regression path: **1/1 passed, exit 0**. - The three upstream changes include their own focused JsRuntimeHost unit coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d47cbab2-d751-4cf9-984f-4412dd9ec601
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.
Emscripten's
UTF16ToStringdoesnew TextDecoder('utf-16le')at module scope, so the constructor threw before any decoding was attempted and the whole module failed to load. That blocks anyEXPORT_ES6Emscripten build — which is how Babylon.js ships Gaussian Splatting SPZ and CSG2/manifold.Adds the WHATWG
utf-16leandutf-16belabel sets and decodes them to UTF-16 code units, including the leading BOM strip the spec requires. A trailing odd byte is dropped rather than emitting U+FFFD; every producer we care about hands over whole code units.Two existing tests used
"utf-16"as their example of an unsupported encoding and now use"iso-8859-2".New tests cover both endiannesses, the alias sets, BOM stripping, a non-BMP surrogate pair and embedded NUL code units.