mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:47:45 +00:00
AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all its users with one of the following: - A normal, empty DeprecatedString - Optional<DeprecatedString> Note that null states of DeprecatedFlyString/StringView/etc are *not* affected by this commit. However, DeprecatedString::empty() is now considered equal to a null StringView.
This commit is contained in:
parent
daf6d8173c
commit
aeee98b3a1
189 changed files with 597 additions and 652 deletions
|
@ -45,7 +45,7 @@ void JSONObject::initialize(Realm& realm)
|
|||
}
|
||||
|
||||
// 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify
|
||||
ThrowCompletionOr<DeprecatedString> JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space)
|
||||
ThrowCompletionOr<Optional<DeprecatedString>> JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
|
@ -62,7 +62,7 @@ ThrowCompletionOr<DeprecatedString> JSONObject::stringify_impl(VM& vm, Value val
|
|||
Vector<DeprecatedString> list;
|
||||
for (size_t i = 0; i < replacer_length; ++i) {
|
||||
auto replacer_value = TRY(replacer_object.get(i));
|
||||
DeprecatedString item;
|
||||
Optional<DeprecatedString> item;
|
||||
if (replacer_value.is_string()) {
|
||||
item = replacer_value.as_string().deprecated_string();
|
||||
} else if (replacer_value.is_number()) {
|
||||
|
@ -72,8 +72,8 @@ ThrowCompletionOr<DeprecatedString> JSONObject::stringify_impl(VM& vm, Value val
|
|||
if (is<StringObject>(value_object) || is<NumberObject>(value_object))
|
||||
item = TRY(replacer_value.to_deprecated_string(vm));
|
||||
}
|
||||
if (!item.is_null() && !list.contains_slow(item)) {
|
||||
list.append(item);
|
||||
if (item.has_value() && !list.contains_slow(*item)) {
|
||||
list.append(*item);
|
||||
}
|
||||
}
|
||||
state.property_list = list;
|
||||
|
@ -118,15 +118,15 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify)
|
|||
auto replacer = vm.argument(1);
|
||||
auto space = vm.argument(2);
|
||||
|
||||
auto string = TRY(stringify_impl(vm, value, replacer, space));
|
||||
if (string.is_null())
|
||||
auto maybe_string = TRY(stringify_impl(vm, value, replacer, space));
|
||||
if (!maybe_string.has_value())
|
||||
return js_undefined();
|
||||
|
||||
return PrimitiveString::create(vm, string);
|
||||
return PrimitiveString::create(vm, maybe_string.release_value());
|
||||
}
|
||||
|
||||
// 25.5.2.1 SerializeJSONProperty ( state, key, holder ), https://tc39.es/ecma262/#sec-serializejsonproperty
|
||||
ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_property(VM& vm, StringifyState& state, PropertyKey const& key, Object* holder)
|
||||
ThrowCompletionOr<Optional<DeprecatedString>> 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));
|
||||
|
@ -209,14 +209,14 @@ ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_property(VM& vm,
|
|||
|
||||
// b. If isArray is true, return ? SerializeJSONArray(state, value).
|
||||
if (is_array)
|
||||
return serialize_json_array(vm, state, value.as_object());
|
||||
return TRY(serialize_json_array(vm, state, value.as_object()));
|
||||
|
||||
// c. Return ? SerializeJSONObject(state, value).
|
||||
return serialize_json_object(vm, state, value.as_object());
|
||||
return TRY(serialize_json_object(vm, state, value.as_object()));
|
||||
}
|
||||
|
||||
// 12. Return undefined.
|
||||
return DeprecatedString {};
|
||||
return Optional<DeprecatedString> {};
|
||||
}
|
||||
|
||||
// 25.5.2.4 SerializeJSONObject ( state, value ), https://tc39.es/ecma262/#sec-serializejsonobject
|
||||
|
@ -234,7 +234,7 @@ ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_object(VM& vm, St
|
|||
if (key.is_symbol())
|
||||
return {};
|
||||
auto serialized_property_string = TRY(serialize_json_property(vm, state, key, &object));
|
||||
if (!serialized_property_string.is_null()) {
|
||||
if (serialized_property_string.has_value()) {
|
||||
property_strings.append(DeprecatedString::formatted(
|
||||
"{}:{}{}",
|
||||
quote_json_string(key.to_string()),
|
||||
|
@ -305,10 +305,10 @@ ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_array(VM& vm, Str
|
|||
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
auto serialized_property_string = TRY(serialize_json_property(vm, state, i, &object));
|
||||
if (serialized_property_string.is_null()) {
|
||||
if (!serialized_property_string.has_value()) {
|
||||
property_strings.append("null"sv);
|
||||
} else {
|
||||
property_strings.append(serialized_property_string);
|
||||
property_strings.append(serialized_property_string.release_value());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
|
||||
// The base implementation of stringify is exposed because it is used by
|
||||
// test-js to communicate between the JS tests and the C++ test runner.
|
||||
static ThrowCompletionOr<DeprecatedString> stringify_impl(VM&, Value value, Value replacer, Value space);
|
||||
static ThrowCompletionOr<Optional<DeprecatedString>> stringify_impl(VM&, Value value, Value replacer, Value space);
|
||||
|
||||
static Value parse_json_value(VM&, JsonValue const&);
|
||||
|
||||
|
@ -35,7 +35,7 @@ private:
|
|||
};
|
||||
|
||||
// Stringify helpers
|
||||
static ThrowCompletionOr<DeprecatedString> serialize_json_property(VM&, StringifyState&, PropertyKey const& key, Object* holder);
|
||||
static ThrowCompletionOr<Optional<DeprecatedString>> serialize_json_property(VM&, StringifyState&, PropertyKey const& key, Object* holder);
|
||||
static ThrowCompletionOr<DeprecatedString> serialize_json_object(VM&, StringifyState&, Object&);
|
||||
static ThrowCompletionOr<DeprecatedString> serialize_json_array(VM&, StringifyState&, Object&);
|
||||
static DeprecatedString quote_json_string(DeprecatedString);
|
||||
|
|
|
@ -221,7 +221,7 @@ NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, DeprecatedString s
|
|||
|
||||
NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, DeprecatedFlyString const& string)
|
||||
{
|
||||
return create(vm, string.impl());
|
||||
return create(vm, *string.impl());
|
||||
}
|
||||
|
||||
NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, PrimitiveString& lhs, PrimitiveString& rhs)
|
||||
|
|
|
@ -910,7 +910,7 @@ ThrowCompletionOr<NonnullGCPtr<Module>> VM::resolve_imported_module(ScriptOrModu
|
|||
VERIFY(module_request.assertions.is_empty() || (module_request.assertions.size() == 1 && module_request.assertions.first().key == "type"));
|
||||
auto module_type = module_request.assertions.is_empty() ? DeprecatedString {} : module_request.assertions.first().value;
|
||||
|
||||
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] module at {} has type {} [is_null={}]", module_request.module_specifier, module_type, module_type.is_null());
|
||||
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] module at {} has type {}", module_request.module_specifier, module_type);
|
||||
|
||||
StringView base_filename = referencing_script_or_module.visit(
|
||||
[&](Empty) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue