script: Add message to NotFoundError (#39394)

Adding an optional message to be attached to a NotFoundError.

Testing: Just a refactor
Part of #39053

---------

Signed-off-by: Rodion Borovyk <rodion.borovyk@gmail.com>
This commit is contained in:
Rodion Borovyk 2025-09-25 14:16:50 +02:00 committed by GitHub
parent ffdb7d3663
commit 9713bb9e1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 37 additions and 38 deletions

View file

@ -99,9 +99,18 @@ pub(crate) fn create_dom_exception(
result: Error,
can_gc: CanGc,
) -> Result<DomRoot<DOMException>, JsEngineError> {
let new_custom_exception = |error_name, message| {
Ok(DOMException::new_with_custom_message(
global, error_name, message, can_gc,
))
};
let code = match result {
Error::IndexSize => DOMErrorName::IndexSizeError,
Error::NotFound => DOMErrorName::NotFoundError,
Error::NotFound(Some(custom_message)) => {
return new_custom_exception(DOMErrorName::NotFoundError, custom_message);
},
Error::NotFound(None) => DOMErrorName::NotFoundError,
Error::HierarchyRequest => DOMErrorName::HierarchyRequestError,
Error::WrongDocument => DOMErrorName::WrongDocumentError,
Error::InvalidCharacter => DOMErrorName::InvalidCharacterError,
@ -109,12 +118,7 @@ pub(crate) fn create_dom_exception(
Error::InUseAttribute => DOMErrorName::InUseAttributeError,
Error::InvalidState => DOMErrorName::InvalidStateError,
Error::Syntax(Some(custom_message)) => {
return Ok(DOMException::new_with_custom_message(
global,
DOMErrorName::SyntaxError,
custom_message,
can_gc,
));
return new_custom_exception(DOMErrorName::SyntaxError, custom_message);
},
Error::Syntax(None) => DOMErrorName::SyntaxError,
Error::Namespace => DOMErrorName::NamespaceError,
@ -125,12 +129,7 @@ pub(crate) fn create_dom_exception(
Error::Timeout => DOMErrorName::TimeoutError,
Error::InvalidNodeType => DOMErrorName::InvalidNodeTypeError,
Error::DataClone(Some(custom_message)) => {
return Ok(DOMException::new_with_custom_message(
global,
DOMErrorName::DataCloneError,
custom_message,
can_gc,
));
return new_custom_exception(DOMErrorName::DataCloneError, custom_message);
},
Error::DataClone(None) => DOMErrorName::DataCloneError,
Error::Data => DOMErrorName::DataError,