From 5f1d3c93749513d3a8214d6da270550bcec19cde Mon Sep 17 00:00:00 2001 From: Christian Bewernitz Date: Sun, 17 Jan 2021 22:22:56 +0100 Subject: [PATCH] docs: Describe and use exported `DOMException` error code constants --- readme.md | 41 ++++++++++++++++++++++++----------------- test/dom/attr.test.js | 4 ++-- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/readme.md b/readme.md index d38c51156..b0a9072f7 100644 --- a/readme.md +++ b/readme.md @@ -98,23 +98,30 @@ DOM level2 method and attribute: normalize() isSupported(feature, version) hasAttributes() - * [DOMException](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html) - * used as the Error type thrown as part of DOM API: - 1. Index size error - 2. DOMString size error - 3. Hierarchy request error - 4. Wrong document - 5. Invalid character - 6. No data allowed - 7. No modification allowed - 8. Not found - 9. Not supported - 10. Attribute in use - 11. Invalid state - 12. Syntax error - 13. Invalid modification - 14. Invalid namespace - 15. Invalid access +* [DOMException](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html) + The DOMException class has the following constants (and `value` of type `Number`): + + 1. `DOMException.INDEX_SIZE_ERR` (`1`) + 1. `DOMException.DOMSTRING_SIZE_ERR` (`2`) + 1. `DOMException.HIERARCHY_REQUEST_ERR` (`3`) + 1. `DOMException.WRONG_DOCUMENT_ERR` (`4`) + 1. `DOMException.INVALID_CHARACTER_ERR` (`5`) + 1. `DOMException.NO_DATA_ALLOWED_ERR` (`6`) + 1. `DOMException.NO_MODIFICATION_ALLOWED_ERR` (`7`) + 1. `DOMException.NOT_FOUND_ERR` (`8`) + 1. `DOMException.NOT_SUPPORTED_ERR` (`9`) + 1. `DOMException.INUSE_ATTRIBUTE_ERR` (`10`) + 1. `DOMException.INVALID_STATE_ERR` (`11`) + 1. `DOMException.SYNTAX_ERR` (`12`) + 1. `DOMException.INVALID_MODIFICATION_ERR` (`13`) + 1. `DOMException.NAMESPACE_ERR` (`14`) + 1. `DOMException.INVALID_ACCESS_ERR` (`15`) + + The DOMException object has the following properties: + code + This property is of type Number. + + * extends the Error type thrown as part of DOM API: * [DOMImplementation](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-102161490) diff --git a/test/dom/attr.test.js b/test/dom/attr.test.js index d24337cb1..03766727a 100644 --- a/test/dom/attr.test.js +++ b/test/dom/attr.test.js @@ -18,7 +18,7 @@ describe('XML attrs', () => { const c = root.ownerDocument.createElement('c') expect(() => { c.setAttributeNode(root.attributes.item(0)) - }).toThrow(new DOMException(10)) + }).toThrow(new DOMException(DOMException.INUSE_ATTRIBUTE_ERR)) }) it('can properly set ns attribute', () => { @@ -39,7 +39,7 @@ describe('XML attrs', () => { const c = root.ownerDocument.createElement('c') expect(() => { c.setAttributeNodeNS(root.attributes.item(0)) - }).toThrow(new DOMException(10)) + }).toThrow(new DOMException(DOMException.INUSE_ATTRIBUTE_ERR)) }) it('can properly override attribute', () => {