diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-07 12:24:05 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-08 12:13:15 +0100 |
commit | 115baa7e32ba30cc409d52546a78ee97a9cd4f76 (patch) | |
tree | a1c12e8c450a667aa99c9f403c3ef0ce830f4dde /Userland/Libraries/LibJS/Runtime/JSONObject.cpp | |
parent | d793262beba3a113bed4c728b572a78583b43277 (diff) | |
download | serenity-115baa7e32ba30cc409d52546a78ee97a9cd4f76.zip |
LibJS+Everywhere: Make PrimitiveString and Utf16String fallible
This makes construction of Utf16String fallible in OOM conditions. The
immediate impact is that PrimitiveString must then be fallible as well,
as it may either transcode UTF-8 to UTF-16, or create a UTF-16 string
from ropes.
There are a couple of places where it is very non-trivial to propagate
the error further. A FIXME has been added to those locations.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/JSONObject.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/JSONObject.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp index 5698a819f1..530b1dac2b 100644 --- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp @@ -63,7 +63,7 @@ ThrowCompletionOr<DeprecatedString> JSONObject::stringify_impl(VM& vm, Value val auto replacer_value = TRY(replacer_object.get(i)); DeprecatedString item; if (replacer_value.is_string()) { - item = replacer_value.as_string().deprecated_string(); + item = TRY(replacer_value.as_string().deprecated_string()); } else if (replacer_value.is_number()) { item = MUST(replacer_value.to_string(vm)); } else if (replacer_value.is_object()) { @@ -93,7 +93,7 @@ ThrowCompletionOr<DeprecatedString> JSONObject::stringify_impl(VM& vm, Value val space_mv = min(10, space_mv); state.gap = space_mv < 1 ? DeprecatedString::empty() : DeprecatedString::repeated(' ', space_mv); } else if (space.is_string()) { - auto string = space.as_string().deprecated_string(); + auto string = TRY(space.as_string().deprecated_string()); if (string.length() <= 10) state.gap = string; else @@ -185,7 +185,7 @@ ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_property(VM& vm, // 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(TRY(value.as_string().deprecated_string())); // 9. If Type(value) is Number, then if (value.is_number()) { @@ -250,7 +250,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(TRY(property.as_string().deprecated_string()))); } StringBuilder builder; if (property_strings.is_empty()) { @@ -473,7 +473,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(TRY(property_key.as_string().deprecated_string()))); } } |