mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 09:21:57 -05:00
LibJS: Make ParserError::to_string infallible
This commit is contained in:
parent
d568b15acf
commit
0090b916dd
11 changed files with 17 additions and 17 deletions
|
@ -133,7 +133,7 @@ static ErrorOr<bool> parse_and_run(JS::Realm& realm, StringView source, StringVi
|
|||
if (!hint.is_empty())
|
||||
displayln("{}", hint);
|
||||
|
||||
auto error_string = TRY(error.to_string());
|
||||
auto error_string = error.to_string();
|
||||
displayln("{}", error_string);
|
||||
result = g_vm->throw_completion<JS::SyntaxError>(move(error_string));
|
||||
} else {
|
||||
|
@ -149,7 +149,7 @@ static ErrorOr<bool> parse_and_run(JS::Realm& realm, StringView source, StringVi
|
|||
if (!hint.is_empty())
|
||||
displayln("{}", hint);
|
||||
|
||||
auto error_string = TRY(error.to_string());
|
||||
auto error_string = error.to_string();
|
||||
displayln("{}", error_string);
|
||||
result = g_vm->throw_completion<JS::SyntaxError>(move(error_string));
|
||||
} else {
|
||||
|
|
|
@ -167,7 +167,7 @@ JS::ThrowCompletionOr<JS::Value> Sheet::evaluate(StringView source, Cell* on_beh
|
|||
name);
|
||||
|
||||
if (script_or_error.is_error())
|
||||
return vm().throw_completion<JS::SyntaxError>(TRY_OR_THROW_OOM(vm(), script_or_error.error().first().to_string()));
|
||||
return vm().throw_completion<JS::SyntaxError>(script_or_error.error().first().to_string());
|
||||
|
||||
return vm().bytecode_interpreter().run(script_or_error.value());
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ JS_DEFINE_NATIVE_FUNCTION($262Object::eval_script)
|
|||
auto& error = script_or_error.error()[0];
|
||||
|
||||
// b. Return Completion { [[Type]]: throw, [[Value]]: error, [[Target]]: empty }.
|
||||
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
|
||||
return vm.throw_completion<SyntaxError>(error.to_string());
|
||||
}
|
||||
|
||||
// 5. Let status be ScriptEvaluation(s).
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
ErrorOr<String> ParserError::to_string() const
|
||||
String ParserError::to_string() const
|
||||
{
|
||||
if (!position.has_value())
|
||||
return String::from_byte_string(message);
|
||||
return String::formatted("{} (line: {}, column: {})", message, position.value().line, position.value().column);
|
||||
return MUST(String::from_byte_string(message));
|
||||
return MUST(String::formatted("{} (line: {}, column: {})", message, position.value().line, position.value().column));
|
||||
}
|
||||
|
||||
ByteString ParserError::to_byte_string() const
|
||||
|
|
|
@ -19,7 +19,7 @@ struct ParserError {
|
|||
ByteString message;
|
||||
Optional<Position> position;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
ByteString to_byte_string() const;
|
||||
ByteString source_location_hint(StringView source, char const spacer = ' ', char const indicator = '^') const;
|
||||
};
|
||||
|
|
|
@ -586,7 +586,7 @@ ThrowCompletionOr<Value> perform_eval(VM& vm, Value x, CallerMode strict_caller,
|
|||
// b. If script is a List of errors, throw a SyntaxError exception.
|
||||
if (parser.has_errors()) {
|
||||
auto& error = parser.errors()[0];
|
||||
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
|
||||
return vm.throw_completion<SyntaxError>(error.to_string());
|
||||
}
|
||||
|
||||
bool strict_eval = false;
|
||||
|
|
|
@ -178,7 +178,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
|
|||
// 17. If parameters is a List of errors, throw a SyntaxError exception.
|
||||
if (parameters_parser.has_errors()) {
|
||||
auto error = parameters_parser.errors()[0];
|
||||
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
|
||||
return vm.throw_completion<SyntaxError>(error.to_string());
|
||||
}
|
||||
|
||||
// 18. Let body be ParseText(StringToCodePoints(bodyString), bodySym).
|
||||
|
@ -188,7 +188,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
|
|||
// 19. If body is a List of errors, throw a SyntaxError exception.
|
||||
if (body_parser.has_errors()) {
|
||||
auto error = body_parser.errors()[0];
|
||||
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
|
||||
return vm.throw_completion<SyntaxError>(error.to_string());
|
||||
}
|
||||
|
||||
// 20. NOTE: The parameters and body are parsed separately to ensure that each is valid alone. For example, new Function("/*", "*/ ) {") is not legal.
|
||||
|
@ -202,7 +202,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
|
|||
// 23. If expr is a List of errors, throw a SyntaxError exception.
|
||||
if (source_parser.has_errors()) {
|
||||
auto error = source_parser.errors()[0];
|
||||
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
|
||||
return vm.throw_completion<SyntaxError>(error.to_string());
|
||||
}
|
||||
|
||||
// 24. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).
|
||||
|
|
|
@ -110,7 +110,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(VM& vm, StringView source_tex
|
|||
// b. If script is a List of errors, throw a SyntaxError exception.
|
||||
if (parser.has_errors()) {
|
||||
auto& error = parser.errors()[0];
|
||||
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
|
||||
return vm.throw_completion<SyntaxError>(error.to_string());
|
||||
}
|
||||
|
||||
// c. If script Contains ScriptBody is false, return undefined.
|
||||
|
|
|
@ -59,7 +59,7 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(ByteString filename, Strin
|
|||
dbgln_if(HTML_SCRIPT_DEBUG, "ClassicScript: Failed to parse: {}", parse_error.to_byte_string());
|
||||
|
||||
// 1. Set script's parse error and its error to rethrow to result[0].
|
||||
script->set_parse_error(JS::SyntaxError::create(environment_settings_object.realm(), parse_error.to_string().release_value_but_fixme_should_propagate_errors()));
|
||||
script->set_parse_error(JS::SyntaxError::create(environment_settings_object.realm(), parse_error.to_string()));
|
||||
script->set_error_to_rethrow(script->parse_error());
|
||||
|
||||
// 2. Return script.
|
||||
|
|
|
@ -62,7 +62,7 @@ WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::c
|
|||
dbgln("JavaScriptModuleScript: Failed to parse: {}", parse_error.to_byte_string());
|
||||
|
||||
// 1. Set script's parse error to result[0].
|
||||
script->set_parse_error(JS::SyntaxError::create(settings_object.realm(), parse_error.to_string().release_value_but_fixme_should_propagate_errors()));
|
||||
script->set_parse_error(JS::SyntaxError::create(settings_object.realm(), parse_error.to_string()));
|
||||
|
||||
// 2. Return script.
|
||||
return script;
|
||||
|
|
|
@ -222,7 +222,7 @@ static ErrorOr<bool> parse_and_run(JS::Realm& realm, StringView source, StringVi
|
|||
if (!hint.is_empty())
|
||||
outln("{}", hint);
|
||||
|
||||
auto error_string = TRY(error.to_string());
|
||||
auto error_string = error.to_string();
|
||||
outln("{}", error_string);
|
||||
result = vm.throw_completion<JS::SyntaxError>(move(error_string));
|
||||
} else {
|
||||
|
@ -236,7 +236,7 @@ static ErrorOr<bool> parse_and_run(JS::Realm& realm, StringView source, StringVi
|
|||
if (!hint.is_empty())
|
||||
outln("{}", hint);
|
||||
|
||||
auto error_string = TRY(error.to_string());
|
||||
auto error_string = error.to_string();
|
||||
outln("{}", error_string);
|
||||
result = vm.throw_completion<JS::SyntaxError>(move(error_string));
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue