implemented missed constructor for DOMException; fixed the tests expectations

This commit is contained in:
cdeler 2019-01-05 22:20:25 +03:00
parent 34fda66dfa
commit 220a471b14
5 changed files with 95 additions and 520 deletions

View file

@ -5,6 +5,7 @@
use crate::dom::bindings::codegen::Bindings::DOMExceptionBinding;
use crate::dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionConstants;
use crate::dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionMethods;
use crate::dom::bindings::error::Error;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
@ -38,43 +39,46 @@ pub enum DOMErrorName {
NotReadableError = DOMExceptionConstants::NOT_READABLE_ERR,
}
impl DOMErrorName {
pub fn from(s: &DOMString) -> Option<DOMErrorName> {
match s.as_ref() {
"IndexSizeError" => Some(DOMErrorName::IndexSizeError),
"HierarchyRequestError" => Some(DOMErrorName::HierarchyRequestError),
"WrongDocumentError" => Some(DOMErrorName::WrongDocumentError),
"InvalidCharacterError" => Some(DOMErrorName::InvalidCharacterError),
"NoModificationAllowedError" => Some(DOMErrorName::NoModificationAllowedError),
"NotFoundError" => Some(DOMErrorName::NotFoundError),
"NotSupportedError" => Some(DOMErrorName::NotSupportedError),
"InUseAttributeError" => Some(DOMErrorName::InUseAttributeError),
"InvalidStateError" => Some(DOMErrorName::InvalidStateError),
"SyntaxError" => Some(DOMErrorName::SyntaxError),
"InvalidModificationError" => Some(DOMErrorName::InvalidModificationError),
"NamespaceError" => Some(DOMErrorName::NamespaceError),
"InvalidAccessError" => Some(DOMErrorName::InvalidAccessError),
"SecurityError" => Some(DOMErrorName::SecurityError),
"NetworkError" => Some(DOMErrorName::NetworkError),
"AbortError" => Some(DOMErrorName::AbortError),
"TypeMismatchError" => Some(DOMErrorName::TypeMismatchError),
"QuotaExceededError" => Some(DOMErrorName::QuotaExceededError),
"TimeoutError" => Some(DOMErrorName::TimeoutError),
"InvalidNodeTypeError" => Some(DOMErrorName::InvalidNodeTypeError),
"DataCloneError" => Some(DOMErrorName::DataCloneError),
"NotReadableError" => Some(DOMErrorName::NotReadableError),
_ => None,
}
}
}
#[dom_struct]
pub struct DOMException {
reflector_: Reflector,
code: DOMErrorName,
message: DOMString,
name: DOMString,
}
impl DOMException {
fn new_inherited(code: DOMErrorName) -> DOMException {
DOMException {
reflector_: Reflector::new(),
code: code,
}
}
pub fn new(global: &GlobalScope, code: DOMErrorName) -> DomRoot<DOMException> {
reflect_dom_object(
Box::new(DOMException::new_inherited(code)),
global,
DOMExceptionBinding::Wrap,
)
}
}
impl DOMExceptionMethods for DOMException {
// https://heycam.github.io/webidl/#dfn-DOMException
fn Code(&self) -> u16 {
self.code as u16
}
// https://heycam.github.io/webidl/#idl-DOMException-error-names
fn Name(&self) -> DOMString {
DOMString::from(format!("{:?}", self.code))
}
// https://heycam.github.io/webidl/#error-names
fn Message(&self) -> DOMString {
let message = match self.code {
fn get_error_data_by_code(code: DOMErrorName) -> (DOMString, DOMString) {
let message = match &code {
DOMErrorName::IndexSizeError => "The index is not in the allowed range.",
DOMErrorName::HierarchyRequestError => {
"The operation would yield an incorrect node tree."
@ -105,11 +109,64 @@ impl DOMExceptionMethods for DOMException {
DOMErrorName::NotReadableError => "The I/O read operation failed.",
};
DOMString::from(message)
(
DOMString::from(message),
DOMString::from(format!("{:?}", code)),
)
}
fn new_inherited(message_: DOMString, name_: DOMString) -> DOMException {
DOMException {
reflector_: Reflector::new(),
message: message_,
name: name_,
}
}
pub fn new(global: &GlobalScope, code: DOMErrorName) -> DomRoot<DOMException> {
let (message, name) = DOMException::get_error_data_by_code(code);
reflect_dom_object(
Box::new(DOMException::new_inherited(message, name)),
global,
DOMExceptionBinding::Wrap,
)
}
pub fn Constructor(
global: &GlobalScope,
message: DOMString,
name: DOMString,
) -> Result<DomRoot<DOMException>, Error> {
Ok(reflect_dom_object(
Box::new(DOMException::new_inherited(message, name)),
global,
DOMExceptionBinding::Wrap,
))
}
}
impl DOMExceptionMethods for DOMException {
// https://heycam.github.io/webidl/#dfn-DOMException
fn Code(&self) -> u16 {
match DOMErrorName::from(&self.name) {
Some(code) => code as u16,
None => 0 as u16,
}
}
// https://heycam.github.io/webidl/#idl-DOMException-error-names
fn Name(&self) -> DOMString {
self.name.clone()
}
// https://heycam.github.io/webidl/#error-names
fn Message(&self) -> DOMString {
self.message.clone()
}
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-error.prototype.tostring
fn Stringifier(&self) -> DOMString {
DOMString::from(format!("{}: {}", self.Name(), self.Message()))
DOMString::from(format!("{}: {}", self.name, self.message))
}
}

View file

@ -7,7 +7,11 @@
* https://heycam.github.io/webidl/#es-DOMException-constructor-object
*/
[ExceptionClass, Exposed=(Window,Worker)]
[
ExceptionClass,
Exposed=(Window,Worker),
Constructor(optional DOMString message="", optional DOMString name="Error")
]
interface DOMException {
const unsigned short INDEX_SIZE_ERR = 1;
const unsigned short DOMSTRING_SIZE_ERR = 2; // historical

View file

@ -1,197 +1,11 @@
[DOMException-constructor-behavior.any.worker.html]
type: testharness
[new DOMException()]
expected: FAIL
[new DOMException(): inherited-ness]
expected: FAIL
[new DOMException(null)]
expected: FAIL
[new DOMException(undefined)]
expected: FAIL
[new DOMException(undefined): inherited-ness]
expected: FAIL
[new DOMException("foo")]
expected: FAIL
[new DOMException("foo"): inherited-ness]
expected: FAIL
[new DOMException("bar", undefined)]
expected: FAIL
[new DOMException("bar", "NotSupportedError")]
expected: FAIL
[new DOMException("bar", "NotSupportedError"): inherited-ness]
expected: FAIL
[new DOMException("bar", "foo")]
expected: FAIL
[new DOMexception("msg", "IndexSizeError")]
expected: FAIL
[new DOMexception("msg", "HierarchyRequestError")]
expected: FAIL
[new DOMexception("msg", "WrongDocumentError")]
expected: FAIL
[new DOMexception("msg", "InvalidCharacterError")]
expected: FAIL
[new DOMexception("msg", "NoModificationAllowedError")]
expected: FAIL
[new DOMexception("msg", "NotFoundError")]
expected: FAIL
[new DOMexception("msg", "NotSupportedError")]
expected: FAIL
[new DOMexception("msg", "InUseAttributeError")]
expected: FAIL
[new DOMexception("msg", "InvalidStateError")]
expected: FAIL
[new DOMexception("msg", "SyntaxError")]
expected: FAIL
[new DOMexception("msg", "InvalidModificationError")]
expected: FAIL
[new DOMexception("msg", "NamespaceError")]
expected: FAIL
[new DOMexception("msg", "InvalidAccessError")]
expected: FAIL
[new DOMexception("msg", "SecurityError")]
expected: FAIL
[new DOMexception("msg", "NetworkError")]
expected: FAIL
[new DOMexception("msg", "AbortError")]
expected: FAIL
[new DOMexception("msg", "URLMismatchError")]
expected: FAIL
[new DOMexception("msg", "QuotaExceededError")]
expected: FAIL
[new DOMexception("msg", "TimeoutError")]
expected: FAIL
[new DOMexception("msg", "InvalidNodeTypeError")]
expected: FAIL
[new DOMexception("msg", "DataCloneError")]
expected: FAIL
[DOMException-constructor-behavior.any.html]
type: testharness
[new DOMException()]
expected: FAIL
[new DOMException(): inherited-ness]
expected: FAIL
[new DOMException(null)]
expected: FAIL
[new DOMException(undefined)]
expected: FAIL
[new DOMException(undefined): inherited-ness]
expected: FAIL
[new DOMException("foo")]
expected: FAIL
[new DOMException("foo"): inherited-ness]
expected: FAIL
[new DOMException("bar", undefined)]
expected: FAIL
[new DOMException("bar", "NotSupportedError")]
expected: FAIL
[new DOMException("bar", "NotSupportedError"): inherited-ness]
expected: FAIL
[new DOMException("bar", "foo")]
expected: FAIL
[new DOMexception("msg", "IndexSizeError")]
expected: FAIL
[new DOMexception("msg", "HierarchyRequestError")]
expected: FAIL
[new DOMexception("msg", "WrongDocumentError")]
expected: FAIL
[new DOMexception("msg", "InvalidCharacterError")]
expected: FAIL
[new DOMexception("msg", "NoModificationAllowedError")]
expected: FAIL
[new DOMexception("msg", "NotFoundError")]
expected: FAIL
[new DOMexception("msg", "NotSupportedError")]
expected: FAIL
[new DOMexception("msg", "InUseAttributeError")]
expected: FAIL
[new DOMexception("msg", "InvalidStateError")]
expected: FAIL
[new DOMexception("msg", "SyntaxError")]
expected: FAIL
[new DOMexception("msg", "InvalidModificationError")]
expected: FAIL
[new DOMexception("msg", "NamespaceError")]
expected: FAIL
[new DOMexception("msg", "InvalidAccessError")]
expected: FAIL
[new DOMexception("msg", "SecurityError")]
expected: FAIL
[new DOMexception("msg", "NetworkError")]
expected: FAIL
[new DOMexception("msg", "AbortError")]
expected: FAIL
[new DOMexception("msg", "URLMismatchError")]
expected: FAIL
[new DOMexception("msg", "QuotaExceededError")]
expected: FAIL
[new DOMexception("msg", "TimeoutError")]
expected: FAIL
[new DOMexception("msg", "InvalidNodeTypeError")]
expected: FAIL
[new DOMexception("msg", "DataCloneError")]
expected: FAIL

View file

@ -1,20 +1,5 @@
[DOMException-custom-bindings.any.worker.html]
type: testharness
[message property descriptor]
expected: FAIL
[name property descriptor]
expected: FAIL
[code property descriptor]
expected: FAIL
[code property is not affected by shadowing the name property]
expected: FAIL
[Object.prototype.toString behavior is like other interfaces]
expected: FAIL
[Inherits its toString() from Error.prototype]
expected: FAIL
@ -24,21 +9,6 @@
[DOMException-custom-bindings.any.html]
type: testharness
[message property descriptor]
expected: FAIL
[name property descriptor]
expected: FAIL
[code property descriptor]
expected: FAIL
[code property is not affected by shadowing the name property]
expected: FAIL
[Object.prototype.toString behavior is like other interfaces]
expected: FAIL
[Inherits its toString() from Error.prototype]
expected: FAIL

View file

@ -1,275 +1,5 @@
[interfaces.html]
type: testharness
[DOMException must be primary interface of new DOMException()]
expected: FAIL
[Stringification of new DOMException()]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "name" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "message" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "code" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "INDEX_SIZE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "DOMSTRING_SIZE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "HIERARCHY_REQUEST_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "WRONG_DOCUMENT_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "INVALID_CHARACTER_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "NO_DATA_ALLOWED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "NO_MODIFICATION_ALLOWED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "NOT_FOUND_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "NOT_SUPPORTED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "INUSE_ATTRIBUTE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "INVALID_STATE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "SYNTAX_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "INVALID_MODIFICATION_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "NAMESPACE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "INVALID_ACCESS_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "VALIDATION_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "TYPE_MISMATCH_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "SECURITY_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "NETWORK_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "ABORT_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "URL_MISMATCH_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "QUOTA_EXCEEDED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "TIMEOUT_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "INVALID_NODE_TYPE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException() must inherit property "DATA_CLONE_ERR" with the proper type]
expected: FAIL
[DOMException must be primary interface of new DOMException("my message")]
expected: FAIL
[Stringification of new DOMException("my message")]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "name" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "message" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "code" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "INDEX_SIZE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "DOMSTRING_SIZE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "HIERARCHY_REQUEST_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "WRONG_DOCUMENT_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "INVALID_CHARACTER_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "NO_DATA_ALLOWED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "NO_MODIFICATION_ALLOWED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "NOT_FOUND_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "NOT_SUPPORTED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "INUSE_ATTRIBUTE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "INVALID_STATE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "SYNTAX_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "INVALID_MODIFICATION_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "NAMESPACE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "INVALID_ACCESS_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "VALIDATION_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "TYPE_MISMATCH_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "SECURITY_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "NETWORK_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "ABORT_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "URL_MISMATCH_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "QUOTA_EXCEEDED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "TIMEOUT_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "INVALID_NODE_TYPE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message") must inherit property "DATA_CLONE_ERR" with the proper type]
expected: FAIL
[DOMException must be primary interface of new DOMException("my message", "myName")]
expected: FAIL
[Stringification of new DOMException("my message", "myName")]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "name" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "message" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "code" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "INDEX_SIZE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "DOMSTRING_SIZE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "HIERARCHY_REQUEST_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "WRONG_DOCUMENT_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "INVALID_CHARACTER_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "NO_DATA_ALLOWED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "NO_MODIFICATION_ALLOWED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "NOT_FOUND_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "NOT_SUPPORTED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "INUSE_ATTRIBUTE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "INVALID_STATE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "SYNTAX_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "INVALID_MODIFICATION_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "NAMESPACE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "INVALID_ACCESS_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "VALIDATION_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "TYPE_MISMATCH_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "SECURITY_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "NETWORK_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "ABORT_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "URL_MISMATCH_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "QUOTA_EXCEEDED_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "TIMEOUT_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "INVALID_NODE_TYPE_ERR" with the proper type]
expected: FAIL
[DOMException interface: new DOMException("my message", "myName") must inherit property "DATA_CLONE_ERR" with the proper type]
expected: FAIL
[WebIDL IDL tests]
expected: FAIL