Skip to content

Commit 1c24269

Browse files
authored
Adding message argument in WrongDocument Error (servo#39773)
*This pull request address one of the action item of [*Provide messages in JS errors*](servo#39053) i.e. it adds message argument in WrongDocument Error * Testing: *This PR is tested using CLI ./mach test-unit -p libservo --jobs=3* Fixes: [*Provide messages in JS errors*](servo#39053) --------- Signed-off-by: Ankur Gupta <[email protected]>
1 parent e3aaf74 commit 1c24269

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

components/script/dom/bindings/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ pub(crate) fn create_dom_exception(
118118
},
119119
Error::NotFound(None) => DOMErrorName::NotFoundError,
120120
Error::HierarchyRequest => DOMErrorName::HierarchyRequestError,
121-
Error::WrongDocument => DOMErrorName::WrongDocumentError,
121+
Error::WrongDocument(Some(doc_err_custom_message)) => {
122+
return new_custom_exception(DOMErrorName::WrongDocumentError, doc_err_custom_message);
123+
},
124+
Error::WrongDocument(None) => DOMErrorName::WrongDocumentError,
122125
Error::InvalidCharacter => DOMErrorName::InvalidCharacterError,
123126
Error::NotSupported => DOMErrorName::NotSupportedError,
124127
Error::InUseAttribute => DOMErrorName::InUseAttributeError,

components/script/dom/range.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl Range {
252252
.unwrap();
253253
if start_node_root != node_root {
254254
// Step 1.
255-
return Err(Error::WrongDocument);
255+
return Err(Error::WrongDocument(None));
256256
}
257257
if node.is_doctype() {
258258
// Step 2.
@@ -505,7 +505,7 @@ impl RangeMethods<crate::DomTypeHolder> for Range {
505505
.unwrap();
506506
if this_root != other_root {
507507
// Step 2.
508-
return Err(Error::WrongDocument);
508+
return Err(Error::WrongDocument(None));
509509
}
510510
// Step 3.
511511
let (this_point, other_point) = match how {
@@ -543,7 +543,7 @@ impl RangeMethods<crate::DomTypeHolder> for Range {
543543
Ok(Ordering::Less) => Ok(false),
544544
Ok(Ordering::Equal) => Ok(true),
545545
Ok(Ordering::Greater) => Ok(false),
546-
Err(Error::WrongDocument) => {
546+
Err(Error::WrongDocument(None)) => {
547547
// Step 2.
548548
Ok(false)
549549
},

components/script_bindings/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum Error {
2020
/// HierarchyRequestError DOMException
2121
HierarchyRequest,
2222
/// WrongDocumentError DOMException
23-
WrongDocument,
23+
WrongDocument(Option<String>),
2424
/// InvalidCharacterError DOMException
2525
InvalidCharacter,
2626
/// NotSupportedError DOMException

0 commit comments

Comments
 (0)