mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:17:35 +00:00
LibJS+Everywhere: Convert JS::Error to String
This includes an Error::create overload to create an Error from a UTF-8 StringView. If creating a String from that view fails, the factory will return an OOM InternalError instead. VM::throw_completion can also make use of this overload via its perfect forwarding.
This commit is contained in:
parent
153b793638
commit
88814acbd3
36 changed files with 198 additions and 151 deletions
|
@ -89,7 +89,7 @@ JS::ThrowCompletionOr<void> Location::set_href(DeprecatedString const& new_href)
|
|||
// 2. Parse the given value relative to the entry settings object. If that failed, throw a TypeError exception.
|
||||
auto href_url = window.associated_document().parse_url(new_href);
|
||||
if (!href_url.is_valid())
|
||||
return vm.throw_completion<JS::URIError>(DeprecatedString::formatted("Invalid URL '{}'", new_href));
|
||||
return vm.throw_completion<JS::URIError>(TRY_OR_THROW_OOM(vm, String::formatted("Invalid URL '{}'", new_href)));
|
||||
|
||||
// 3. Location-object navigate given the resulting URL record.
|
||||
window.did_set_location_href({}, href_url);
|
||||
|
|
|
@ -90,7 +90,7 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors, JS::GCPtr<JS::En
|
|||
|
||||
// 5. If script's error to rethrow is not null, then set evaluationStatus to Completion { [[Type]]: throw, [[Value]]: script's error to rethrow, [[Target]]: empty }.
|
||||
if (m_error_to_rethrow.has_value()) {
|
||||
evaluation_status = vm.throw_completion<JS::SyntaxError>(m_error_to_rethrow.value().to_deprecated_string());
|
||||
evaluation_status = vm.throw_completion<JS::SyntaxError>(TRY_OR_THROW_OOM(vm, m_error_to_rethrow.value().to_string()));
|
||||
} else {
|
||||
auto timer = Core::ElapsedTimer::start_new();
|
||||
|
||||
|
|
|
@ -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().to_deprecated_string()), error_in_promise == ErrorInPromise::Yes);
|
||||
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);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#report-the-exception
|
||||
|
|
|
@ -1725,7 +1725,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::scroll)
|
|||
if (!behavior_string_value.is_undefined())
|
||||
behavior_string = TRY(behavior_string_value.to_deprecated_string(vm));
|
||||
if (behavior_string != "smooth" && behavior_string != "auto")
|
||||
return vm.throw_completion<JS::TypeError>("Behavior is not one of 'smooth' or 'auto'");
|
||||
return vm.throw_completion<JS::TypeError>("Behavior is not one of 'smooth' or 'auto'"sv);
|
||||
|
||||
} else if (vm.argument_count() >= 2) {
|
||||
// We ignore arguments 2+ in line with behavior of Chrome and Firefox
|
||||
|
@ -1788,7 +1788,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::scroll_by)
|
|||
auto behavior_string_value = TRY(options->get("behavior"));
|
||||
auto behavior_string = behavior_string_value.is_undefined() ? "auto" : TRY(behavior_string_value.to_deprecated_string(vm));
|
||||
if (behavior_string != "smooth" && behavior_string != "auto")
|
||||
return vm.throw_completion<JS::TypeError>("Behavior is not one of 'smooth' or 'auto'");
|
||||
return vm.throw_completion<JS::TypeError>("Behavior is not one of 'smooth' or 'auto'"sv);
|
||||
ScrollBehavior behavior = (behavior_string == "smooth") ? ScrollBehavior::Smooth : ScrollBehavior::Auto;
|
||||
|
||||
// FIXME: Spec wants us to call scroll(options) here.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue