diff options
author | Linus Groh <mail@linusgroh.de> | 2023-03-06 11:19:16 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-07 23:33:34 +0000 |
commit | 6dd1934ed87e937f8c36611e618dba6eddc27d97 (patch) | |
tree | b0ab77595f3d7e54f63ce60391577af1be70351a /Userland/Libraries | |
parent | 192f5e61f65b5e1cd8e217c97e14cf84fdf58c4e (diff) | |
download | serenity-6dd1934ed87e937f8c36611e618dba6eddc27d97.zip |
LibWeb/HTML: Port Window.atob() to IDL
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Window.cpp | 30 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Window.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Window.idl | 1 |
3 files changed, 2 insertions, 31 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index db5ef88654..3e62021000 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1063,7 +1063,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm define_native_function(realm, "clearTimeout", clear_timeout, 1, attr); define_native_function(realm, "requestAnimationFrame", request_animation_frame, 1, attr); define_native_function(realm, "cancelAnimationFrame", cancel_animation_frame, 1, attr); - define_native_function(realm, "atob", atob, 1, attr); define_native_function(realm, "focus", focus, 0, attr); define_native_function(realm, "queueMicrotask", queue_microtask, 1, attr); @@ -1472,35 +1471,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::cancel_idle_callback) return JS::js_undefined(); } -// https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob-dev -JS_DEFINE_NATIVE_FUNCTION(Window::atob) -{ - if (!vm.argument_count()) - return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "atob"); - auto deprecated_string = TRY(vm.argument(0).to_deprecated_string(vm)); - auto string = String::from_utf8(deprecated_string).release_value_but_fixme_should_propagate_errors(); - - // must throw an "InvalidCharacterError" DOMException if data contains any character whose code point is greater than U+00FF - for (auto code_point : string.code_points()) { - if (code_point > 0x00FF) - return throw_completion(WebIDL::InvalidCharacterError::create(*vm.current_realm(), "Data contains characters outside the range U+0000 and U+00FF")); - } - - // 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. - auto decoded = Infra::decode_forgiving_base64(StringView(deprecated_string)); - if (decoded.is_error()) - return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidFormat, "Base64"); - - // The bytes object might contain bytes greater than 128, encode them in UTF8 - // 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 = TRY_OR_THROW_OOM(vm, text_decoder->to_utf8(decoded.release_value())); - - return JS::PrimitiveString::create(vm, text); -} - // https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus JS_DEFINE_NATIVE_FUNCTION(Window::focus) { diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 2bb6dfc368..4cbd88ac51 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -46,6 +46,7 @@ public: ~Window(); + using WindowOrWorkerGlobalScopeMixin::atob; using WindowOrWorkerGlobalScopeMixin::btoa; // ^DOM::EventTarget @@ -266,7 +267,6 @@ private: JS_DECLARE_NATIVE_FUNCTION(clear_timeout); JS_DECLARE_NATIVE_FUNCTION(request_animation_frame); JS_DECLARE_NATIVE_FUNCTION(cancel_animation_frame); - JS_DECLARE_NATIVE_FUNCTION(atob); JS_DECLARE_NATIVE_FUNCTION(focus); JS_DECLARE_NATIVE_FUNCTION(get_computed_style); diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index 029f3f7ff3..1ca2aa2c52 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -40,6 +40,7 @@ interface Window : EventTarget { [Replaceable] readonly attribute USVString origin; readonly attribute boolean isSecureContext; DOMString btoa(DOMString data); + ByteString atob(DOMString data); }; Window includes GlobalEventHandlers; Window includes WindowEventHandlers; |