Decoupled DOMErrorName from legacy error codes

This commit is contained in:
Alan Jeffrey 2019-07-18 16:54:29 -05:00
parent c08ef4cb23
commit 23f15c94ef
2 changed files with 6 additions and 10 deletions

View file

@ -13,7 +13,7 @@ use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
#[repr(u16)]
#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf)]
#[derive(Clone, Copy, Debug, Eq, JSTraceable, MallocSizeOf, Ord, PartialEq, PartialOrd)]
pub enum DOMErrorName {
IndexSizeError = DOMExceptionConstants::INDEX_SIZE_ERR,
HierarchyRequestError = DOMExceptionConstants::HIERARCHY_REQUEST_ERR,
@ -36,8 +36,8 @@ pub enum DOMErrorName {
TimeoutError = DOMExceptionConstants::TIMEOUT_ERR,
InvalidNodeTypeError = DOMExceptionConstants::INVALID_NODE_TYPE_ERR,
DataCloneError = DOMExceptionConstants::DATA_CLONE_ERR,
NotReadableError = DOMExceptionConstants::NOT_READABLE_ERR,
OperationError = DOMExceptionConstants::OPERATION_ERR,
NotReadableError,
OperationError,
}
impl DOMErrorName {
@ -152,11 +152,11 @@ impl DOMException {
}
impl DOMExceptionMethods for DOMException {
// https://heycam.github.io/webidl/#dfn-DOMException
// https://heycam.github.io/webidl/#dom-domexception-code
fn Code(&self) -> u16 {
match DOMErrorName::from(&self.name) {
Some(code) => code as u16,
None => 0 as u16,
Some(code) if code <= DOMErrorName::DataCloneError => code as u16,
_ => 0,
}
}

View file

@ -38,10 +38,6 @@ interface DOMException {
const unsigned short TIMEOUT_ERR = 23;
const unsigned short INVALID_NODE_TYPE_ERR = 24;
const unsigned short DATA_CLONE_ERR = 25;
// Only the first 25 errors are given codes in
// https://heycam.github.io/webidl/#idl-DOMException
const unsigned short NOT_READABLE_ERR = 26;
const unsigned short OPERATION_ERR = 27;
// Error code as u16
readonly attribute unsigned short code;