1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:07:45 +00:00

AK: Stop using DeprecatedString in Base64 encoding

This commit is contained in:
Jelle Raaijmakers 2022-12-19 00:23:47 +01:00 committed by Andreas Kling
parent 99c1b634fc
commit 25f2e4981c
14 changed files with 47 additions and 27 deletions

View file

@ -181,7 +181,12 @@ DeprecatedString HTMLCanvasElement::to_data_url(DeprecatedString const& type, [[
dbgln("Gfx::PNGWriter failed to encode the HTMLCanvasElement: {}", encoded_bitmap_or_error.error());
return {};
}
return AK::URL::create_with_data(type, encode_base64(encoded_bitmap_or_error.value()), true).to_deprecated_string();
auto base64_encoded_or_error = encode_base64(encoded_bitmap_or_error.value());
if (base64_encoded_or_error.is_error()) {
// FIXME: propagate error
return {};
}
return AK::URL::create_with_data(type, base64_encoded_or_error.release_value().to_deprecated_string(), true).to_deprecated_string();
}
void HTMLCanvasElement::present()

View file

@ -1423,8 +1423,8 @@ JS_DEFINE_NATIVE_FUNCTION(Window::btoa)
byte_string.append(code_point);
}
auto encoded = encode_base64(byte_string.span());
return JS::PrimitiveString::create(vm, move(encoded));
auto encoded = MUST(encode_base64(byte_string.span()));
return JS::PrimitiveString::create(vm, encoded.to_deprecated_string());
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus

View file

@ -137,7 +137,7 @@ WebIDL::ExceptionOr<DeprecatedString> WorkerGlobalScope::btoa(DeprecatedString c
// Otherwise, the user agent must convert data to a byte sequence whose nth byte is the eight-bit representation of the nth code point of data,
// and then must apply forgiving-base64 encode to that byte sequence and return the result.
return encode_base64(byte_string.span());
return TRY_OR_RETURN_OOM(realm(), encode_base64(byte_string.span())).to_deprecated_string();
}
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob