LibWeb: Handle TextDecoder's fatal flag

This commit is contained in:
Simon Wanner 2024-05-27 16:58:36 +02:00 committed by Andreas Kling
parent f8ac883fb4
commit 3029406c4b
Notes: sideshowbarker 2024-07-17 18:08:55 +09:00

View File

@ -56,7 +56,10 @@ WebIDL::ExceptionOr<String> TextDecoder::decode(Optional<JS::Handle<WebIDL::Buff
if (data_buffer_or_error.is_error())
return WebIDL::OperationError::create(realm(), "Failed to copy bytes from ArrayBuffer"_fly_string);
auto& data_buffer = data_buffer_or_error.value();
return TRY_OR_THROW_OOM(vm(), m_decoder.to_utf8({ data_buffer.data(), data_buffer.size() }));
auto result = TRY_OR_THROW_OOM(vm(), m_decoder.to_utf8({ data_buffer.data(), data_buffer.size() }));
if (this->fatal() && result.contains(0xfffd))
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Decoding failed"sv };
return result;
}
}