Table of contents
    1. 2.8 Common DOM interfaces
      1. 2.8.1 Reflecting content attributes in IDL attributes
      2. 2.8.2 Collections
        1. 2.8.2.1 HTMLCollection
        2. 2.8.2.2 HTMLAllCollection
        3. 2.8.2.3 HTMLFormControlsCollection
        4. 2.8.2.4 HTMLOptionsCollection
      3. 2.8.3 DOMTokenList
      4. 2.8.4 DOMSettableTokenList
      5. 2.8.5 Safe passing of structured data
      6. 2.8.6 DOMStringMap
      7. 2.8.7 DOM feature strings
      8. 2.8.8 Exceptions
      9. 2.8.9 Garbage collection

2.8 Common DOM interfaces

2.8.1 Reflecting content attributes in IDL attributes

Some IDL attributes are defined to reflect a particular content attribute. This means that on getting, the IDL attribute returns the current value of the content attribute, and on setting, the IDL attribute changes the value of the content attribute to the given value.

In general, on getting, if the content attribute is not present, the IDL attribute must act as if the content attribute's value is the empty string; and on setting, if the content attribute is not present, it must first be added.

If a reflecting IDL attribute is a DOMString attribute whose content attribute is defined to contain a URL, then on getting, the IDL attribute must resolve the value of the content attribute relative to the element and return the resulting absolute URL if that was successful, or the empty string otherwise; and on setting, must set the content attribute to the specified literal value. If the content attribute is absent, the IDL attribute must return the default value, if the content attribute has one, or else the empty string.

If a reflecting IDL attribute is a DOMString attribute whose content attribute is defined to contain one or more URLs, then on getting, the IDL attribute must split the content attribute on spaces and return the concatenation of resolving each token URL to an absolute URL relative to the element, with a single U+0020 SPACE character between each URL, ignoring any tokens that did not resolve successfully. If the content attribute is absent, the IDL attribute must return the default value, if the content attribute has one, or else the empty string. On setting, the IDL attribute must set the content attribute to the specified literal value.

If a reflecting IDL attribute is a DOMString attribute whose content attribute is an enumerated attribute, and the IDL attribute is limited to only known values, then, on getting, the IDL attribute must return the conforming value associated with the state the attribute is in (in its canonical case), or the empty string if the attribute is in a state that has no associated keyword value; and on setting, the content attribute must be set to the specified new value.

If a reflecting IDL attribute is a DOMString attribute but doesn't fall into any of the above categories, then the getting and setting must be done in a transparent, case-preserving manner.

If a reflecting IDL attribute is a boolean attribute, then on getting the IDL attribute must return true if the content attribute is set, and false if it is absent. On setting, the content attribute must be removed if the IDL attribute is set to false, and must be set to the empty string if the IDL attribute is set to true. (This corresponds to the rules for boolean content attributes.)

If a reflecting IDL attribute has a signed integer type (long) then, on getting, the content attribute must be parsed according to the rules for parsing signed integers, and if that is successful, and the value is in the range of the IDL attribute's type, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, then the default value must be returned instead, or 0 if there is no default value. On setting, the given value must be converted to the shortest possible string representing the number as a valid integer and then that string must be used as the new content attribute value.

If a reflecting IDL attribute has a signed integer type (long) that is limited to only non-negative numbers then, on getting, the content attribute must be parsed according to the rules for parsing non-negative integers, and if that is successful, and the value is in the range of the IDL attribute's type, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead, or −1 if there is no default value. On setting, if the value is negative, the user agent must fire an INDEX_SIZE_ERR exception. Otherwise, the given value must be converted to the shortest possible string representing the number as a valid non-negative integer and then that string must be used as the new content attribute value.

If a reflecting IDL attribute has an unsigned integer type (unsigned long) then, on getting, the content attribute must be parsed according to the rules for parsing non-negative integers, and if that is successful, and the value is in the range 0 to 2147483647 inclusive, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead, or 0 if there is no default value. On setting, the given value must be converted to the shortest possible string representing the number as a valid non-negative integer and then that string must be used as the new content attribute value.

If a reflecting IDL attribute has an unsigned integer type (unsigned long) that is limited to only non-negative numbers greater than zero, then the behavior is similar to the previous case, but zero is not allowed. On getting, the content attribute must first be parsed according to the rules for parsing non-negative integers, and if that is successful, and the value is in the range 1 to 2147483647 inclusive, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead, or 1 if there is no default value. On setting, if the value is zero, the user agent must fire an INDEX_SIZE_ERR exception. Otherwise, the given value must be converted to the shortest possible string representing the number as a valid non-negative integer and then that string must be used as the new content attribute value.

If a reflecting IDL attribute has a floating point number type (double), then, on getting, the content attribute must be parsed according to the rules for parsing floating point number values, and if that is successful, the resulting value must be returned. If, on the other hand, it fails, or if the attribute is absent, the default value must be returned instead, or 0.0 if there is no default value. On setting, the given value must be converted to the best representation of the number as a floating point number and then that string must be used as the new content attribute value.

The values Infinity and Not-a-Number (NaN) values throw an exception on setting, as defined earlier.

If a reflecting IDL attribute has the type DOMTokenList or DOMSettableTokenList, then on getting it must return a DOMTokenList or DOMSettableTokenList object (as appropriate) whose underlying string is the element's corresponding content attribute. When the object mutates its underlying string, the content attribute must itself be immediately mutated. When the attribute is absent, then the string represented by the object is the empty string; when the object mutates this empty string, the user agent must add the corresponding content attribute, with its value set to the value it would have been set to after mutating the empty string. The same DOMTokenList or DOMSettableTokenList object must be returned every time for each attribute.

If an element with no attributes has its element.classList.remove() method invoked, the underlying string won't be changed, since the result of removing any token from the empty string is still the empty string. However, if the element.classList.add() method is then invoked, a class attribute will be added to the element with the value of the token to be added.

If a reflecting IDL attribute has the type HTMLElement, or an interface that descends from HTMLElement, then, on getting, it must run the following algorithm (stopping at the first point where a value is returned):

  1. If the corresponding content attribute is absent, then the IDL attribute must return null.
  2. Let candidate be the element that the document.getElementById() method would find when called on the content attribute's document if it was passed as its argument the current value of the corresponding content attribute.
  3. If candidate is null, or if it is not type-compatible with the IDL attribute, then the IDL attribute must return null.
  4. Otherwise, it must return candidate.

On setting, if the given element has an id attribute, then the content attribute must be set to the value of that id attribute. Otherwise, the IDL attribute must be set to the empty string.

2.8.2 Collections

The HTMLCollection, HTMLAllCollection, HTMLFormControlsCollection, HTMLOptionsCollection, interfaces represent various lists of DOM nodes. Collectively, objects implementing these interfaces are called collections.

When a collection is created, a filter and a root are associated with the collection.

For example, when the HTMLCollection object for the document.images attribute is created, it is associated with a filter that selects only img elements, and rooted at the root of the document.

The collection then represents a live view of the subtree rooted at the collection's root, containing only nodes that match the given filter. The view is linear. In the absence of specific requirements to the contrary, the nodes within the collection must be sorted in tree order.

The rows list is not in tree order.

An attribute that returns a collection must return the same object every time it is retrieved.

2.8.2.1 HTMLCollection

The HTMLCollection interface represents a generic collection of elements.

interface HTMLCollection {
  readonly attribute unsigned long length;
  caller getter Element item(in unsigned long index);
  caller getter object namedItem(in DOMString name); // only returns Element
};
collection . length

Returns the number of elements in the collection.

element = collection . item(index)
collection[index]
collection(index)

Returns the item with index index from the collection. The items are sorted in tree order.

Returns null if index is out of range.

element = collection . namedItem(name)
collection[name]
collection(name)

Returns the first item with ID or name name from the collection.

Returns null if no element with that ID or name could be found.

Only a, applet, area, embed, form, frame, frameset, iframe, img, and object elements can have a name for the purpose of this method; their name is given by the value of their name attribute.

The object's supported property indices are the numbers in the range zero to one less than the number of nodes represented by the collection. If there are no such elements, then there are no supported property indices.

The length attribute must return the number of nodes represented by the collection.

The item(index) method must return the indexth node in the collection. If there is no indexth node in the collection, then the method must return null.

The supported property names consist of the values of the name attributes of each a, applet, area, embed, form, frame, frameset, iframe, img, and object element represented by the collection with a name attribute, plus the list of IDs that the elements represented by the collection have.

