mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibJS+Everywhere: Convert JS::Error to String
This includes an Error::create overload to create an Error from a UTF-8 StringView. If creating a String from that view fails, the factory will return an OOM InternalError instead. VM::throw_completion can also make use of this overload via its perfect forwarding.
This commit is contained in:
parent
153b793638
commit
88814acbd3
36 changed files with 198 additions and 151 deletions
|
@ -193,14 +193,14 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_real_cell_contents)
|
|||
auto sheet_object = static_cast<SheetGlobalObject*>(this_object);
|
||||
|
||||
if (vm.argument_count() != 1)
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly one argument to get_real_cell_contents()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly one argument to get_real_cell_contents()"sv);
|
||||
|
||||
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()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected a String argument to get_real_cell_contents()"sv);
|
||||
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");
|
||||
return vm.throw_completion<JS::TypeError>("Invalid cell name"sv);
|
||||
|
||||
auto const* cell = sheet_object->m_sheet.at(position.value());
|
||||
if (!cell)
|
||||
|
@ -222,18 +222,18 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::set_real_cell_contents)
|
|||
auto sheet_object = static_cast<SheetGlobalObject*>(this_object);
|
||||
|
||||
if (vm.argument_count() != 2)
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly two arguments to set_real_cell_contents()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly two arguments to set_real_cell_contents()"sv);
|
||||
|
||||
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");
|
||||
return vm.throw_completion<JS::TypeError>("Expected the first argument of set_real_cell_contents() to be a String"sv);
|
||||
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");
|
||||
return vm.throw_completion<JS::TypeError>("Invalid cell name"sv);
|
||||
|
||||
auto new_contents_value = vm.argument(1);
|
||||
if (!new_contents_value.is_string())
|
||||
return vm.throw_completion<JS::TypeError>("Expected the second argument of set_real_cell_contents() to be a String");
|
||||
return vm.throw_completion<JS::TypeError>("Expected the second argument of set_real_cell_contents() to be a String"sv);
|
||||
|
||||
auto& cell = sheet_object->m_sheet.ensure(position.value());
|
||||
auto new_contents = TRY(new_contents_value.as_string().deprecated_string());
|
||||
|
@ -253,10 +253,10 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
|
|||
auto sheet_object = static_cast<SheetGlobalObject*>(this_object);
|
||||
|
||||
if (vm.argument_count() != 1)
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly one argument to parse_cell_name()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly one argument to parse_cell_name()"sv);
|
||||
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()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected a String argument to parse_cell_name()"sv);
|
||||
auto position = sheet_object->m_sheet.parse_cell_name(TRY(name_value.as_string().deprecated_string()));
|
||||
if (!position.has_value())
|
||||
return JS::js_undefined();
|
||||
|
@ -273,7 +273,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position)
|
|||
auto& realm = *vm.current_realm();
|
||||
|
||||
if (vm.argument_count() != 0)
|
||||
return vm.throw_completion<JS::TypeError>("Expected no arguments to current_cell_position()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected no arguments to current_cell_position()"sv);
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
|
@ -297,7 +297,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position)
|
|||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_index)
|
||||
{
|
||||
if (vm.argument_count() != 1)
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly one argument to column_index()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly one argument to column_index()"sv);
|
||||
|
||||
auto column_name = vm.argument(0);
|
||||
if (!column_name.is_string())
|
||||
|
@ -314,7 +314,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_index)
|
|||
auto& sheet = sheet_object->m_sheet;
|
||||
auto column_index = sheet.column_index(column_name_str);
|
||||
if (!column_index.has_value())
|
||||
return vm.throw_completion<JS::TypeError>(DeprecatedString::formatted("'{}' is not a valid column", column_name_str));
|
||||
return vm.throw_completion<JS::TypeError>(TRY_OR_THROW_OOM(vm, String::formatted("'{}' is not a valid column", column_name_str)));
|
||||
|
||||
return JS::Value((i32)column_index.value());
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_index)
|
|||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_arithmetic)
|
||||
{
|
||||
if (vm.argument_count() != 2)
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly two arguments to column_arithmetic()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly two arguments to column_arithmetic()"sv);
|
||||
|
||||
auto column_name = vm.argument(0);
|
||||
if (!column_name.is_string())
|
||||
|
@ -342,7 +342,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_arithmetic)
|
|||
auto& sheet = sheet_object->m_sheet;
|
||||
auto new_column = sheet.column_arithmetic(column_name_str, offset_number);
|
||||
if (!new_column.has_value())
|
||||
return vm.throw_completion<JS::TypeError>(DeprecatedString::formatted("'{}' is not a valid column", column_name_str));
|
||||
return vm.throw_completion<JS::TypeError>(TRY_OR_THROW_OOM(vm, String::formatted("'{}' is not a valid column", column_name_str)));
|
||||
|
||||
return JS::PrimitiveString::create(vm, new_column.release_value());
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_arithmetic)
|
|||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_column_bound)
|
||||
{
|
||||
if (vm.argument_count() != 1)
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly one argument to get_column_bound()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly one argument to get_column_bound()"sv);
|
||||
|
||||
auto column_name = vm.argument(0);
|
||||
if (!column_name.is_string())
|
||||
|
@ -366,7 +366,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_column_bound)
|
|||
auto& sheet = sheet_object->m_sheet;
|
||||
auto maybe_column_index = sheet.column_index(column_name_str);
|
||||
if (!maybe_column_index.has_value())
|
||||
return vm.throw_completion<JS::TypeError>(DeprecatedString::formatted("'{}' is not a valid column", column_name_str));
|
||||
return vm.throw_completion<JS::TypeError>(TRY_OR_THROW_OOM(vm, String::formatted("'{}' is not a valid column", column_name_str)));
|
||||
|
||||
auto bounds = sheet.written_data_bounds(*maybe_column_index);
|
||||
return JS::Value(bounds.row);
|
||||
|
@ -396,10 +396,10 @@ void WorkbookObject::visit_edges(Visitor& visitor)
|
|||
JS_DEFINE_NATIVE_FUNCTION(WorkbookObject::sheet)
|
||||
{
|
||||
if (vm.argument_count() != 1)
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly one argument to sheet()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected exactly one argument to sheet()"sv);
|
||||
auto name_value = vm.argument(0);
|
||||
if (!name_value.is_string() && !name_value.is_number())
|
||||
return vm.throw_completion<JS::TypeError>("Expected a String or Number argument to sheet()");
|
||||
return vm.throw_completion<JS::TypeError>("Expected a String or Number argument to sheet()"sv);
|
||||
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue