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 { interface Attr {
[Constant]
readonly attribute DOMString? namespaceURI; readonly attribute DOMString? namespaceURI;
[Constant]
readonly attribute DOMString? prefix; readonly attribute DOMString? prefix;
[Constant]
readonly attribute DOMString localName; readonly attribute DOMString localName;
[Constant]
readonly attribute DOMString name; readonly attribute DOMString name;
[Pure]
attribute DOMString value; attribute DOMString value;
[Pure]
attribute DOMString textContent; // alias of .value attribute DOMString textContent; // alias of .value
[Pure]
attribute DOMString nodeValue; // alias of .value attribute DOMString nodeValue; // alias of .value
[Pure]
readonly attribute Element? ownerElement; readonly attribute Element? ownerElement;
[Constant]
readonly attribute boolean specified; // useless; always returns true readonly attribute boolean specified; // useless; always returns true
}; };

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -34,6 +34,7 @@ interface Node : EventTarget {
readonly attribute Node? parentNode; readonly attribute Node? parentNode;
[Pure] [Pure]
readonly attribute Element? parentElement; readonly attribute Element? parentElement;
[Pure]
boolean hasChildNodes(); boolean hasChildNodes();
[SameObject] [SameObject]
readonly attribute NodeList childNodes; readonly attribute NodeList childNodes;
@ -53,6 +54,7 @@ interface Node : EventTarget {
void normalize(); void normalize();
Node cloneNode(optional boolean deep = false); Node cloneNode(optional boolean deep = false);
[Pure]
boolean isEqualNode(Node? node); boolean isEqualNode(Node? node);
const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01; 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_CONTAINS = 0x08;
const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10; const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10;
const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20;
[Pure]
unsigned short compareDocumentPosition(Node other); unsigned short compareDocumentPosition(Node other);
[Pure]
boolean contains(Node? other); boolean contains(Node? other);
[Pure]
DOMString? lookupPrefix(DOMString? namespace); DOMString? lookupPrefix(DOMString? namespace);
[Pure]
DOMString? lookupNamespaceURI(DOMString? prefix); DOMString? lookupNamespaceURI(DOMString? prefix);
[Pure]
boolean isDefaultNamespace(DOMString? namespace); boolean isDefaultNamespace(DOMString? namespace);
[Throws] [Throws]

View file

@ -24,5 +24,6 @@ interface NodeIterator {
[Throws] [Throws]
Node? previousNode(); Node? previousNode();
[Pure]
void detach(); void detach();
}; };

View file

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

View file

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

View file

@ -26,7 +26,7 @@ interface ParentNode {
//Element? query(DOMString relativeSelectors); //Element? query(DOMString relativeSelectors);
//[NewObject] //[NewObject]
//Elements queryAll(DOMString relativeSelectors); //Elements queryAll(DOMString relativeSelectors);
[Throws] [Pure, Throws]
Element? querySelector(DOMString selectors); Element? querySelector(DOMString selectors);
[NewObject, Throws] [NewObject, Throws]
NodeList querySelectorAll(DOMString selectors); NodeList querySelectorAll(DOMString selectors);

View file

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

View file

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

View file

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