The namedItem(key) method must return the first node in the collection that matches either of the following requirements:

If no such elements are found, then the method must return null.

2.8.2.2 HTMLAllCollection

The HTMLAllCollection interface represents a generic collection of elements just like HTMLCollection, with the exception that its namedItem() method returns an HTMLAllCollection object when there are multiple matching elements.

interface HTMLAllCollection : HTMLCollection {
  // inherits length and item()
  caller getter object namedItem(in DOMString name); // overrides inherited namedItem()
  HTMLAllCollection tags(in DOMString tagName);
};
collection . length

Returns the number of elements in the collection.

element = collection . item(index)
collection[index]
collection(index)

Returns the item with index index from the collection. The items are sorted in tree order.

Returns null if index is out of range.

element = collection . namedItem(name)
collection = collection . namedItem(name)
collection[name]
collection(name)

Returns the item with ID or name name from the collection.

If there are multiple matching items, then an HTMLAllCollection object containing all those elements is returned.

Returns null if no element with that ID or name could be found.

Only a, applet, area, embed, form, frame, frameset, iframe, img, and object elements can have a name for the purpose of this method; their name is given by the value of their name attribute.

collection = collection . tags(tagName)

Returns a collection that is a filtered view of the current collection, containing only elements with the given tag name.

The object's supported property indices and supported property names are as defined for HTMLCollection objects.

The namedItem(key) method must act according to the following algorithm:

  1. Let collection be an HTMLAllCollection object rooted at the same node as the HTMLAllCollection object on which the method was invoked, whose filter matches only elements that already match the filter of the HTMLAllCollection object on which the method was invoked and that are either:

  2. If, at the time the method is called, there is exactly one node in collection, then return that node and stop the algorithm.
  3. Otherwise, if, at the time the method is called, collection is empty, return null and stop the algorithm.
  4. Otherwise, return collection.

The tags(tagName) method must return an HTMLAllCollection rooted at the same node as the HTMLAllCollection object on which the method was invoked, whose filter matches only HTML elements whose local name is the tagName argument and that already match the filter of the HTMLAllCollection object on which the method was invoked. In HTML documents, the argument must first be converted to ASCII lowercase.

2.8.2.3 HTMLFormControlsCollection

The HTMLFormControlsCollection interface represents a collection of listed elements in form and fieldset elements.

interface HTMLFormControlsCollection : HTMLCollection {
  // inherits length and item()
  caller getter object namedItem(in DOMString name); // overrides inherited namedItem()
};

interface RadioNodeList : NodeList {
          attribute DOMString value;
};
collection . length

Returns the number of elements in the collection.

element = collection . item(index)
collection[index]
collection(index)

Returns the item with index index from the collection. The items are sorted in tree order.

Returns null if index is out of range.

element = collection . namedItem(name)
radioNodeList = collection . namedItem(name)
collection[name]
collection(name)

Returns the item with ID or name name from the collection.

If there are multiple matching items, then a RadioNodeList object containing all those elements is returned.

Returns null if no element with that ID or name could be found.

radioNodeList . value [ = value ]

Returns the value of the first checked radio button represented by the object.

Can be set, to check the first radio button with the given value represented by the object.

The object's supported property indices are as defined for HTMLCollection objects.

The supported property names consist of the values of all the id and name attributes of all the elements represented by the collection.

The namedItem(name) method must act according to the following algorithm:

  1. If, at the time the method is called, there is exactly one node in the collection that has either an id attribute or a name attribute equal to name, then return that node and stop the algorithm.
  2. Otherwise, if there are no nodes in the collection that have either an id attribute or a name attribute equal to name, then return null and stop the algorithm.
  3. Otherwise, create a new RadioNodeList object representing a live view of the HTMLFormControlsCollection object, further filtered so that the only nodes in the RadioNodeList object are those that have either an id attribute or a name attribute equal to name. The nodes in the RadioNodeList object must be sorted in tree order.
  4. Return that RadioNodeList object.

Members of the RadioNodeList interface inherited from the NodeList interface must behave as they would on a NodeList object.

The value IDL attribute on the RadioNodeList object, on getting, must return the value returned by running the following steps:

  1. Let element be the first element in tree order represented by the RadioNodeList object that is an input element whose type attribute is in the Radio Button state and whose checkedness is true. Otherwise, let it be null.

  2. If element is null, or if it is an element with no value attribute, return the empty string.

  3. Otherwise, return the value of element's value attribute.

On setting, the value IDL attribute must run the following steps:

  1. Let element be the first element in tree order represented by the RadioNodeList object that is an input element whose type attribute is in the Radio Button state and whose value content attribute is present and equal to the new value, if any. Otherwise, let it be null.

  2. If element is not null, then set its checkedness to true.

2.8.2.4 HTMLOptionsCollection

The HTMLOptionsCollection interface represents a list of option elements. It is always rooted on a select element and has attributes and methods that manipulate that element's descendants.

interface HTMLOptionsCollection : HTMLCollection {
  // inherits item()
           attribute unsigned long length; // overrides inherited length
  caller getter object namedItem(in DOMString name); // overrides inherited namedItem()
  void add(in HTMLElement element, in optional HTMLElement before);
  void add(in HTMLElement element, in long before);
  void remove(in long index);
           attribute long selectedIndex;
};
collection . length [ = value ]

Returns the number of elements in the collection.

When set to a smaller number, truncates the number of option elements in the corresponding container.

When set to a greater number, adds new blank option elements to that container.

element = collection . item(index)
collection[index]
collection(index)

Returns the item with index index from the collection. The items are sorted in tree order.

Returns null if index is out of range.

element = collection . namedItem(name)
nodeList = collection . namedItem(name)
collection[name]
collection(name)

Returns the item with ID or name name from the collection.

If there are multiple matching items, then a NodeList object containing all those elements is returned.

Returns null if no element with that ID could be found.

collection . add(element [, before ] )

Inserts element before the node given by before.

The before argument can be a number, in which case element is inserted before the item with that number, or an element from the collection, in which case element is inserted before that element.

If before is omitted, null, or a number out of range, then element will be added at the end of the list.

This method will throw a HIERARCHY_REQUEST_ERR exception if element is an ancestor of the element into which it is to be inserted. If element is not an option or optgroup element, then the method does nothing.

collection . selectedIndex [ = value ]

Returns the index of the first selected item, if any, or −1 if there is no selected item.

Can be set, to change the selection.

The object's supported property indices are as defined for HTMLCollection objects.

On getting, the length attribute must return the number of nodes represented by the collection.

On setting, the behavior depends on whether the new value is equal to, greater than, or less than the number of nodes represented by the collection at that time. If the number is the same, then setting the attribute must do nothing. If the new value is greater, then n new option elements with no attributes and no child nodes must be appended to the select element on which the HTMLOptionsCollection is rooted, where n is the difference between the two numbers (new value minus old value). Mutation events must be fired as if a DocumentFragment containing the new option elements had been inserted. If the new value is lower, then the last n nodes in the collection must be removed from their parent nodes, where n is the difference between the two numbers (old value minus new value).

Setting length never removes or adds any optgroup elements, and never adds new children to existing optgroup elements (though it can remove children from them).

The supported property names consist of the values of all the id and name attributes of all the elements represented by the collection.

The namedItem(name) method must act according to the following algorithm:

  1. If, at the time the method is called, there is exactly one node in the collection that has either an id attribute or a name attribute equal to name, then return that node and stop the algorithm.
  2. Otherwise, if there are no nodes in the collection that have either an id attribute or a name attribute equal to name, then return null and stop the algorithm.
  3. Otherwise, create a new NodeList object representing a live view of the HTMLOptionsCollection object, further filtered so that the only nodes in the NodeList object are those that have either an id attribute or a name attribute equal to name. The nodes in the NodeList object must be sorted in tree order.
  4. Return that NodeList object.

The add(element, before) method must act according to the following algorithm:

  1. If element is not an option or optgroup element, then return and abort these steps.

  2. If element is an ancestor of the select element on which the HTMLOptionsCollection is rooted, then throw a HIERARCHY_REQUEST_ERR exception.

  3. If before is an element, but that element isn't a descendant of the select element on which the HTMLOptionsCollection is rooted, then throw a NOT_FOUND_ERR exception.

  4. If element and before are the same element, then return and abort these steps.

  5. If before is a node, then let reference be that node. Otherwise, if before is an integer, and there is a beforeth node in the collection, let reference be that node. Otherwise, let reference be null.

  6. If reference is not null, let parent be the parent node of reference. Otherwise, let parent be the select element on which the HTMLOptionsCollection is rooted.

  7. Act as if the DOM Core insertBefore() method was invoked on the parent node, with element as the first argument and reference as the second argument.

