1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 00:07:35 +00:00

AK+Everywhere: Rename String to DeprecatedString

We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
This commit is contained in:
Linus Groh 2022-12-04 18:02:33 +00:00 committed by Andreas Kling
parent f74251606d
commit 6e19ab2bbc
2006 changed files with 11635 additions and 11636 deletions

View file

@ -71,7 +71,7 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
return JS::Value(true);
// Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true.
if (auto supports = parse_css_supports({}, String::formatted("({})", supports_text)); supports && supports->matches())
if (auto supports = parse_css_supports({}, DeprecatedString::formatted("({})", supports_text)); supports && supports->matches())
return JS::Value(true);
// Otherwise, return false.

View file

@ -50,7 +50,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (vm.argument_count() < 1)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "fetch");
auto arg0 = vm.argument(0);
auto arg0_to_variant = [&vm, &realm](JS::Value arg0) -> JS::ThrowCompletionOr<Variant<JS::Handle<Request>, String>> {
auto arg0_to_variant = [&vm, &realm](JS::Value arg0) -> JS::ThrowCompletionOr<Variant<JS::Handle<Request>, DeprecatedString>> {
// These might be unused.
(void)vm;
(void)realm;
@ -63,7 +63,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
}
return TRY(arg0.to_string(vm));
};
Variant<JS::Handle<Request>, String> input = TRY(arg0_to_variant(arg0));
Variant<JS::Handle<Request>, DeprecatedString> input = TRY(arg0_to_variant(arg0));
auto arg1 = vm.argument(1);
if (!arg1.is_nullish() && !arg1.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "RequestInit");
@ -72,7 +72,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (arg1.is_object())
body_property_value = TRY(arg1.as_object().get("body"));
if (!body_property_value.is_undefined()) {
auto body_property_value_to_variant = [&vm, &realm](JS::Value body_property_value) -> JS::ThrowCompletionOr<Variant<JS::Handle<ReadableStream>, JS::Handle<Blob>, JS::Handle<JS::Object>, JS::Handle<URLSearchParams>, String>> {
auto body_property_value_to_variant = [&vm, &realm](JS::Value body_property_value) -> JS::ThrowCompletionOr<Variant<JS::Handle<ReadableStream>, JS::Handle<Blob>, JS::Handle<JS::Object>, JS::Handle<URLSearchParams>, DeprecatedString>> {
// These might be unused.
(void)vm;
(void)realm;
@ -91,7 +91,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
}
return TRY(body_property_value.to_string(vm));
};
Optional<Variant<JS::Handle<ReadableStream>, JS::Handle<Blob>, JS::Handle<JS::Object>, JS::Handle<URLSearchParams>, String>> body_value;
Optional<Variant<JS::Handle<ReadableStream>, JS::Handle<Blob>, JS::Handle<JS::Object>, JS::Handle<URLSearchParams>, DeprecatedString>> body_value;
if (!body_property_value.is_nullish())
body_value = TRY(body_property_value_to_variant(body_property_value));
init.body = body_value;
@ -156,7 +156,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (arg1.is_object())
headers_property_value = TRY(arg1.as_object().get("headers"));
if (!headers_property_value.is_undefined()) {
auto headers_property_value_to_variant = [&vm, &realm](JS::Value headers_property_value) -> JS::ThrowCompletionOr<Variant<Vector<Vector<String>>, OrderedHashMap<String, String>>> {
auto headers_property_value_to_variant = [&vm, &realm](JS::Value headers_property_value) -> JS::ThrowCompletionOr<Variant<Vector<Vector<DeprecatedString>>, OrderedHashMap<DeprecatedString, DeprecatedString>>> {
// These might be unused.
(void)vm;
(void)realm;
@ -165,7 +165,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
auto* method = TRY(headers_property_value.get_method(vm, *vm.well_known_symbol_iterator()));
if (method) {
auto iterator1 = TRY(JS::get_iterator(vm, headers_property_value, JS::IteratorHint::Sync, method));
Vector<Vector<String>> headers_value;
Vector<Vector<DeprecatedString>> headers_value;
for (;;) {
auto* next1 = TRY(JS::iterator_step(vm, iterator1));
if (!next1)
@ -177,15 +177,15 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (!iterator_method1)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, next_item1.to_string_without_side_effects());
auto iterator2 = TRY(JS::get_iterator(vm, next_item1, JS::IteratorHint::Sync, iterator_method1));
Vector<String> sequence_item1;
Vector<DeprecatedString> sequence_item1;
for (;;) {
auto* next2 = TRY(JS::iterator_step(vm, iterator2));
if (!next2)
break;
auto next_item2 = TRY(JS::iterator_value(vm, *next2));
String sequence_item2;
DeprecatedString sequence_item2;
if (next_item2.is_null() && false) {
sequence_item2 = String::empty();
sequence_item2 = DeprecatedString::empty();
} else {
sequence_item2 = TRY(next_item2.to_string(vm));
}
@ -195,23 +195,23 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
}
return headers_value;
}
OrderedHashMap<String, String> record_union_type;
OrderedHashMap<DeprecatedString, DeprecatedString> record_union_type;
auto record_keys1 = TRY(headers_property_value_object.internal_own_property_keys());
for (auto& key1 : record_keys1) {
auto property_key1 = MUST(JS::PropertyKey::from_value(vm, key1));
auto descriptor1 = TRY(headers_property_value_object.internal_get_own_property(property_key1));
if (!descriptor1.has_value() || !descriptor1->enumerable.has_value() || !descriptor1->enumerable.value())
continue;
String typed_key1;
DeprecatedString typed_key1;
if (key1.is_null() && false) {
typed_key1 = String::empty();
typed_key1 = DeprecatedString::empty();
} else {
typed_key1 = TRY(key1.to_string(vm));
}
auto value1 = TRY(headers_property_value_object.get(property_key1));
String typed_value1;
DeprecatedString typed_value1;
if (value1.is_null() && false) {
typed_value1 = String::empty();
typed_value1 = DeprecatedString::empty();
} else {
typed_value1 = TRY(value1.to_string(vm));
}
@ -221,7 +221,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
}
return vm.throw_completion<JS::TypeError>("No union types matched");
};
Optional<Variant<Vector<Vector<String>>, OrderedHashMap<String, String>>> headers_value;
Optional<Variant<Vector<Vector<DeprecatedString>>, OrderedHashMap<DeprecatedString, DeprecatedString>>> headers_value;
if (!headers_property_value.is_nullish())
headers_value = TRY(headers_property_value_to_variant(headers_property_value));
init.headers = headers_value;
@ -230,10 +230,10 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (arg1.is_object())
integrity_property_value = TRY(arg1.as_object().get("integrity"));
if (!integrity_property_value.is_undefined()) {
String integrity_value;
DeprecatedString integrity_value;
if (!integrity_property_value.is_undefined()) {
if (integrity_property_value.is_null() && false)
integrity_value = String::empty();
integrity_value = DeprecatedString::empty();
else
integrity_value = TRY(integrity_property_value.to_string(vm));
}
@ -252,10 +252,10 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (arg1.is_object())
method_property_value = TRY(arg1.as_object().get("method"));
if (!method_property_value.is_undefined()) {
String method_value;
DeprecatedString method_value;
if (!method_property_value.is_undefined()) {
if (method_property_value.is_null() && false)
method_value = String::empty();
method_value = DeprecatedString::empty();
else
method_value = TRY(method_property_value.to_string(vm));
}
@ -303,10 +303,10 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (arg1.is_object())
referrer_property_value = TRY(arg1.as_object().get("referrer"));
if (!referrer_property_value.is_undefined()) {
String referrer_value;
DeprecatedString referrer_value;
if (!referrer_property_value.is_undefined()) {
if (referrer_property_value.is_null() && false)
referrer_value = String::empty();
referrer_value = DeprecatedString::empty();
else
referrer_value = TRY(referrer_property_value.to_string(vm));
}

View file

@ -47,13 +47,13 @@ JS::ThrowCompletionOr<JS::Object*> ImageConstructor::construct(FunctionObject&)
// 3. If width is given, then set an attribute value for img using "width" and width.
if (vm.argument_count() > 0) {
u32 width = TRY(vm.argument(0).to_u32(vm));
MUST(image_element->set_attribute(HTML::AttributeNames::width, String::formatted("{}", width)));
MUST(image_element->set_attribute(HTML::AttributeNames::width, DeprecatedString::formatted("{}", width)));
}
// 4. If height is given, then set an attribute value for img using "height" and height.
if (vm.argument_count() > 1) {
u32 height = TRY(vm.argument(1).to_u32(vm));
MUST(image_element->set_attribute(HTML::AttributeNames::height, String::formatted("{}", height)));
MUST(image_element->set_attribute(HTML::AttributeNames::height, DeprecatedString::formatted("{}", height)));
}
// 5. Return img.

View file

@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/HashMap.h>
#include <AK/String.h>
#include <LibJS/Forward.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/Object.h>
@ -13,7 +13,7 @@
namespace Web::Bindings {
JS::Object& Intrinsics::cached_web_prototype(String const& class_name)
JS::Object& Intrinsics::cached_web_prototype(DeprecatedString const& class_name)
{
auto it = m_prototypes.find(class_name);
if (it == m_prototypes.end()) {

View file

@ -25,10 +25,10 @@ public:
{
}
JS::Object& cached_web_prototype(String const& class_name);
JS::Object& cached_web_prototype(DeprecatedString const& class_name);
template<typename T>
JS::Object& ensure_web_prototype(String const& class_name)
JS::Object& ensure_web_prototype(DeprecatedString const& class_name)
{
auto it = m_prototypes.find(class_name);
if (it != m_prototypes.end())
@ -40,7 +40,7 @@ public:
}
template<typename T>
JS::NativeFunction& ensure_web_constructor(String const& class_name)
JS::NativeFunction& ensure_web_constructor(DeprecatedString const& class_name)
{
auto it = m_constructors.find(class_name);
if (it != m_constructors.end())
@ -54,8 +54,8 @@ public:
private:
virtual void visit_edges(JS::Cell::Visitor&) override;
HashMap<String, JS::Object*> m_prototypes;
HashMap<String, JS::NativeFunction*> m_constructors;
HashMap<DeprecatedString, JS::Object*> m_prototypes;
HashMap<DeprecatedString, JS::NativeFunction*> m_constructors;
JS::NonnullGCPtr<JS::Realm> m_realm;
};
@ -66,18 +66,18 @@ private:
}
template<typename T>
[[nodiscard]] JS::Object& ensure_web_prototype(JS::Realm& realm, String const& class_name)
[[nodiscard]] JS::Object& ensure_web_prototype(JS::Realm& realm, DeprecatedString const& class_name)
{
return host_defined_intrinsics(realm).ensure_web_prototype<T>(class_name);
}
template<typename T>
[[nodiscard]] JS::NativeFunction& ensure_web_constructor(JS::Realm& realm, String const& class_name)
[[nodiscard]] JS::NativeFunction& ensure_web_constructor(JS::Realm& realm, DeprecatedString const& class_name)
{
return host_defined_intrinsics(realm).ensure_web_constructor<T>(class_name);
}
[[nodiscard]] inline JS::Object& cached_web_prototype(JS::Realm& realm, String const& class_name)
[[nodiscard]] inline JS::Object& cached_web_prototype(JS::Realm& realm, DeprecatedString const& class_name)
{
return host_defined_intrinsics(realm).cached_web_prototype(class_name);
}

View file

@ -30,7 +30,7 @@ JS::ThrowCompletionOr<bool> LegacyPlatformObject::is_named_property_exposed_on_o
// 1. If P is not a supported property name of O, then return false.
// NOTE: This is in it's own variable to enforce the type.
// FIXME: Can this throw?
Vector<String> supported_property_names = this->supported_property_names();
Vector<DeprecatedString> supported_property_names = this->supported_property_names();
auto property_key_string = property_key.to_string();
if (!supported_property_names.contains_slow(property_key_string))
return false;
@ -195,7 +195,7 @@ JS::ThrowCompletionOr<bool> LegacyPlatformObject::internal_define_own_property(J
// 1. Let creating be true if P is not a supported property name, and false otherwise.
// NOTE: This is in it's own variable to enforce the type.
// FIXME: Can this throw?
Vector<String> supported_property_names = this->supported_property_names();
Vector<DeprecatedString> supported_property_names = this->supported_property_names();
[[maybe_unused]] bool creating = !supported_property_names.contains_slow(property_name_as_string);
// NOTE: This has to be done manually instead of using Object::has_own_property, as that would use the overridden internal_get_own_property.
@ -269,7 +269,7 @@ JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> LegacyPlatformObject::interna
for (u64 index = 0; index <= NumericLimits<u32>::max(); ++index) {
if (is_supported_property_index(index))
keys.append(js_string(vm, String::number(index)));
keys.append(js_string(vm, DeprecatedString::number(index)));
else
break;
}
@ -307,7 +307,7 @@ JS::Value LegacyPlatformObject::named_item_value(FlyString const&) const
return JS::js_undefined();
}
Vector<String> LegacyPlatformObject::supported_property_names() const
Vector<DeprecatedString> LegacyPlatformObject::supported_property_names() const
{
return {};
}

View file

@ -30,7 +30,7 @@ public:
virtual JS::Value item_value(size_t index) const;
virtual JS::Value named_item_value(FlyString const& name) const;
virtual Vector<String> supported_property_names() const;
virtual Vector<DeprecatedString> supported_property_names() const;
virtual bool is_supported_property_index(u32) const;
protected:

View file

@ -111,7 +111,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter)
auto new_href = TRY(vm.argument(0).to_string(vm));
auto href_url = window.associated_document().parse_url(new_href);
if (!href_url.is_valid())
return vm.throw_completion<JS::URIError>(String::formatted("Invalid URL '{}'", new_href));
return vm.throw_completion<JS::URIError>(DeprecatedString::formatted("Invalid URL '{}'", new_href));
// 3. Location-object navigate given the resulting URL record.
window.did_set_location_href({}, href_url);
@ -139,7 +139,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::hostname_getter)
// 2. If this's url's host is null, return the empty string.
if (location_object->url().host().is_null())
return JS::js_string(vm, String::empty());
return JS::js_string(vm, DeprecatedString::empty());
// 3. Return this's url's host, serialized.
return JS::js_string(vm, location_object->url().host());
@ -157,14 +157,14 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::host_getter)
// 3. If url's host is null, return the empty string.
if (url.host().is_null())
return JS::js_string(vm, String::empty());
return JS::js_string(vm, DeprecatedString::empty());
// 4. If url's port is null, return url's host, serialized.
if (!url.port().has_value())
return JS::js_string(vm, url.host());
// 5. Return url's host, serialized, followed by ":" and url's port, serialized.
return JS::js_string(vm, String::formatted("{}:{}", url.host(), *url.port()));
return JS::js_string(vm, DeprecatedString::formatted("{}:{}", url.host(), *url.port()));
}
// https://html.spec.whatwg.org/multipage/history.html#dom-location-hash
@ -176,10 +176,10 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::hash_getter)
// 2. If this's url's fragment is either null or the empty string, return the empty string.
if (location_object->url().fragment().is_empty())
return JS::js_string(vm, String::empty());
return JS::js_string(vm, DeprecatedString::empty());
// 3. Return "#", followed by this's url's fragment.
return JS::js_string(vm, String::formatted("#{}", location_object->url().fragment()));
return JS::js_string(vm, DeprecatedString::formatted("#{}", location_object->url().fragment()));
}
// https://html.spec.whatwg.org/multipage/history.html#dom-location-search
@ -191,10 +191,10 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::search_getter)
// 2. If this's url's query is either null or the empty string, return the empty string.
if (location_object->url().query().is_empty())
return JS::js_string(vm, String::empty());
return JS::js_string(vm, DeprecatedString::empty());
// 3. Return "?", followed by this's url's query.
return JS::js_string(vm, String::formatted("?{}", location_object->url().query()));
return JS::js_string(vm, DeprecatedString::formatted("?{}", location_object->url().query()));
}
// https://html.spec.whatwg.org/multipage/history.html#dom-location-protocol
@ -205,7 +205,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::protocol_getter)
// FIXME: 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
// 2. Return this's url's scheme, followed by ":".
return JS::js_string(vm, String::formatted("{}:", location_object->url().scheme()));
return JS::js_string(vm, DeprecatedString::formatted("{}:", location_object->url().scheme()));
}
// https://html.spec.whatwg.org/multipage/history.html#dom-location-port
@ -217,10 +217,10 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::port_getter)
// 2. If this's url's port is null, return the empty string.
if (!location_object->url().port().has_value())
return JS::js_string(vm, String::empty());
return JS::js_string(vm, DeprecatedString::empty());
// 3. Return this's url's port, serialized.
return JS::js_string(vm, String::number(*location_object->url().port()));
return JS::js_string(vm, DeprecatedString::number(*location_object->url().port()));
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-origin
@ -327,7 +327,7 @@ JS::ThrowCompletionOr<bool> LocationObject::internal_define_own_property(JS::Pro
}
// 2. Throw a "SecurityError" DOMException.
return throw_completion(WebIDL::SecurityError::create(realm(), String::formatted("Can't define property '{}' on cross-origin object", property_key)));
return throw_completion(WebIDL::SecurityError::create(realm(), DeprecatedString::formatted("Can't define property '{}' on cross-origin object", property_key)));
}
// 7.10.5.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-get
@ -364,7 +364,7 @@ JS::ThrowCompletionOr<bool> LocationObject::internal_delete(JS::PropertyKey cons
return JS::Object::internal_delete(property_key);
// 2. Throw a "SecurityError" DOMException.
return throw_completion(WebIDL::SecurityError::create(realm(), String::formatted("Can't delete property '{}' on cross-origin object", property_key)));
return throw_completion(WebIDL::SecurityError::create(realm(), DeprecatedString::formatted("Can't delete property '{}' on cross-origin object", property_key)));
}
// 7.10.5.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-ownpropertykeys

