diff --git a/sdk/lib/_internal/wasm_js_compatibility/lib/convert_patch.dart b/sdk/lib/_internal/wasm_js_compatibility/lib/convert_patch.dart index d5521bef6071..39649528c049 100644 --- a/sdk/lib/_internal/wasm_js_compatibility/lib/convert_patch.dart +++ b/sdk/lib/_internal/wasm_js_compatibility/lib/convert_patch.dart @@ -1503,12 +1503,44 @@ class _Utf8Decoder { if (decoded != null) return decoded; } - return convertGeneral(codeUnits, start, maybeEnd, true); + return _convertGeneral(codeUnits, start, maybeEnd, true); } @patch String convertChunked(List codeUnits, int start, int? maybeEnd) { - return convertGeneral(codeUnits, start, maybeEnd, false); + return _convertGeneral(codeUnits, start, maybeEnd, false); + } + + String _convertGeneral( + List codeUnits, + int start, + int? maybeEnd, + bool single, + ) { + int end = RangeError.checkValidRange(start, maybeEnd, codeUnits.length); + + if (start == end) return ""; + + // Have bytes as Uint8List. + Uint8List bytes; + int errorOffset; + if (codeUnits is Uint8List) { + bytes = codeUnits; + errorOffset = 0; + } else { + bytes = _makeUint8List(codeUnits, start, end); + errorOffset = start; + end -= start; + start = 0; + } + + String result = decodeGeneral(bytes, start, end, single); + if (isErrorState(_state)) { + String message = errorDescription(_state); + _state = initial; // Ready for more input. + throw FormatException(message, codeUnits, errorOffset + _charOrIndex); + } + return result; } } diff --git a/sdk/lib/convert/utf.dart b/sdk/lib/convert/utf.dart index 394a47c01ec1..ec87b5f60b32 100644 --- a/sdk/lib/convert/utf.dart +++ b/sdk/lib/convert/utf.dart @@ -552,38 +552,6 @@ class _Utf8Decoder { external String convertChunked(List codeUnits, int start, int? maybeEnd); - String convertGeneral( - List codeUnits, - int start, - int? maybeEnd, - bool single, - ) { - int end = RangeError.checkValidRange(start, maybeEnd, codeUnits.length); - - if (start == end) return ""; - - // Have bytes as Uint8List. - Uint8List bytes; - int errorOffset; - if (codeUnits is Uint8List) { - bytes = codeUnits; - errorOffset = 0; - } else { - bytes = _makeUint8List(codeUnits, start, end); - errorOffset = start; - end -= start; - start = 0; - } - - String result = decodeGeneral(bytes, start, end, single); - if (isErrorState(_state)) { - String message = errorDescription(_state); - _state = initial; // Ready for more input. - throw FormatException(message, codeUnits, errorOffset + _charOrIndex); - } - return result; - } - /// Flushes this decoder as if closed. /// /// This method throws if the input was partial and the decoder was