Auto merge of #7601 - nox:cleanup-dom-webidls, r=Ms2ger

Improve DOM interfaces' extended attributes

Some should have been `[SameObject]` instead of `[Constant]`. The rest of the changes are additional `[Constant]` and `[Pure]` extended attributes on many operations.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7601)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-19 17:50:22 -06:00
commit 61267cde63
18 changed files with 75 additions and 21 deletions

View file

@ -9,15 +9,24 @@
*/
interface Attr {
[Constant]
readonly attribute DOMString? namespaceURI;
[Constant]
readonly attribute DOMString? prefix;
[Constant]
readonly attribute DOMString localName;
[Constant]
readonly attribute DOMString name;
[Pure]
attribute DOMString value;
[Pure]
attribute DOMString textContent; // alias of .value
[Pure]
attribute DOMString nodeValue; // alias of .value
[Pure]
readonly attribute Element? ownerElement;
[Constant]
readonly attribute boolean specified; // useless; always returns true
};

View file

@ -12,9 +12,9 @@
[Abstract]
interface CharacterData : Node {
[TreatNullAs=EmptyString] attribute DOMString data;
readonly attribute unsigned long length;
[Throws]
[Pure, TreatNullAs=EmptyString] attribute DOMString data;
[Pure] readonly attribute unsigned long length;
[Pure, Throws]
DOMString substringData(unsigned long offset, unsigned long count);
void appendData(DOMString data);
[Throws]

View file

@ -23,5 +23,6 @@ interface DOMImplementation {
[NewObject]
Document createHTMLDocument(optional DOMString title);
[Pure]
boolean hasFeature(); // useless, always return true
};

View file

@ -5,10 +5,12 @@
// https://dom.spec.whatwg.org/#domtokenlist
interface DOMTokenList {
[Pure]
readonly attribute unsigned long length;
[Pure]
getter DOMString? item(unsigned long index);
[Throws]
[Pure, Throws]
boolean contains(DOMString token);
[Throws]
void add(DOMString... tokens);

View file

@ -13,15 +13,20 @@
interface Document : Node {
[SameObject]
readonly attribute DOMImplementation implementation;
[Constant]
readonly attribute DOMString URL;
readonly attribute Element? activeElement;
[Constant]
readonly attribute DOMString documentURI;
readonly attribute DOMString compatMode;
readonly attribute DOMString characterSet;
readonly attribute DOMString inputEncoding; // legacy alias of .characterSet
[Constant]
readonly attribute DOMString contentType;
[Pure]
readonly attribute DocumentType? doctype;
[Pure]
readonly attribute Element? documentElement;
HTMLCollection getElementsByTagName(DOMString localName);
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);

View file

@ -11,8 +11,11 @@
*/
interface DocumentType : Node {
[Constant]
readonly attribute DOMString name;
[Constant]
readonly attribute DOMString publicId;
[Constant]
readonly attribute DOMString systemId;
};

View file

@ -14,12 +14,12 @@
*/
interface Element : Node {
readonly attribute DOMString? prefix;
readonly attribute DOMString localName;
[Constant]
readonly attribute DOMString? namespaceURI;
[Constant]
readonly attribute DOMString? prefix;
[Constant]
readonly attribute DOMString localName;
// Not [Constant] because it depends on which document we're in
[Pure]
readonly attribute DOMString tagName;
@ -28,12 +28,14 @@ interface Element : Node {
attribute DOMString id;
[Pure]
attribute DOMString className;
[Constant]
[SameObject]
readonly attribute DOMTokenList classList;
[Constant]
[SameObject]
readonly attribute NamedNodeMap attributes;
[Pure]
DOMString? getAttribute(DOMString name);
[Pure]
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
[Throws]
void setAttribute(DOMString name, DOMString value);
@ -44,10 +46,10 @@ interface Element : Node {
boolean hasAttribute(DOMString name);
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
[Throws]
[Pure, Throws]
Element? closest(DOMString selectors);
[Throws]
[Pure, Throws]
boolean matches(DOMString selectors);
HTMLCollection getElementsByTagName(DOMString localName);

View file

@ -12,6 +12,7 @@
[Constructor(DOMString type, optional EventInit eventInitDict)]
interface Event {
[Pure]
readonly attribute DOMString type;
readonly attribute EventTarget? target;
readonly attribute EventTarget? currentTarget;
@ -25,12 +26,16 @@ interface Event {
void stopPropagation();
void stopImmediatePropagation();
[Pure]
readonly attribute boolean bubbles;
[Pure]
readonly attribute boolean cancelable;
void preventDefault();
[Pure]
readonly attribute boolean defaultPrevented;
readonly attribute boolean isTrusted;
[Constant]
readonly attribute DOMTimeStamp timeStamp;
void initEvent(DOMString type, boolean bubbles, boolean cancelable);

View file

@ -6,7 +6,10 @@
// https://dom.spec.whatwg.org/#interface-htmlcollection
interface HTMLCollection {
[Pure]
readonly attribute unsigned long length;
[Pure]
getter Element? item(unsigned long index);
[Pure]
getter Element? namedItem(DOMString name);
};

View file

@ -5,9 +5,13 @@
// https://dom.spec.whatwg.org/#interface-namednodemap
interface NamedNodeMap {
[Pure]
readonly attribute unsigned long length;
[Pure]
getter Attr? item(unsigned long index);
[Pure]
getter Attr? getNamedItem(DOMString name);
[Pure]
Attr? getNamedItemNS(DOMString? namespace, DOMString localName);
//[Throws]
//Attr? setNamedItem(Attr attr);

View file

@ -35,8 +35,9 @@ interface Node : EventTarget {
readonly attribute Node? parentNode;
[Pure]
readonly attribute Element? parentElement;
[Pure]
boolean hasChildNodes();
[Constant]
[SameObject]
readonly attribute NodeList childNodes;
[Pure]
readonly attribute Node? firstChild;
@ -54,6 +55,7 @@ interface Node : EventTarget {
void normalize();
Node cloneNode(optional boolean deep = false);
[Pure]
boolean isEqualNode(Node? node);
const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01;
@ -62,11 +64,16 @@ interface Node : EventTarget {
const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08;
const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10;
const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20;
[Pure]
unsigned short compareDocumentPosition(Node other);
[Pure]
boolean contains(Node? other);
[Pure]
DOMString? lookupPrefix(DOMString? namespace);
[Pure]
DOMString? lookupNamespaceURI(DOMString? prefix);
[Pure]
boolean isDefaultNamespace(DOMString? namespace);
[Throws]

View file

@ -8,7 +8,7 @@
// Import from http://hg.mozilla.org/mozilla-central/raw-file/a5a720259d79/dom/webidl/NodeIterator.webidl
interface NodeIterator {
[Constant]
[SameObject]
readonly attribute Node root;
[Pure]
readonly attribute Node referenceNode;
@ -24,5 +24,6 @@ interface NodeIterator {
[Throws]
Node? previousNode();
[Pure]
void detach();
};

View file

@ -8,6 +8,8 @@
*/
interface NodeList {
[Pure]
readonly attribute unsigned long length;
[Pure]
getter Node? item(unsigned long index);
};

View file

@ -7,5 +7,6 @@
[NoInterfaceObject,
Exposed=Window]
interface NonElementParentNode {
[Pure]
Element? getElementById(DOMString elementId);
};

View file

@ -9,7 +9,7 @@
[NoInterfaceObject]
interface ParentNode {
[Constant]
[SameObject]
readonly attribute HTMLCollection children;
[Pure]
readonly attribute Element? firstElementChild;
@ -26,9 +26,8 @@ interface ParentNode {
//Element? query(DOMString relativeSelectors);
//[NewObject]
//Elements queryAll(DOMString relativeSelectors);
[Throws]
[Pure, Throws]
Element? querySelector(DOMString selectors);
//[NewObject]
[Throws]
[NewObject, Throws]
NodeList querySelectorAll(DOMString selectors);
};

View file

@ -8,5 +8,6 @@
*/
interface ProcessingInstruction : CharacterData {
[Constant]
readonly attribute DOMString target;
};

View file

@ -11,11 +11,17 @@
[Constructor /*, Exposed=Window */]
interface Range {
[Pure]
readonly attribute Node startContainer;
[Pure]
readonly attribute unsigned long startOffset;
[Pure]
readonly attribute Node endContainer;
[Pure]
readonly attribute unsigned long endOffset;
[Pure]
readonly attribute boolean collapsed;
[Pure]
readonly attribute Node commonAncestorContainer;
[Throws]
@ -40,7 +46,7 @@ interface Range {
const unsigned short START_TO_END = 1;
const unsigned short END_TO_END = 2;
const unsigned short END_TO_START = 3;
[Throws]
[Pure, Throws]
short compareBoundaryPoints(unsigned short how, Range sourceRange);
// [Throws]
// void deleteContents();
@ -55,13 +61,15 @@ interface Range {
[NewObject]
Range cloneRange();
[Pure]
void detach();
[Throws]
[Pure, Throws]
boolean isPointInRange(Node node, unsigned long offset);
[Throws]
[Pure, Throws]
short comparePoint(Node node, unsigned long offset);
[Pure]
boolean intersectsNode(Node node);
// stringifier;

View file

@ -15,5 +15,6 @@
interface Text : CharacterData {
[NewObject, Throws]
Text splitText(unsigned long offset);
[Pure]
readonly attribute DOMString wholeText;
};