View file

@ -318,7 +318,7 @@ JS::VM& main_thread_vm()
// FIXME: Implement 8.1.5.5.3 HostResolveImportedModule(referencingScriptOrModule, moduleRequest), https://html.spec.whatwg.org/multipage/webappapis.html#hostresolveimportedmodule(referencingscriptormodule,-modulerequest)
// 8.1.5.5.4 HostGetSupportedImportAssertions(), https://html.spec.whatwg.org/multipage/webappapis.html#hostgetsupportedimportassertions
vm->host_get_supported_import_assertions = []() -> Vector<String> {
vm->host_get_supported_import_assertions = []() -> Vector<DeprecatedString> {
// 1. Return « "type" ».
return { "type"sv };
};

View file

@ -13,13 +13,13 @@
namespace Web::Bindings {
#define WEB_PLATFORM_OBJECT(class_, base_class) \
JS_OBJECT(class_, base_class) \
virtual bool implements_interface(String const& interface) const override \
{ \
if (interface == #class_) \
return true; \
return Base::implements_interface(interface); \
#define WEB_PLATFORM_OBJECT(class_, base_class) \
JS_OBJECT(class_, base_class) \
virtual bool implements_interface(DeprecatedString const& interface) const override \
{ \
if (interface == #class_) \
return true; \
return Base::implements_interface(interface); \
}
// https://webidl.spec.whatwg.org/#dfn-platform-object
@ -38,7 +38,7 @@ public:
// https://webidl.spec.whatwg.org/#implements
// This is implemented by overrides that get generated by the WEB_PLATFORM_OBJECT macro.
[[nodiscard]] virtual bool implements_interface(String const&) const { return false; }
[[nodiscard]] virtual bool implements_interface(DeprecatedString const&) const { return false; }
protected:
explicit PlatformObject(JS::Realm&);