feat: add TextEncoder/TextDecoder scene globals#2542
Open
kuruk-mm wants to merge 1 commit into
Open
Conversation
Co-authored-by: Esteban Ordano <esteban@decentraland.org>
Contributor
📦 Build Report🤖 Android
Build Status: ✅ Success 🍏 iOS
🔗 Workflow Run: View logs 🔄 Updated: 2026-07-15 00:13:41 UTC |
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.
Scene runtimes have no
TextEncoder/TextDecoderbecause the embedded deno_core runs without deno_web, so SDK scenes and libraries relying on the WHATWG text codecs crash at load (or fall back to slow bundled polyfills).This adds two std-only ops (
op_utf8_encode/op_utf8_decode) and a small JS shim module registered like the existing fetch/ws shims, installing WHATWG-shapedTextEncoderandTextDecoderonglobalThiswhen absent.TextDecoderaccepts the WHATWG utf-8 label set withfatalandignoreBOMsupport, throwsRangeErrorfor any other encoding and a loudTypeErrorfor the unsupported{ stream: true }option.TextEncoderimplementsencodeandencodeInto, including correct UTF-8 boundary truncation forencodeIntoon short destinations.from_utf8_lossy, whose maximal-subparts U+FFFD substitution matches the WHATWG spec exactly; encoding inherits USVString lone-surrogate replacement from deno_core's string conversion. No new dependencies.Unit tests cover the Rust decode paths (
cargo test text_encoding) and the JS shim (13node:testcases mirroringws.test.cjs). Full crate suite passes (170 tests),cargo fmtclean. The ops are purestdstring/slice operations with no OS APIs, so this ships identically on desktop and the Android/iOS builds (default features includeuse_denoon all targets).Scenes built with the current SDK keep working unchanged: the SDK installs its polyfill only when the global is absent, so the native-backed implementation wins automatically, including for already-published content.
Related: decentraland/js-sdk-toolchain#1452 (slims the SDK polyfill to a validating utf-8 codec), decentraland/bevy-explorer#958 (same exposure via deno_web).
Note for maintainers: the shim tests are runnable with
node --test lib/src/dcl/js/js_modules/text_encoding.test.cjsand are meant to joinws.test.cjsin the static-checksnode --teststep; that one-line workflow edit is left out of this PR (pushed from a token without workflow scope).Supersedes #2517 (same changes, re-committed with a signed commit).