Annotate many DOM attribute and methods with [Constant] and [Pure]

This commit is contained in:
Anthony Ramine 2015-09-11 02:51:51 +02:00
parent 4dbf391e83
commit 49219baab8
18 changed files with 69 additions and 14 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

@ -11,9 +11,9 @@
*/
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;
@ -33,7 +33,9 @@ interface Element : Node {
[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

@ -34,6 +34,7 @@ interface Node : EventTarget {
readonly attribute Node? parentNode;
[Pure]
readonly attribute Element? parentElement;
[Pure]
boolean hasChildNodes();
[SameObject]
readonly attribute NodeList childNodes;
@ -53,6 +54,7 @@ interface Node : EventTarget {
void normalize();
Node cloneNode(optional boolean deep = false);
[Pure]
boolean isEqualNode(Node? node);
const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01;
@ -61,11 +63,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

@ -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

@ -26,7 +26,7 @@ interface ParentNode {
//Element? query(DOMString relativeSelectors);
//[NewObject]
//Elements queryAll(DOMString relativeSelectors);
[Throws]
[Pure, Throws]
Element? querySelector(DOMString selectors);
[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;
};