The remove(index) method must act according to the following algorithm:

  1. If the number of nodes represented by the collection is zero, abort these steps.

  2. If index is not a number greater than or equal to 0 and less than the number of nodes represented by the collection, let element be the first element in the collection. Otherwise, let element be the indexth element in the collection.

  3. Remove element from its parent node.

The selectedIndex IDL attribute must act like the identically named attribute on the select element on which the HTMLOptionsCollection is rooted

2.8.3 DOMTokenList

The DOMTokenList interface represents an interface to an underlying string that consists of a set of space-separated tokens.

DOMTokenList objects are always case-sensitive, even when the underlying string might ordinarily be treated in a case-insensitive manner.

interface DOMTokenList {
  readonly attribute unsigned long length;
  getter DOMString item(in unsigned long index);
  boolean contains(in DOMString token);
  void add(in DOMString token);
  void remove(in DOMString token);
  boolean toggle(in DOMString token);
  stringifier DOMString ();
};
tokenlist . length

Returns the number of tokens in the string.

element = tokenlist . item(index)
tokenlist[index]

Returns the token with index index. The tokens are returned in the order they are found in the underlying string.

Returns null if index is out of range.

hastoken = tokenlist . contains(token)

Returns true if the token is present; false otherwise.

Throws a SYNTAX_ERR exception if token is empty.

Throws an INVALID_CHARACTER_ERR exception if token contains any spaces.

tokenlist . add(token)

Adds token, unless it is already present.

Throws a SYNTAX_ERR exception if token is empty.

Throws an INVALID_CHARACTER_ERR exception if token contains any spaces.

tokenlist . remove(token)

Removes token if it is present.

Throws a SYNTAX_ERR exception if token is empty.

Throws an INVALID_CHARACTER_ERR exception if token contains any spaces.

hastoken = tokenlist . toggle(token)

Adds token if it is not present, or removes it if it is. Returns true if token is now present (it was added); returns false if it is not (it was removed).

Throws a SYNTAX_ERR exception if token is empty.

Throws an INVALID_CHARACTER_ERR exception if token contains any spaces.

The length attribute must return the number of tokens that result from splitting the underlying string on spaces. This is the length.

The object's supported property indices are the numbers in the range zero to length-1, unless the length is zero, in which case there are no supported property indices.

The item(index) method must split the underlying string on spaces, preserving the order of the tokens as found in the underlying string, and then return the indexth item in this list. If index is equal to or greater than the number of tokens, then the method must return null.

For example, if the string is "a b a c" then there are four tokens: the token with index 0 is "a", the token with index 1 is "b", the token with index 2 is "a", and the token with index 3 is "c".

The contains(token) method must run the following algorithm:

  1. If the token argument is the empty string, then raise a SYNTAX_ERR exception and stop the algorithm.
  2. If the token argument contains any space characters, then raise an INVALID_CHARACTER_ERR exception and stop the algorithm.
  3. Otherwise, split the underlying string on spaces to get the list of tokens in the DOMTokenList object's underlying string.
  4. If the token indicated by token is a case-sensitive match for one of the tokens in the DOMTokenList object's underlying string then return true and stop this algorithm.
  5. Otherwise, return false.

The add(token) method must run the following algorithm:

  1. If the token argument is the empty string, then raise a SYNTAX_ERR exception and stop the algorithm.
  2. If the token argument contains any space characters, then raise an INVALID_CHARACTER_ERR exception and stop the algorithm.
  3. Otherwise, split the underlying string on spaces to get the list of tokens in the DOMTokenList object's underlying string.
  4. If the given token is a case-sensitive match for one of the tokens in the DOMTokenList object's underlying string then stop the algorithm.
  5. Otherwise, if the DOMTokenList object's underlying string is not the empty string and the last character of that string is not a space character, then append a U+0020 SPACE character to the end of that string.
  6. Append the value of token to the end of the DOMTokenList object's underlying string.

The remove(token) method must run the following algorithm:

  1. If the token argument is the empty string, then raise a SYNTAX_ERR exception and stop the algorithm.
  2. If the token argument contains any space characters, then raise an INVALID_CHARACTER_ERR exception and stop the algorithm.
  3. Otherwise, remove the given token from the underlying string.

The toggle(token) method must run the following algorithm:

  1. If the token argument is the empty string, then raise a SYNTAX_ERR exception and stop the algorithm.
  2. If the token argument contains any space characters, then raise an INVALID_CHARACTER_ERR exception and stop the algorithm.
  3. Otherwise, split the underlying string on spaces to get the list of tokens in the DOMTokenList object's underlying string.
  4. If the given token is a case-sensitive match for one of the tokens in the DOMTokenList object's underlying string then remove the given token from the underlying string and stop the algorithm, returning false.
  5. Otherwise, if the DOMTokenList object's underlying string is not the empty string and the last character of that string is not a space character, then append a U+0020 SPACE character to the end of that string.
  6. Append the value of token to the end of the DOMTokenList object's underlying string.
  7. Return true.

A DOMTokenList object must stringify to the value of the DOMTokenList object's underlying string.

2.8.4 DOMSettableTokenList

The DOMSettableTokenList interface is the same as the DOMTokenList interface, except that it allows the underlying string to be directly changed.

interface DOMSettableTokenList : DOMTokenList {
            attribute DOMString value;
};
tokenlist . value

Returns the underlying string.

Can be set, to change the underlying string.

An object implementing the DOMSettableTokenList interface must act as defined for the DOMTokenList interface, except for the value attribute defined here.

The value attribute must return the underlying string on getting, and must replace the underlying string with the new value on setting.

2.8.5 Safe passing of structured data

When a user agent is required to obtain a structured clone of a value, it must run the following algorithm, which either returns a separate value, or throws an exception.

  1. Let input be the value being cloned.

  2. Let memory be an association list of pairs of objects, initially empty. This is used to handle duplicate references. In each pair of objects, one is called the source object and the other the destination object.

  3. Let output be the value resulting from calling the internal structured cloning algorithm with input and memory.

  4. Return output.

The internal structured cloning algorithm is always called with two arguments, input and memory, and its behavior is as follows:

  1. If input is the source object of a pair of objects in memory, then return the destination object in that pair of objects and abort these steps.

  2. If input is a primitive value, then return that value and abort these steps.

  3. The input value is an object. Jump to the appropriate step below:

    If input is a Boolean object

    Let output be a newly constructed Boolean object with the same value as input.

    If input is a Number object

    Let output be a newly constructed Number object with the same value as input.

    If input is a String object

    Let output be a newly constructed String object with the same value as input.

    If input is a Date object

    Let output be a newly constructed Date object with the same value as input.

    If input is a RegExp object

    Let output be a newly constructed RegExp object with the same pattern and flags as input.

    The value of the lastIndex property is not copied.

    If input is a ImageData object

    Let output be a newly constructed ImageData object with the same width and height as input, and with a newly constructed CanvasPixelArray for its data attribute, with the same length and pixel values as the input's.

    If input is a File object

    Let output be a newly constructed File object corresponding to the same underlying data.

    If input is a Blob object

    Let output be a newly constructed Blob object corresponding to the same underlying data.

    If input is a FileList object

    Let output be a newly constructed FileList object containing a list of newly constructed File objects corresponding to the same underlying data as those in input, maintaining their relative order.

    If input is an Array object

    Let output be a newly constructed empty Array object.

    If input is an Object object

    Let output be a newly constructed empty Object object.

    If input is another native object type (e.g. Error, Function)
    If input is a host object (e.g. a DOM node)

    Throw a DATA_CLONE_ERR exception and abort the overall structured clone algorithm.

  4. Add a mapping from input (the source object) to output (the destination object) to memory.

  5. If input is an Array object or an Object object, then, for each enumerable property in input, add a new property to output having the same name, and having a value created from invoking the internal structured cloning algorithm recursively with the value of the property as the "input" argument and memory as the "memory" argument. The order of the properties in the input and output objects must be the same.

    This does not walk the prototype chain.

    Property descriptors, setters, getters, and analogous features are not copied in this process. For example, the property in the input could be marked as read-only, but in the output it would just have the default state (typically read-write, though that could depend on the scripting environment).

  6. Return output.

This algorithm preserves cycles and preserves the identity of duplicate objects in graphs.

2.8.6 DOMStringMap

The DOMStringMap interface represents a set of name-value pairs. It exposes these using the scripting language's native mechanisms for property access.

When a DOMStringMap object is instantiated, it is associated with three algorithms, one for getting the list of name-value pairs, one for setting names to certain values, and one for deleting names.

interface DOMStringMap {
  getter DOMString (in DOMString name);
  setter void (in DOMString name, in DOMString value);
  creator void (in DOMString name, in DOMString value);
  deleter void (in DOMString name);
};

The supported property names on a DOMStringMap object at any instant are the names of each pair returned from the algorithm for getting the list of name-value pairs at that instant.

To determine the value of a named property name in a DOMStringMap, the user agent must return the value component of the name-value pair whose name component is name in the list returned by the algorithm for getting the list of name-value pairs.

To set the value of a new or existing named property name to value value, the algorithm for setting names to certain values must be run, passing name as the name and the result of converting value to a DOMString as the value.

To delete an existing named property name, the algorithm for deleting names must be run, passing name as the name.

The DOMStringMap interface definition here is only intended for JavaScript environments. Other language bindings will need to define how DOMStringMap is to be implemented for those languages.

The dataset attribute on elements exposes the data-* attributes on the element.

Given the following fragment and elements with similar constructions:

<img class="tower" id="tower5" data-x="12" data-y="5"
     data-ai="robotarget" data-hp="46" data-ability="flames"
     src="towers/rocket.png alt="Rocket Tower">

...one could imagine a function splashDamage() that takes some arguments, the first of which is the element to process:

function splashDamage(node, x, y, damage) {
  if (node.classList.contains('tower') && // checking the 'class' attribute
      node.dataset.x == x && // reading the 'data-x' attribute
      node.dataset.y == y) { // reading the 'data-y' attribute
    var hp = parseInt(node.dataset.hp); // reading the 'data-hp' attribute
    hp = hp - damage;
    if (hp < 0) {
      hp = 0;
      node.dataset.ai = 'dead'; // setting the 'data-ai' attribute
      delete node.dataset.ability; // removing the 'data-ability' attribute
    }
    node.dataset.hp = hp; // setting the 'data-hp' attribute
  }
}

2.8.7 DOM feature strings

DOM3 Core defines mechanisms for checking for interface support, and for obtaining implementations of interfaces, using feature strings. [DOMCORE]

Authors are strongly discouraged from using these, as they are notoriously unreliable and imprecise. Authors are encouraged to rely on explicit feature testing or the graceful degradation behavior intrinsic to some of the features in this specification.

For historical reasons, user agents should return the true value when the hasFeature(feature, version) method of the DOMImplementation interface is invoked with feature set to either "HTML" or "XHTML" and version set to either "1.0" or "2.0".

2.8.8 Exceptions

The following are DOMException codes. [DOMCORE]

  1. INDEX_SIZE_ERR
  2. DOMSTRING_SIZE_ERR
  3. HIERARCHY_REQUEST_ERR
  4. WRONG_DOCUMENT_ERR
  5. INVALID_CHARACTER_ERR
  6. NO_DATA_ALLOWED_ERR
  7. NO_MODIFICATION_ALLOWED_ERR
  8. NOT_FOUND_ERR
  9. NOT_SUPPORTED_ERR
  10. INUSE_ATTRIBUTE_ERR
  11. INVALID_STATE_ERR
  12. SYNTAX_ERR
  13. INVALID_MODIFICATION_ERR
  14. NAMESPACE_ERR
  15. INVALID_ACCESS_ERR
  16. VALIDATION_ERR
  17. TYPE_MISMATCH_ERR
  18. SECURITY_ERR
  19. NETWORK_ERR
  20. ABORT_ERR
  21. URL_MISMATCH_ERR
  22. QUOTA_EXCEEDED_ERR
  23. TIMEOUT_ERR
  24. DATA_CLONE_ERR
[Supplemental] exception DOMException {
  const unsigned short URL_MISMATCH_ERR = 21;
  const unsigned short QUOTA_EXCEEDED_ERR = 22;
  const unsigned short DATA_CLONE_ERR = 25;
};

2.8.9 Garbage collection

There is an implied strong reference from any IDL attribute that returns a pre-existing object to that object.

For example, the document.location attribute means that there is a strong reference from a Document object to its Location object. Similarly, there is always a strong reference from a Document to any descendant nodes, and from any node to its owner Document.