mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:57:35 +00:00
LibJS: Make Value::to_string_without_side_effects() infallible
Work towards #20449.
This commit is contained in:
parent
b8f78c0adc
commit
97ebfd9f0f
69 changed files with 182 additions and 182 deletions
|
@ -263,37 +263,37 @@ WebIDL::ExceptionOr<String> DOMMatrixReadOnly::to_string() const
|
|||
TRY_OR_THROW_OOM(vm, builder.try_append("matrix("sv));
|
||||
|
||||
// 2. Append ! ToString(m11 element) to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(TRY_OR_THROW_OOM(vm, JS::Value(m11()).to_string_without_side_effects())));
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(JS::Value(m11()).to_string_without_side_effects()));
|
||||
|
||||
// 3. Append ", " to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(", "sv));
|
||||
|
||||
// 4. Append ! ToString(m12 element) to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(TRY_OR_THROW_OOM(vm, JS::Value(m12()).to_string_without_side_effects())));
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(JS::Value(m12()).to_string_without_side_effects()));
|
||||
|
||||
// 5. Append ", " to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(", "sv));
|
||||
|
||||
// 6. Append ! ToString(m21 element) to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(TRY_OR_THROW_OOM(vm, JS::Value(m21()).to_string_without_side_effects())));
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(JS::Value(m21()).to_string_without_side_effects()));
|
||||
|
||||
// 7. Append ", " to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(", "sv));
|
||||
|
||||
// 8. Append ! ToString(m22 element) to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(TRY_OR_THROW_OOM(vm, JS::Value(m22()).to_string_without_side_effects())));
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(JS::Value(m22()).to_string_without_side_effects()));
|
||||
|
||||
// 9. Append ", " to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(", "sv));
|
||||
|
||||
// 10. Append ! ToString(m41 element) to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(TRY_OR_THROW_OOM(vm, JS::Value(m41()).to_string_without_side_effects())));
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(JS::Value(m41()).to_string_without_side_effects()));
|
||||
|
||||
// 11. Append ", " to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(", "sv));
|
||||
|
||||
// 12. Append ! ToString(m42 element) to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(TRY_OR_THROW_OOM(vm, JS::Value(m42()).to_string_without_side_effects())));
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(JS::Value(m42()).to_string_without_side_effects()));
|
||||
|
||||
// 13. Append ")" to string.
|
||||
TRY_OR_THROW_OOM(vm, builder.try_append(")"sv));
|
||||
|
|
|
@ -38,7 +38,7 @@ static JS::ThrowCompletionOr<JS::NonnullGCPtr<WebIDL::CallbackType>> convert_val
|
|||
// FIXME: De-duplicate this from the IDL generator.
|
||||
// 1. If the result of calling IsCallable(V) is false and the conversion to an IDL value is not being performed due to V being assigned to an attribute whose type is a nullable callback function that is annotated with [LegacyTreatNonObjectAsNull], then throw a TypeError.
|
||||
if (!value.is_function())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, TRY_OR_THROW_OOM(vm, value.to_string_without_side_effects()));
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, value.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.
|
||||
return vm.heap().allocate_without_realm<WebIDL::CallbackType>(value.as_object(), HTML::incumbent_settings_object());
|
||||
|
@ -51,14 +51,14 @@ static JS::ThrowCompletionOr<Vector<String>> convert_value_to_sequence_of_string
|
|||
// An ECMAScript value V is converted to an IDL sequence<T> value as follows:
|
||||
// 1. If Type(V) is not Object, throw a TypeError.
|
||||
if (!value.is_object())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, value.to_string_without_side_effects()));
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, value.to_string_without_side_effects());
|
||||
|
||||
// 2. Let method be ? GetMethod(V, @@iterator).
|
||||
auto method = TRY(value.get_method(vm, vm.well_known_symbol_iterator()));
|
||||
|
||||
// 3. If method is undefined, throw a TypeError.
|
||||
if (!method)
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, TRY_OR_THROW_OOM(vm, value.to_string_without_side_effects()));
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, value.to_string_without_side_effects());
|
||||
|
||||
// 4. Return the result of creating a sequence from V and method.
|
||||
|
||||
|
@ -108,7 +108,7 @@ JS::ThrowCompletionOr<void> CustomElementRegistry::define(String const& name, We
|
|||
|
||||
// 1. If IsConstructor(constructor) is false, then throw a TypeError.
|
||||
if (!JS::Value(constructor->callback).is_constructor())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, TRY_OR_THROW_OOM(vm, JS::Value(constructor->callback).to_string_without_side_effects()));
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, JS::Value(constructor->callback).to_string_without_side_effects());
|
||||
|
||||
// 2. If name is not a valid custom element name, then throw a "SyntaxError" DOMException.
|
||||
if (!is_valid_custom_element_name(name))
|
||||
|
@ -179,7 +179,7 @@ JS::ThrowCompletionOr<void> CustomElementRegistry::define(String const& name, We
|
|||
|
||||
// 2. If Type(prototype) is not Object, then throw a TypeError exception.
|
||||
if (!prototype_value.is_object())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, prototype_value.to_string_without_side_effects()));
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, prototype_value.to_string_without_side_effects());
|
||||
|
||||
auto& prototype = prototype_value.as_object();
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ void report_exception_to_console(JS::Value value, JS::Realm& realm, ErrorInPromi
|
|||
dbgln("\033[31;1mUnhandled JavaScript exception{}:\033[0m {}", error_in_promise == ErrorInPromise::Yes ? " (in promise)" : "", value);
|
||||
}
|
||||
|
||||
console.report_exception(*JS::Error::create(realm, value.to_string_without_side_effects().release_value_but_fixme_should_propagate_errors()), error_in_promise == ErrorInPromise::Yes);
|
||||
console.report_exception(*JS::Error::create(realm, value.to_string_without_side_effects()), error_in_promise == ErrorInPromise::Yes);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#report-the-exception
|
||||
|
|
|
@ -326,7 +326,7 @@ WebIDL::ExceptionOr<void> Worker::terminate()
|
|||
// https://html.spec.whatwg.org/multipage/workers.html#dom-worker-postmessage
|
||||
void Worker::post_message(JS::Value message, JS::Value)
|
||||
{
|
||||
dbgln_if(WEB_WORKER_DEBUG, "WebWorker: Post Message: {}", MUST(message.to_string_without_side_effects()));
|
||||
dbgln_if(WEB_WORKER_DEBUG, "WebWorker: Post Message: {}", message.to_string_without_side_effects());
|
||||
|
||||
// 1. Let targetPort be the port with which this is entangled, if any; otherwise let it be null.
|
||||
auto& target_port = m_outside_port;
|
||||
|
|
|
@ -3297,7 +3297,7 @@ JS::ThrowCompletionOr<JS::Handle<WebIDL::CallbackType>> property_to_callback(JS:
|
|||
return JS::Handle<WebIDL::CallbackType> {};
|
||||
|
||||
if (!property.is_function())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, TRY_OR_THROW_OOM(vm, property.to_string_without_side_effects()));
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, property.to_string_without_side_effects());
|
||||
|
||||
return vm.heap().allocate_without_realm<WebIDL::CallbackType>(property.as_object(), HTML::incumbent_settings_object(), operation_returns_promise);
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ JS::ThrowCompletionOr<size_t> instantiate_module(JS::VM& vm, Wasm::Module const&
|
|||
|
||||
auto method = TRY(result.get_method(vm, vm.names.iterator));
|
||||
if (method == JS::js_undefined())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, TRY_OR_THROW_OOM(vm, result.to_string_without_side_effects()));
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, result.to_string_without_side_effects());
|
||||
|
||||
auto values = TRY(JS::iterator_to_list(vm, TRY(JS::get_iterator_from_method(vm, result, *method))));
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, Deprec
|
|||
|
||||
// 4. If ! IsCallable(X) is false, then set completion to a new Completion{[[Type]]: throw, [[Value]]: a newly created TypeError object, [[Target]]: empty}, and jump to the step labeled return.
|
||||
if (!get_result.value().is_function()) {
|
||||
completion = realm.vm().template throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, TRY_OR_THROW_OOM(realm.vm(), get_result.value().to_string_without_side_effects()));
|
||||
completion = realm.vm().template throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, get_result.value().to_string_without_side_effects());
|
||||
return clean_up_on_return(stored_settings, relevant_settings, completion, callback.operation_returns_promise);
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ JS::Completion construct(WebIDL::CallbackType& callback, JS::MarkedVector<JS::Va
|
|||
|
||||
// 3. If IsConstructor(F) is false, throw a TypeError exception.
|
||||
if (!JS::Value(function_object).is_constructor())
|
||||
return realm.vm().template throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, TRY_OR_THROW_OOM(realm.vm(), JS::Value(function_object).to_string_without_side_effects()));
|
||||
return realm.vm().template throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, JS::Value(function_object).to_string_without_side_effects());
|
||||
|
||||
// 5. Let relevant settings be realm’s settings object.
|
||||
auto& relevant_settings = Bindings::host_defined_environment_settings_object(realm);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue