summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2022-12-19 00:23:47 +0100
committerAndreas Kling <kling@serenityos.org>2022-12-20 10:34:19 +0100
commit25f2e4981c1236f69776c290fba7472ec7714869 (patch)
treebf46d80f5e93fe9590dc990082751c7b320fc9dd /Userland/Libraries/LibWeb/HTML
parent99c1b634fc80c922ca4867e4eac83b73e4c28304 (diff)
downloadserenity-25f2e4981c1236f69776c290fba7472ec7714869.zip
AK: Stop using `DeprecatedString` in Base64 encoding
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp7
-rw-r--r--Userland/Libraries/LibWeb/HTML/Window.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp2
3 files changed, 9 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp
index faad688c1c..3c4eb53e67 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp
@@ -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()
diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index 5b4147b3d4..52f1707947 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -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
diff --git a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
index bad102430e..09bf7004c3 100644
--- a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
@@ -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