mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #10762 - canaltinova:has_attributes, r=nox
Implement Element::hasAttributes Fixes #10748 . Implement Element::hasAttributes. I'm not sure if tests are enough. I'm open to suggestion :) <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10762) <!-- Reviewable:end -->
This commit is contained in:
commit
8163347e34
6 changed files with 55 additions and 9 deletions
|
@ -1335,6 +1335,11 @@ impl ElementMethods for Element {
|
|||
self.attr_list.or_init(|| NamedNodeMap::new(&window_from_node(self), self))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-hasattributes
|
||||
fn HasAttributes(&self) -> bool {
|
||||
!self.attrs.borrow().is_empty()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-getattributenames
|
||||
fn GetAttributeNames(&self) -> Vec<DOMString> {
|
||||
self.attrs.borrow().iter().map(|attr| attr.Name()).collect()
|
||||
|
|
|
@ -35,6 +35,8 @@ interface Element : Node {
|
|||
[Pure]
|
||||
sequence<DOMString> getAttributeNames();
|
||||
[Pure]
|
||||
boolean hasAttributes();
|
||||
[Pure]
|
||||
DOMString? getAttribute(DOMString name);
|
||||
[Pure]
|
||||
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
|
||||
|
|
|
@ -35228,6 +35228,14 @@
|
|||
"url": "/html/rendering/replaced-elements/embedded-content-rendering-rules/canvas_scale.html"
|
||||
}
|
||||
]
|
||||
},
|
||||
"testharness": {
|
||||
"dom/nodes/Element-hasAttributes.html": [
|
||||
{
|
||||
"path": "dom/nodes/Element-hasAttributes.html",
|
||||
"url": "/dom/nodes/Element-hasAttributes.html"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"reftest_nodes": {
|
||||
|
|
|
@ -102,9 +102,6 @@
|
|||
[DocumentFragment interface: calling queryAll(DOMString) on document.createDocumentFragment() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[Element interface: operation hasAttributes()]
|
||||
expected: FAIL
|
||||
|
||||
[Element interface: operation query(DOMString)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -264,9 +261,6 @@
|
|||
[Element interface: element must inherit property "slot" with the proper type (7)]
|
||||
expected: FAIL
|
||||
|
||||
[Element interface: element must inherit property "hasAttributes" with the proper type (8)]
|
||||
expected: FAIL
|
||||
|
||||
[Element interface: element must inherit property "attachShadow" with the proper type (24)]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1956,9 +1956,6 @@
|
|||
[HTMLElement interface: document.createElement("noscript") must inherit property "onwaiting" with the proper type (94)]
|
||||
expected: FAIL
|
||||
|
||||
[Element interface: document.createElement("noscript") must inherit property "hasAttributes" with the proper type (7)]
|
||||
expected: FAIL
|
||||
|
||||
[Element interface: document.createElement("noscript") must inherit property "query" with the proper type (34)]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
|
||||
<button></button>
|
||||
<div id="foo"></div>
|
||||
<p data-foo=""></p>
|
||||
|
||||
<script>
|
||||
test(function() {
|
||||
var buttonElement = document.getElementsByTagName('button')[0];
|
||||
assert_equals(buttonElement.hasAttributes(), false, 'hasAttributes() on empty element must return false.');
|
||||
|
||||
var emptyDiv = document.createElement('div');
|
||||
assert_equals(emptyDiv.hasAttributes(), false, 'hasAttributes() on dynamically created empty element must return false.');
|
||||
|
||||
}, 'element.hasAttributes() must return false when the element does not have attribute.');
|
||||
|
||||
test(function() {
|
||||
var divWithId = document.getElementById('foo');
|
||||
assert_equals(divWithId.hasAttributes(), true, 'hasAttributes() on element with id attribute must return true.');
|
||||
|
||||
var divWithClass = document.createElement('div');
|
||||
divWithClass.setAttribute('class', 'foo');
|
||||
assert_equals(divWithClass.hasAttributes(), true, 'hasAttributes() on dynamically created element with class attribute must return true.');
|
||||
|
||||
var pWithCustomAttr = document.getElementsByTagName('p')[0];
|
||||
assert_equals(pWithCustomAttr.hasAttributes(), true, 'hasAttributes() on element with custom attribute must return true.');
|
||||
|
||||
var divWithCustomAttr = document.createElement('div');
|
||||
divWithCustomAttr.setAttribute('data-custom', 'foo');
|
||||
assert_equals(divWithCustomAttr.hasAttributes(), true, 'hasAttributes() on dynamically created element with custom attribute must return true.');
|
||||
|
||||
}, 'element.hasAttributes() must return true when the element has attribute.');
|
||||
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue