mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Auto merge of #5490 - nox:namednodemap, r=jdm
This commit is contained in:
commit
e521860a0e
5 changed files with 46 additions and 7 deletions
|
@ -34,6 +34,8 @@ pub enum Error {
|
|||
InvalidCharacter,
|
||||
/// NotSupportedError DOMException
|
||||
NotSupported,
|
||||
/// InUseAttributeError DOMException
|
||||
InUseAttribute,
|
||||
/// InvalidStateError DOMException
|
||||
InvalidState,
|
||||
/// SyntaxError DOMException
|
||||
|
@ -79,6 +81,7 @@ pub fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef,
|
|||
Error::HierarchyRequest => DOMErrorName::HierarchyRequestError,
|
||||
Error::InvalidCharacter => DOMErrorName::InvalidCharacterError,
|
||||
Error::NotSupported => DOMErrorName::NotSupportedError,
|
||||
Error::InUseAttribute => DOMErrorName::InUseAttributeError,
|
||||
Error::InvalidState => DOMErrorName::InvalidStateError,
|
||||
Error::Syntax => DOMErrorName::SyntaxError,
|
||||
Error::Namespace => DOMErrorName::NamespaceError,
|
||||
|
|
|
@ -23,6 +23,7 @@ pub enum DOMErrorName {
|
|||
NoModificationAllowedError = DOMExceptionConstants::NO_MODIFICATION_ALLOWED_ERR,
|
||||
NotFoundError = DOMExceptionConstants::NOT_FOUND_ERR,
|
||||
NotSupportedError = DOMExceptionConstants::NOT_SUPPORTED_ERR,
|
||||
InUseAttributeError = DOMExceptionConstants::INUSE_ATTRIBUTE_ERR,
|
||||
InvalidStateError = DOMExceptionConstants::INVALID_STATE_ERR,
|
||||
SyntaxError = DOMExceptionConstants::SYNTAX_ERR,
|
||||
InvalidModificationError = DOMExceptionConstants::INVALID_MODIFICATION_ERR,
|
||||
|
@ -83,6 +84,7 @@ impl<'a> DOMExceptionMethods for JSRef<'a, DOMException> {
|
|||
DOMErrorName::NoModificationAllowedError => "The object can not be modified.",
|
||||
DOMErrorName::NotFoundError => "The object can not be found here.",
|
||||
DOMErrorName::NotSupportedError => "The operation is not supported.",
|
||||
DOMErrorName::InUseAttributeError => "The attribute already in use.",
|
||||
DOMErrorName::InvalidStateError => "The object is in an invalid state.",
|
||||
DOMErrorName::SyntaxError => "The string did not match the expected pattern.",
|
||||
DOMErrorName::InvalidModificationError => "The object can not be modified in this way.",
|
||||
|
|
|
@ -8,8 +8,12 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
|
|||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::element::{Element, ElementHelpers};
|
||||
use dom::element::{AttributeHandlers, Element, ElementHelpers};
|
||||
use dom::window::Window;
|
||||
use util::namespace;
|
||||
use util::str::DOMString;
|
||||
|
||||
use string_cache::Atom;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct NamedNodeMap {
|
||||
|
@ -32,6 +36,7 @@ impl NamedNodeMap {
|
|||
}
|
||||
|
||||
impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
|
||||
// https://dom.spec.whatwg.org/#dom-namednodemap-length
|
||||
fn Length(self) -> u32 {
|
||||
let owner = self.owner.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
|
@ -40,6 +45,7 @@ impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
|
|||
attrs.len() as u32
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-namednodemap-item
|
||||
fn Item(self, index: u32) -> Option<Temporary<Attr>> {
|
||||
let owner = self.owner.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
|
@ -48,10 +54,34 @@ impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
|
|||
attrs.as_slice().get(index as usize).map(|x| Temporary::new(x.clone()))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditem
|
||||
fn GetNamedItem(self, name: DOMString) -> Option<Temporary<Attr>> {
|
||||
let owner = self.owner.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let owner = owner.r();
|
||||
let name = owner.parsed_name(name);
|
||||
owner.get_attribute_by_name(&Atom::from_slice(&name))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditemns
|
||||
fn GetNamedItemNS(self, namespace: Option<DOMString>, name: DOMString) -> Option<Temporary<Attr>> {
|
||||
let owner = self.owner.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let owner = owner.r();
|
||||
let ns = namespace::from_domstring(namespace);
|
||||
owner.get_attribute(&ns, &Atom::from_slice(&name))
|
||||
}
|
||||
|
||||
fn IndexedGetter(self, index: u32, found: &mut bool) -> Option<Temporary<Attr>> {
|
||||
let item = self.Item(index);
|
||||
*found = item.is_some();
|
||||
item
|
||||
}
|
||||
|
||||
fn NamedGetter(self, name: DOMString, found: &mut bool) -> Option<Temporary<Attr>> {
|
||||
let item = self.GetNamedItem(name);
|
||||
*found = item.is_some();
|
||||
item
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,4 +5,14 @@
|
|||
interface NamedNodeMap {
|
||||
readonly attribute unsigned long length;
|
||||
getter Attr? item(unsigned long index);
|
||||
getter Attr? getNamedItem(DOMString name);
|
||||
Attr? getNamedItemNS(DOMString? namespace, DOMString localName);
|
||||
//[Throws]
|
||||
//Attr? setNamedItem(Attr attr);
|
||||
//[Throws]
|
||||
//Attr? setNamedItemNS(Attr attr);
|
||||
//[Throws]
|
||||
//Attr removeNamedItem(DOMString name);
|
||||
//[Throws]
|
||||
//Attr removeNamedItemNS(DOMString? namespace, DOMString name);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue