LibWeb: Port WorkerGlobalScope to new String

This commit is contained in:
Kenneth Myhra 2023-02-23 10:16:20 +01:00 committed by Sam Atkins
parent 9c5bdb0b86
commit be727ea871
Notes: sideshowbarker 2024-07-17 05:13:53 +09:00
3 changed files with 12 additions and 12 deletions

View file

@ -49,7 +49,7 @@ void WorkerGlobalScope::visit_edges(Cell::Visitor& visitor)
}
// https://html.spec.whatwg.org/multipage/workers.html#importing-scripts-and-libraries
WebIDL::ExceptionOr<void> WorkerGlobalScope::import_scripts(Vector<DeprecatedString> urls)
WebIDL::ExceptionOr<void> WorkerGlobalScope::import_scripts(Vector<String> urls)
{
// The algorithm may optionally be customized by supplying custom perform the fetch hooks,
// which if provided will be used when invoking fetch a classic worker-imported script.
@ -104,7 +104,7 @@ ENUMERATE_WORKER_GLOBAL_SCOPE_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-origin
DeprecatedString WorkerGlobalScope::origin() const
String WorkerGlobalScope::origin() const
{
// FIXME: The origin getter steps are to return this's relevant settings object's origin, serialized.
return {};
@ -127,14 +127,14 @@ bool WorkerGlobalScope::cross_origin_isolated() const
}
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-btoa
WebIDL::ExceptionOr<DeprecatedString> WorkerGlobalScope::btoa(DeprecatedString const& data) const
WebIDL::ExceptionOr<String> WorkerGlobalScope::btoa(String const& data) const
{
// FIXME: This is the same as the implementation in Bindings/WindowObject.cpp
// Find a way to share this implementation, since they come from the same mixin.
// The btoa(data) method must throw an "InvalidCharacterError" DOMException if data contains any character whose code point is greater than U+00FF.
Vector<u8> byte_string;
byte_string.ensure_capacity(data.length());
byte_string.ensure_capacity(data.bytes().size());
for (u32 code_point : Utf8View(data)) {
if (code_point > 0xff)
return WebIDL::InvalidCharacterError::create(realm(), "Data contains characters outside the range U+0000 and U+00FF");
@ -143,17 +143,17 @@ 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 TRY_OR_THROW_OOM(vm(), encode_base64(byte_string.span())).to_deprecated_string();
return TRY_OR_THROW_OOM(vm(), encode_base64(byte_string.span()));
}
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob
WebIDL::ExceptionOr<DeprecatedString> WorkerGlobalScope::atob(DeprecatedString const& data) const
WebIDL::ExceptionOr<String> WorkerGlobalScope::atob(String const& data) const
{
// FIXME: This is the same as the implementation in Bindings/WindowObject.cpp
// Find a way to share this implementation, since they come from the same mixin.
// 1. Let decodedData be the result of running forgiving-base64 decode on data.
auto decoded_data = decode_base64(data.view());
auto decoded_data = decode_base64(data.bytes_as_string_view());
// 2. If decodedData is failure, then throw an "InvalidCharacterError" DOMException.
if (decoded_data.is_error())

View file

@ -42,7 +42,7 @@ public:
JS::NonnullGCPtr<WorkerLocation> location() const;
JS::NonnullGCPtr<WorkerNavigator> navigator() const;
WebIDL::ExceptionOr<void> import_scripts(Vector<DeprecatedString> urls);
WebIDL::ExceptionOr<void> import_scripts(Vector<String> urls);
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
@ -54,11 +54,11 @@ public:
// Following methods are from the WindowOrWorkerGlobalScope mixin
// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope-mixin
DeprecatedString origin() const;
String origin() const;
bool is_secure_context() const;
bool cross_origin_isolated() const;
WebIDL::ExceptionOr<DeprecatedString> btoa(DeprecatedString const& data) const;
WebIDL::ExceptionOr<DeprecatedString> atob(DeprecatedString const& data) const;
WebIDL::ExceptionOr<String> btoa(String const& data) const;
WebIDL::ExceptionOr<String> atob(String const& data) const;
// Non-IDL public methods

View file

@ -5,7 +5,7 @@
#import <HTML/WorkerNavigator.idl>
// https://html.spec.whatwg.org/multipage/workers.html#workerglobalscope
[Exposed=Worker]
[Exposed=Worker, UseNewAKString]
interface WorkerGlobalScope : EventTarget {
readonly attribute WorkerGlobalScope self;
readonly attribute WorkerLocation location;