mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:57:45 +00:00
LibTextCodec+Everywhere: Port Decoders to new Strings
This commit is contained in:
parent
3c5090e172
commit
2db168acc1
21 changed files with 149 additions and 123 deletions
|
@ -515,7 +515,7 @@ void HTMLScriptElement::resource_did_load()
|
|||
// we have to re-encode it to UTF-8.
|
||||
if (resource()->has_encoding()) {
|
||||
if (auto codec = TextCodec::decoder_for(resource()->encoding().value()); codec.has_value()) {
|
||||
data = codec->to_utf8(data).to_byte_buffer();
|
||||
data = codec->to_utf8(data).release_value_but_fixme_should_propagate_errors().to_deprecated_string().to_byte_buffer();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2800,7 +2800,7 @@ HTMLTokenizer::HTMLTokenizer(StringView input, DeprecatedString const& encoding)
|
|||
{
|
||||
auto decoder = TextCodec::decoder_for(encoding);
|
||||
VERIFY(decoder.has_value());
|
||||
m_decoded_input = decoder->to_utf8(input);
|
||||
m_decoded_input = decoder->to_utf8(input).release_value_but_fixme_should_propagate_errors().to_deprecated_string();
|
||||
m_utf8_view = Utf8View(m_decoded_input);
|
||||
m_utf8_iterator = m_utf8_view.begin();
|
||||
m_prev_utf8_iterator = m_utf8_view.begin();
|
||||
|
|
|
@ -1421,9 +1421,9 @@ JS_DEFINE_NATIVE_FUNCTION(Window::atob)
|
|||
// NOTE: Any 8-bit encoding -> utf-8 decoder will work for this
|
||||
auto text_decoder = TextCodec::decoder_for("windows-1252"sv);
|
||||
VERIFY(text_decoder.has_value());
|
||||
auto text = text_decoder->to_utf8(decoded.release_value());
|
||||
auto text = TRY_OR_THROW_OOM(vm, text_decoder->to_utf8(decoded.release_value()));
|
||||
|
||||
return JS::PrimitiveString::create(vm, DeprecatedString(text));
|
||||
return JS::PrimitiveString::create(vm, text);
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::btoa)
|
||||
|
|
|
@ -163,7 +163,7 @@ WebIDL::ExceptionOr<DeprecatedString> WorkerGlobalScope::atob(DeprecatedString c
|
|||
// decode_base64() returns a byte string. LibJS uses UTF-8 for strings. Use Latin1Decoder to convert bytes 128-255 to UTF-8.
|
||||
auto decoder = TextCodec::decoder_for("windows-1252"sv);
|
||||
VERIFY(decoder.has_value());
|
||||
return decoder->to_utf8(decoded_data.value());
|
||||
return TRY_OR_THROW_OOM(vm(), decoder->to_utf8(decoded_data.value()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue