Skip to content

Commit 0090b91

Browse files
shannonboothtrflynn89
authored andcommitted
LibJS: Make ParserError::to_string infallible
1 parent d568b15 commit 0090b91

File tree

11 files changed

+17
-17
lines changed

11 files changed

+17
-17
lines changed

Meta/Lagom/Wasm/js_repl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static ErrorOr<bool> parse_and_run(JS::Realm& realm, StringView source, StringVi
133133
if (!hint.is_empty())
134134
displayln("{}", hint);
135135

136-
auto error_string = TRY(error.to_string());
136+
auto error_string = error.to_string();
137137
displayln("{}", error_string);
138138
result = g_vm->throw_completion<JS::SyntaxError>(move(error_string));
139139
} else {
@@ -149,7 +149,7 @@ static ErrorOr<bool> parse_and_run(JS::Realm& realm, StringView source, StringVi
149149
if (!hint.is_empty())
150150
displayln("{}", hint);
151151

152-
auto error_string = TRY(error.to_string());
152+
auto error_string = error.to_string();
153153
displayln("{}", error_string);
154154
result = g_vm->throw_completion<JS::SyntaxError>(move(error_string));
155155
} else {

Userland/Applications/Spreadsheet/Spreadsheet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ JS::ThrowCompletionOr<JS::Value> Sheet::evaluate(StringView source, Cell* on_beh
167167
name);
168168

169169
if (script_or_error.is_error())
170-
return vm().throw_completion<JS::SyntaxError>(TRY_OR_THROW_OOM(vm(), script_or_error.error().first().to_string()));
170+
return vm().throw_completion<JS::SyntaxError>(script_or_error.error().first().to_string());
171171

172172
return vm().bytecode_interpreter().run(script_or_error.value());
173173
}

Userland/Libraries/LibJS/Contrib/Test262/262Object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ JS_DEFINE_NATIVE_FUNCTION($262Object::eval_script)
100100
auto& error = script_or_error.error()[0];
101101

102102
// b. Return Completion { [[Type]]: throw, [[Value]]: error, [[Target]]: empty }.
103-
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
103+
return vm.throw_completion<SyntaxError>(error.to_string());
104104
}
105105

106106
// 5. Let status be ScriptEvaluation(s).

Userland/Libraries/LibJS/ParserError.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
namespace JS {
1414

15-
ErrorOr<String> ParserError::to_string() const
15+
String ParserError::to_string() const
1616
{
1717
if (!position.has_value())
18-
return String::from_byte_string(message);
19-
return String::formatted("{} (line: {}, column: {})", message, position.value().line, position.value().column);
18+
return MUST(String::from_byte_string(message));
19+
return MUST(String::formatted("{} (line: {}, column: {})", message, position.value().line, position.value().column));
2020
}
2121

2222
ByteString ParserError::to_byte_string() const

Userland/Libraries/LibJS/ParserError.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct ParserError {
1919
ByteString message;
2020
Optional<Position> position;
2121

22-
ErrorOr<String> to_string() const;
22+
String to_string() const;
2323
ByteString to_byte_string() const;
2424
ByteString source_location_hint(StringView source, char const spacer = ' ', char const indicator = '^') const;
2525
};

Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ ThrowCompletionOr<Value> perform_eval(VM& vm, Value x, CallerMode strict_caller,
586586
// b. If script is a List of errors, throw a SyntaxError exception.
587587
if (parser.has_errors()) {
588588
auto& error = parser.errors()[0];
589-
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
589+
return vm.throw_completion<SyntaxError>(error.to_string());
590590
}
591591

592592
bool strict_eval = false;

Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
178178
// 17. If parameters is a List of errors, throw a SyntaxError exception.
179179
if (parameters_parser.has_errors()) {
180180
auto error = parameters_parser.errors()[0];
181-
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
181+
return vm.throw_completion<SyntaxError>(error.to_string());
182182
}
183183

184184
// 18. Let body be ParseText(StringToCodePoints(bodyString), bodySym).
@@ -188,7 +188,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
188188
// 19. If body is a List of errors, throw a SyntaxError exception.
189189
if (body_parser.has_errors()) {
190190
auto error = body_parser.errors()[0];
191-
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
191+
return vm.throw_completion<SyntaxError>(error.to_string());
192192
}
193193

194194
// 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
202202
// 23. If expr is a List of errors, throw a SyntaxError exception.
203203
if (source_parser.has_errors()) {
204204
auto error = source_parser.errors()[0];
205-
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
205+
return vm.throw_completion<SyntaxError>(error.to_string());
206206
}
207207

208208
// 24. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).

Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(VM& vm, StringView source_tex
110110
// b. If script is a List of errors, throw a SyntaxError exception.
111111
if (parser.has_errors()) {
112112
auto& error = parser.errors()[0];
113-
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
113+
return vm.throw_completion<SyntaxError>(error.to_string());
114114
}
115115

116116
// c. If script Contains ScriptBody is false, return undefined.

Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(ByteString filename, Strin
5959
dbgln_if(HTML_SCRIPT_DEBUG, "ClassicScript: Failed to parse: {}", parse_error.to_byte_string());
6060

6161
// 1. Set script's parse error and its error to rethrow to result[0].
62-
script->set_parse_error(JS::SyntaxError::create(environment_settings_object.realm(), parse_error.to_string().release_value_but_fixme_should_propagate_errors()));
62+
script->set_parse_error(JS::SyntaxError::create(environment_settings_object.realm(), parse_error.to_string()));
6363
script->set_error_to_rethrow(script->parse_error());
6464

6565
// 2. Return script.

Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::c
6262
dbgln("JavaScriptModuleScript: Failed to parse: {}", parse_error.to_byte_string());
6363

6464
// 1. Set script's parse error to result[0].
65-
script->set_parse_error(JS::SyntaxError::create(settings_object.realm(), parse_error.to_string().release_value_but_fixme_should_propagate_errors()));
65+
script->set_parse_error(JS::SyntaxError::create(settings_object.realm(), parse_error.to_string()));
6666

6767
// 2. Return script.
6868
return script;

0 commit comments

Comments
 (0)