mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:17:35 +00:00
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.
This commit is contained in:
parent
d793262beb
commit
115baa7e32
57 changed files with 306 additions and 295 deletions
|
@ -196,7 +196,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_real_cell_contents)
|
|||
auto name_value = vm.argument(0);
|
||||
if (!name_value.is_string())
|
||||
return vm.throw_completion<JS::TypeError>("Expected a String argument to get_real_cell_contents()");
|
||||
auto position = sheet_object->m_sheet.parse_cell_name(name_value.as_string().deprecated_string());
|
||||
auto position = sheet_object->m_sheet.parse_cell_name(TRY(name_value.as_string().deprecated_string()));
|
||||
if (!position.has_value())
|
||||
return vm.throw_completion<JS::TypeError>("Invalid cell name");
|
||||
|
||||
|
@ -225,7 +225,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::set_real_cell_contents)
|
|||
auto name_value = vm.argument(0);
|
||||
if (!name_value.is_string())
|
||||
return vm.throw_completion<JS::TypeError>("Expected the first argument of set_real_cell_contents() to be a String");
|
||||
auto position = sheet_object->m_sheet.parse_cell_name(name_value.as_string().deprecated_string());
|
||||
auto position = sheet_object->m_sheet.parse_cell_name(TRY(name_value.as_string().deprecated_string()));
|
||||
if (!position.has_value())
|
||||
return vm.throw_completion<JS::TypeError>("Invalid cell name");
|
||||
|
||||
|
@ -234,7 +234,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::set_real_cell_contents)
|
|||
return vm.throw_completion<JS::TypeError>("Expected the second argument of set_real_cell_contents() to be a String");
|
||||
|
||||
auto& cell = sheet_object->m_sheet.ensure(position.value());
|
||||
auto& new_contents = new_contents_value.as_string().deprecated_string();
|
||||
auto const& new_contents = TRY(new_contents_value.as_string().deprecated_string());
|
||||
cell.set_data(new_contents);
|
||||
return JS::js_null();
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
|
|||
auto name_value = vm.argument(0);
|
||||
if (!name_value.is_string())
|
||||
return vm.throw_completion<JS::TypeError>("Expected a String argument to parse_cell_name()");
|
||||
auto position = sheet_object->m_sheet.parse_cell_name(name_value.as_string().deprecated_string());
|
||||
auto position = sheet_object->m_sheet.parse_cell_name(TRY(name_value.as_string().deprecated_string()));
|
||||
if (!position.has_value())
|
||||
return JS::js_undefined();
|
||||
|
||||
|
@ -301,7 +301,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_index)
|
|||
if (!column_name.is_string())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "String");
|
||||
|
||||
auto& column_name_str = column_name.as_string().deprecated_string();
|
||||
auto const& column_name_str = TRY(column_name.as_string().deprecated_string());
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
|
@ -326,7 +326,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_arithmetic)
|
|||
if (!column_name.is_string())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "String");
|
||||
|
||||
auto& column_name_str = column_name.as_string().deprecated_string();
|
||||
auto const& column_name_str = TRY(column_name.as_string().deprecated_string());
|
||||
|
||||
auto offset = TRY(vm.argument(1).to_number(vm));
|
||||
auto offset_number = static_cast<i32>(offset.as_double());
|
||||
|
@ -354,7 +354,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_column_bound)
|
|||
if (!column_name.is_string())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "String");
|
||||
|
||||
auto& column_name_str = column_name.as_string().deprecated_string();
|
||||
auto const& column_name_str = TRY(column_name.as_string().deprecated_string());
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
if (!is<SheetGlobalObject>(this_object))
|
||||
|
@ -405,7 +405,7 @@ JS_DEFINE_NATIVE_FUNCTION(WorkbookObject::sheet)
|
|||
auto& workbook = static_cast<WorkbookObject*>(this_object)->m_workbook;
|
||||
|
||||
if (name_value.is_string()) {
|
||||
auto& name = name_value.as_string().deprecated_string();
|
||||
auto const& name = TRY(name_value.as_string().deprecated_string());
|
||||
for (auto& sheet : workbook.sheets()) {
|
||||
if (sheet.name() == name)
|
||||
return JS::Value(&sheet.global_object());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue