1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:08:11 +00:00

Everywhere: Rename {Deprecated => Byte}String

This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
This commit is contained in:
Ali Mohammad Pur 2023-12-16 17:49:34 +03:30 committed by Ali Mohammad Pur
parent 38d62563b3
commit 5e1499d104
1615 changed files with 10257 additions and 10257 deletions

View file

@ -47,7 +47,7 @@ void JSONObject::initialize(Realm& realm)
}
// 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify
ThrowCompletionOr<Optional<DeprecatedString>> JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space)
ThrowCompletionOr<Optional<ByteString>> JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space)
{
auto& realm = *vm.current_realm();
@ -61,18 +61,18 @@ ThrowCompletionOr<Optional<DeprecatedString>> JSONObject::stringify_impl(VM& vm,
if (is_array) {
auto& replacer_object = replacer.as_object();
auto replacer_length = TRY(length_of_array_like(vm, replacer_object));
Vector<DeprecatedString> list;
Vector<ByteString> list;
for (size_t i = 0; i < replacer_length; ++i) {
auto replacer_value = TRY(replacer_object.get(i));
Optional<DeprecatedString> item;
Optional<ByteString> item;
if (replacer_value.is_string()) {
item = replacer_value.as_string().deprecated_string();
item = replacer_value.as_string().byte_string();
} else if (replacer_value.is_number()) {
item = MUST(replacer_value.to_deprecated_string(vm));
item = MUST(replacer_value.to_byte_string(vm));
} else if (replacer_value.is_object()) {
auto& value_object = replacer_value.as_object();
if (is<StringObject>(value_object) || is<NumberObject>(value_object))
item = TRY(replacer_value.to_deprecated_string(vm));
item = TRY(replacer_value.to_byte_string(vm));
}
if (item.has_value() && !list.contains_slow(*item)) {
list.append(*item);
@ -94,20 +94,20 @@ ThrowCompletionOr<Optional<DeprecatedString>> JSONObject::stringify_impl(VM& vm,
if (space.is_number()) {
auto space_mv = MUST(space.to_integer_or_infinity(vm));
space_mv = min(10, space_mv);
state.gap = space_mv < 1 ? DeprecatedString::empty() : DeprecatedString::repeated(' ', space_mv);
state.gap = space_mv < 1 ? ByteString::empty() : ByteString::repeated(' ', space_mv);
} else if (space.is_string()) {
auto string = space.as_string().deprecated_string();
auto string = space.as_string().byte_string();
if (string.length() <= 10)
state.gap = string;
else
state.gap = string.substring(0, 10);
} else {
state.gap = DeprecatedString::empty();
state.gap = ByteString::empty();
}
auto wrapper = Object::create(realm, realm.intrinsics().object_prototype());
MUST(wrapper->create_data_property_or_throw(DeprecatedString::empty(), value));
return serialize_json_property(vm, state, DeprecatedString::empty(), wrapper);
MUST(wrapper->create_data_property_or_throw(ByteString::empty(), value));
return serialize_json_property(vm, state, ByteString::empty(), wrapper);
}
// 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify
@ -128,7 +128,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify)
}
// 25.5.2.1 SerializeJSONProperty ( state, key, holder ), https://tc39.es/ecma262/#sec-serializejsonproperty
ThrowCompletionOr<Optional<DeprecatedString>> JSONObject::serialize_json_property(VM& vm, StringifyState& state, PropertyKey const& key, Object* holder)
ThrowCompletionOr<Optional<ByteString>> JSONObject::serialize_json_property(VM& vm, StringifyState& state, PropertyKey const& key, Object* holder)
{
// 1. Let value be ? Get(holder, key).
auto value = TRY(holder->get(key));
@ -188,13 +188,13 @@ ThrowCompletionOr<Optional<DeprecatedString>> JSONObject::serialize_json_propert
// 8. If Type(value) is String, return QuoteJSONString(value).
if (value.is_string())
return quote_json_string(value.as_string().deprecated_string());
return quote_json_string(value.as_string().byte_string());
// 9. If Type(value) is Number, then
if (value.is_number()) {
// a. If value is finite, return ! ToString(value).
if (value.is_finite_number())
return MUST(value.to_deprecated_string(vm));
return MUST(value.to_byte_string(vm));
// b. Return "null".
return "null"sv;
@ -218,26 +218,26 @@ ThrowCompletionOr<Optional<DeprecatedString>> JSONObject::serialize_json_propert
}
// 12. Return undefined.
return Optional<DeprecatedString> {};
return Optional<ByteString> {};
}
// 25.5.2.4 SerializeJSONObject ( state, value ), https://tc39.es/ecma262/#sec-serializejsonobject
ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_object(VM& vm, StringifyState& state, Object& object)
ThrowCompletionOr<ByteString> JSONObject::serialize_json_object(VM& vm, StringifyState& state, Object& object)
{
if (state.seen_objects.contains(&object))
return vm.throw_completion<TypeError>(ErrorType::JsonCircular);
state.seen_objects.set(&object);
DeprecatedString previous_indent = state.indent;
state.indent = DeprecatedString::formatted("{}{}", state.indent, state.gap);
Vector<DeprecatedString> property_strings;
ByteString previous_indent = state.indent;
state.indent = ByteString::formatted("{}{}", state.indent, state.gap);
Vector<ByteString> property_strings;
auto process_property = [&](PropertyKey const& key) -> ThrowCompletionOr<void> {
if (key.is_symbol())
return {};
auto serialized_property_string = TRY(serialize_json_property(vm, state, key, &object));
if (serialized_property_string.has_value()) {
property_strings.append(DeprecatedString::formatted(
property_strings.append(ByteString::formatted(
"{}:{}{}",
quote_json_string(key.to_string()),
state.gap.is_empty() ? "" : " ",
@ -253,7 +253,7 @@ ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_object(VM& vm, St
} else {
auto property_list = TRY(object.enumerable_own_property_names(PropertyKind::Key));
for (auto& property : property_list)
TRY(process_property(property.as_string().deprecated_string()));
TRY(process_property(property.as_string().byte_string()));
}
StringBuilder builder;
if (property_strings.is_empty()) {
@ -271,7 +271,7 @@ ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_object(VM& vm, St
} else {
builder.append('\n');
builder.append(state.indent);
auto separator = DeprecatedString::formatted(",\n{}", state.indent);
auto separator = ByteString::formatted(",\n{}", state.indent);
for (auto& property_string : property_strings) {
if (!first)
builder.append(separator);
@ -286,19 +286,19 @@ ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_object(VM& vm, St
state.seen_objects.remove(&object);
state.indent = previous_indent;
return builder.to_deprecated_string();
return builder.to_byte_string();
}
// 25.5.2.5 SerializeJSONArray ( state, value ), https://tc39.es/ecma262/#sec-serializejsonarray
ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_array(VM& vm, StringifyState& state, Object& object)
ThrowCompletionOr<ByteString> JSONObject::serialize_json_array(VM& vm, StringifyState& state, Object& object)
{
if (state.seen_objects.contains(&object))
return vm.throw_completion<TypeError>(ErrorType::JsonCircular);
state.seen_objects.set(&object);
DeprecatedString previous_indent = state.indent;
state.indent = DeprecatedString::formatted("{}{}", state.indent, state.gap);
Vector<DeprecatedString> property_strings;
ByteString previous_indent = state.indent;
state.indent = ByteString::formatted("{}{}", state.indent, state.gap);
Vector<ByteString> property_strings;
auto length = TRY(length_of_array_like(vm, object));
@ -331,7 +331,7 @@ ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_array(VM& vm, Str
} else {
builder.append("[\n"sv);
builder.append(state.indent);
auto separator = DeprecatedString::formatted(",\n{}", state.indent);
auto separator = ByteString::formatted(",\n{}", state.indent);
bool first = true;
for (auto& property_string : property_strings) {
if (!first)
@ -347,11 +347,11 @@ ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_array(VM& vm, Str
state.seen_objects.remove(&object);
state.indent = previous_indent;
return builder.to_deprecated_string();
return builder.to_byte_string();
}
// 25.5.2.2 QuoteJSONString ( value ), https://tc39.es/ecma262/#sec-quotejsonstring
DeprecatedString JSONObject::quote_json_string(DeprecatedString string)
ByteString JSONObject::quote_json_string(ByteString string)
{
// 1. Let product be the String value consisting solely of the code unit 0x0022 (QUOTATION MARK).
StringBuilder builder;
@ -402,7 +402,7 @@ DeprecatedString JSONObject::quote_json_string(DeprecatedString string)
builder.append('"');
// 4. Return product.
return builder.to_deprecated_string();
return builder.to_byte_string();
}
// 25.5.1 JSON.parse ( text [ , reviver ] ), https://tc39.es/ecma262/#sec-json.parse
@ -410,7 +410,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
{
auto& realm = *vm.current_realm();
auto string = TRY(vm.argument(0).to_deprecated_string(vm));
auto string = TRY(vm.argument(0).to_byte_string(vm));
auto reviver = vm.argument(1);
auto json = JsonValue::from_string(string);
@ -419,7 +419,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
Value unfiltered = parse_json_value(vm, json.value());
if (reviver.is_function()) {
auto root = Object::create(realm, realm.intrinsics().object_prototype());
auto root_name = DeprecatedString::empty();
auto root_name = ByteString::empty();
MUST(root->create_data_property_or_throw(root_name, unfiltered));
return internalize_json_property(vm, root, root_name, reviver.as_function());
}
@ -439,7 +439,7 @@ Value JSONObject::parse_json_value(VM& vm, JsonValue const& value)
if (value.is_number())
return Value(value.to_double(0));
if (value.is_string())
return PrimitiveString::create(vm, value.to_deprecated_string());
return PrimitiveString::create(vm, value.to_byte_string());
if (value.is_bool())
return Value(static_cast<bool>(value.as_bool()));
VERIFY_NOT_REACHED();
@ -490,7 +490,7 @@ ThrowCompletionOr<Value> JSONObject::internalize_json_property(VM& vm, Object* h
} else {
auto property_list = TRY(value_object.enumerable_own_property_names(Object::PropertyKind::Key));
for (auto& property_key : property_list)
TRY(process_property(property_key.as_string().deprecated_string()));
TRY(process_property(property_key.as_string().byte_string()));
}
}