1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 08:28:11 +00:00

LibJS: Make Value::to_string_without_side_effects() infallible

Work towards #20449.
This commit is contained in:
Andreas Kling 2023-08-09 08:49:02 +02:00
parent b8f78c0adc
commit 97ebfd9f0f
69 changed files with 182 additions and 182 deletions

View file

@ -426,7 +426,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
@cpp_type@* @cpp_name@ = nullptr;
if (!@js_name@@js_suffix@.is_nullish()) {
if (!@js_name@@js_suffix@.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, @js_name@@js_suffix@.to_string_without_side_effects()));
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects());
auto callback_type = vm.heap().allocate_without_realm<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
@cpp_name@ = TRY(throw_dom_exception_if_needed(vm, [&] { return @cpp_type@::create(realm, *callback_type); }));
@ -435,7 +435,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
} else {
scoped_generator.append(R"~~~(
if (!@js_name@@js_suffix@.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, @js_name@@js_suffix@.to_string_without_side_effects()));
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects());
auto callback_type = vm.heap().allocate_without_realm<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
auto @cpp_name@ = adopt_ref(*new @cpp_type@(callback_type));
@ -846,7 +846,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (!callback_function.is_legacy_treat_non_object_as_null) {
callback_function_generator.append(R"~~~(
if (!@js_name@@js_suffix@.is_function())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, TRY_OR_THROW_OOM(vm, @js_name@@js_suffix@.to_string_without_side_effects()));
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, @js_name@@js_suffix@.to_string_without_side_effects());
)~~~");
}
// 2. Return the IDL callback function type value that represents a reference to the same object that V represents, with the incumbent settings object as the callback context.
@ -911,11 +911,11 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
sequence_generator.append(R"~~~(
if (!@js_name@@js_suffix@.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, @js_name@@js_suffix@.to_string_without_side_effects()));
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects());
auto iterator_method@recursion_depth@ = TRY(@js_name@@js_suffix@.get_method(vm, vm.well_known_symbol_iterator()));
if (!iterator_method@recursion_depth@)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, TRY_OR_THROW_OOM(vm, @js_name@@js_suffix@.to_string_without_side_effects()));
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, @js_name@@js_suffix@.to_string_without_side_effects());
)~~~");
parameterized_type.generate_sequence_from_iterable(sequence_generator, DeprecatedString::formatted("{}{}", acceptable_cpp_name, optional ? "_non_optional" : ""), DeprecatedString::formatted("{}{}", js_name, js_suffix), DeprecatedString::formatted("iterator_method{}", recursion_depth), interface, recursion_depth + 1);
@ -960,7 +960,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (recursion_depth == 0) {
record_generator.append(R"~~~(
if (!@js_name@@js_suffix@.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, @js_name@@js_suffix@.to_string_without_side_effects()));
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects());
auto& @js_name@@js_suffix@_object = @js_name@@js_suffix@.as_object();
)~~~");
@ -3000,7 +3000,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::for_each)
auto callback = vm.argument(0);
if (!callback.is_function())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, TRY_OR_THROW_OOM(vm, callback.to_string_without_side_effects()));
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, callback.to_string_without_side_effects());
auto this_value = vm.this_value();
TRY(impl->for_each([&](auto key, auto value) -> JS::ThrowCompletionOr<void> {