summaryrefslogtreecommitdiff
path: root/Meta
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-10-12 17:49:01 +0100
committerLinus Groh <mail@linusgroh.de>2021-10-13 09:55:10 +0100
commit4d8912a92b4378d34a06806b3126c8463bdbdcf5 (patch)
tree9d9ed3594c1512756d1c9337794a29a3d5965b5c /Meta
parent5d38cf497331ba9a533d2da64d91f7044b3ee87f (diff)
downloadserenity-4d8912a92b4378d34a06806b3126c8463bdbdcf5.zip
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.
Diffstat (limited to 'Meta')
-rw-r--r--Meta/Lagom/Fuzzers/FuzzilliJs.cpp9
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp32
2 files changed, 22 insertions, 19 deletions
diff --git a/Meta/Lagom/Fuzzers/FuzzilliJs.cpp b/Meta/Lagom/Fuzzers/FuzzilliJs.cpp
index 74754fb5c3..f66d95c028 100644
--- a/Meta/Lagom/Fuzzers/FuzzilliJs.cpp
+++ b/Meta/Lagom/Fuzzers/FuzzilliJs.cpp
@@ -141,10 +141,7 @@ JS_DEFINE_NATIVE_FUNCTION(TestRunnerGlobalObject::fuzzilli)
if (!vm.argument_count())
return JS::js_undefined();
- auto operation = vm.argument(0).to_string(global_object);
- if (vm.exception())
- return {};
-
+ auto operation = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
if (operation == "FUZZILLI_CRASH") {
auto type = vm.argument(1).to_i32(global_object);
if (vm.exception())
@@ -164,9 +161,7 @@ JS_DEFINE_NATIVE_FUNCTION(TestRunnerGlobalObject::fuzzilli)
fzliout = stdout;
}
- auto string = vm.argument(1).to_string(global_object);
- if (vm.exception())
- return {};
+ auto string = TRY_OR_DISCARD(vm.argument(1).to_string(global_object));
fprintf(fzliout, "%s\n", string.characters());
fflush(fzliout);
}
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
index c9e27c81b5..9260c1b5c3 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
@@ -906,19 +906,24 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (!optional) {
if (!parameter.type.nullable) {
scoped_generator.append(R"~~~(
- auto @cpp_name@ = @js_name@@js_suffix@.is_null() && @legacy_null_to_empty_string@
- ? String::empty()
- : @js_name@@js_suffix@.to_string(global_object);
- if (vm.exception())
- @return_statement@
+ String @cpp_name@;
+ if (@js_name@@js_suffix@.is_null() && @legacy_null_to_empty_string@) {
+ @cpp_name@ = String::empty();
+ } else {
+ auto to_string_result = @js_name@@js_suffix@.to_string(global_object);
+ if (to_string_result.is_error())
+ @return_statement@
+ @cpp_name@ = to_string_result.release_value();
+ }
)~~~");
} else {
scoped_generator.append(R"~~~(
String @cpp_name@;
if (!@js_name@@js_suffix@.is_nullish()) {
- @cpp_name@ = @js_name@@js_suffix@.to_string(global_object);
- if (vm.exception())
+ auto to_string_result = @js_name@@js_suffix@.to_string(global_object);
+ if (to_string_result.is_error())
@return_statement@
+ @cpp_name@ = to_string_result.release_value();
}
)~~~");
}
@@ -926,11 +931,14 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
scoped_generator.append(R"~~~(
String @cpp_name@;
if (!@js_name@@js_suffix@.is_undefined()) {
- @cpp_name@ = @js_name@@js_suffix@.is_null() && @legacy_null_to_empty_string@
- ? String::empty()
- : @js_name@@js_suffix@.to_string(global_object);
- if (vm.exception())
- @return_statement@
+ if (@js_name@@js_suffix@.is_null() && @legacy_null_to_empty_string@) {
+ @cpp_name@ = String::empty();
+ } else {
+ auto to_string_result = @js_name@@js_suffix@.to_string(global_object);
+ if (to_string_result.is_error())
+ @return_statement@
+ @cpp_name@ = to_string_result.release_value();
+ }
})~~~");
if (optional_default_value.has_value() && (!parameter.type.nullable || optional_default_value.value() != "null")) {
scoped_generator.append(R"~~~( else {