1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

LibJS: Convert to_string() to ThrowCompletionOr

Also update get_function_name() to use ThrowCompletionOr, but this is
not a standard AO and should be refactored out of existence eventually.
This commit is contained in:
Linus Groh 2021-10-12 17:49:01 +01:00
parent 5d38cf4973
commit 4d8912a92b
48 changed files with 171 additions and 415 deletions

View file

@ -890,9 +890,7 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView const& source
static JS::Value load_file_impl(JS::VM& vm, JS::GlobalObject& global_object)
{
auto filename = vm.argument(0).to_string(global_object);
if (vm.exception())
return {};
auto filename = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
auto file = Core::File::construct(filename);
if (!file->open(Core::OpenMode::ReadOnly)) {
vm.throw_exception<JS::Error>(global_object, String::formatted("Failed to open '{}': {}", filename, file->error_string()));
@ -914,9 +912,7 @@ static JS::Value load_file_impl(JS::VM& vm, JS::GlobalObject& global_object)
static JS::Value load_json_impl(JS::VM& vm, JS::GlobalObject& global_object)
{
auto filename = vm.argument(0).to_string(global_object);
if (vm.exception())
return {};
auto filename = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
auto file = Core::File::construct(filename);
if (!file->open(Core::OpenMode::ReadOnly)) {
vm.throw_exception<JS::Error>(global_object, String::formatted("Failed to open '{}': {}", filename, file->error_string()));