1. 2.6 共通DOMインターフェイス
      1. 2.6.1 IDL属性におけるコンテンツ属性の反映
      2. 2.6.2 コレクション
        1. 2.6.2.1 HTMLAllCollectionインターフェイス
        2. 2.6.2.2 HTMLFormControlsCollectionインターフェイス
        3. 2.6.2.3 HTMLOptionsCollectionインターフェイス
      3. 2.6.3 DOMStringListインターフェイス
      4. 2.6.4 Garbage collection

2.6 共通DOMインターフェイス

2.6.1 IDL属性におけるコンテンツ属性の反映

一部のIDL属性は、特定のコンテンツ属性の反映を定義する。これは、IDL属性がコンテンツ属性の現在値を返し、IDL属性が与えられた値にコンテンツ属性の値を変更することを意味する。

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 USVString attribute whose content attribute is defined to contain a URL, then on getting, if the content attribute is absent, the IDL attribute must return the empty string. Otherwise, the IDL attribute must parse the value of the content attribute relative to the element's node document and if that is successful, return the resulting URL string. If parsing fails, then the value of the content attribute must be returned instead, converted to a USVString. On setting, the content attribute must be set to the specified new 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), if any, or the empty string if the attribute is in a state that has no associated keyword value or if the attribute is not in a defined state (e.g. the attribute is missing and there is no missing value default). On setting, the content attribute must be set to the specified new value.

If a reflecting IDL attribute is a nullable DOMString attribute whose content attribute is an enumerated attribute, then, on getting, if the corresponding content attribute is in its missing value default then the IDL attribute must return null, otherwise, the IDL attribute must return the conforming value associated with the state the attribute is in (in its canonical case). On setting, if the new value is null, the content attribute must be removed, and otherwise, the content attribute must be set to the specified new value.

If a reflecting IDL attribute is a DOMString or USVString 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 throw an "IndexSizeError" DOMException. 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, first, if the new value is in the range 0 to 2147483647, then let n be the new value, otherwise let n be the default value, or 0 if there is no default value; then, n must be converted to the shortest possible string representing the number as a valid non-negative integer and 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 throw an "IndexSizeError" DOMException. Otherwise, first, if the new value is in the range 1 to 2147483647, then let n be the new value, otherwise let n be the default value, or 1 if there is no default value; then, n must be converted to the shortest possible string representing the number as a valid non-negative integer and 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 with fallback, then the behavior is similar to the previous case, but disallowed values are converted to the default value. 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. On setting, first, if the new value is in the range 1 to 2147483647, then let n be the new value, otherwise let n be the default value; then, n must be converted to the shortest possible string representing the number as a valid non-negative integer and 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 clamped to the range [min, max], then 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 between min and max inclusive, the resulting value must be returned. If it fails, the default value must be returned. If it succeeds but the value is less than min, min must be returned. If it succeeds but the value is greater than max, max must be returned. On setting, it behaves the same as setting a regular reflected unsigned integer.

If a reflecting IDL attribute has a floating-point number type (double or unrestricted 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.

If a reflecting IDL attribute has a floating-point number type (double or unrestricted double) that is limited to numbers greater than zero, then the behavior is similar to the previous case, but zero and negative values are not allowed. On getting, the content attribute must be parsed according to the rules for parsing floating-point number values, and if that is successful and the value is greater than 0.0, 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.0 if there is no default value. On setting, if the value is less than or equal to zero, then the value must be ignored. Otherwise, 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 in the Web IDL specification. [WEBIDL]

If a reflecting IDL attribute has the type DOMTokenList, then on getting it must return a DOMTokenList object whose associated element is the element in question and whose associated attribute's local name is the name of the attribute in question.

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 element's node document if it were 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, and has the same tree as the element of the attribute being set, and the given element is the first element in that tree whose ID is the value of that id attribute, then the content attribute must be set to the value of that id attribute. Otherwise, the content attribute must be set to the empty string.

2.6.2 コレクション

HTMLFormControlsCollectionおよびHTMLOptionsCollectionインターフェイスは、HTMLCollectionインターフェイスから派生するコレクションである。HTMLAllCollectionインターフェイスはコレクションであるが、派生ではない。

2.6.2.1 The HTMLAllCollection interface

HTMLAllCollectionインターフェイスは、レガシーdocument.all属性に対して使用される。このインターフェイスは、HTMLCollectionと類似の動作をする。主な違いは、このインターフェイスが完全に最後には何かを返すことになるためにそのメソッドの驚くほどさまざまな異なる(不正)利用を可能にし、プロパティアクセスの代替としての機能として呼び出すことができることということである。

すべてのHTMLAllCollectionオブジェクトは、Documentでルート化され、すべての要素とマッチするフィルターを持つ。その結果HTMLAllCollectionオブジェクトのコレクションによって表される要素は、ルートDocumentのすべての子孫要素から成る。

[LegacyUnenumerableNamedProperties]
interface HTMLAllCollection {
  readonly attribute unsigned long length;
  getter Element? (unsigned long index);
  getter (HTMLCollection or Element)? namedItem(DOMString name);
  legacycaller (HTMLCollection or Element)? item(optional DOMString nameOrIndex);
};
collection . length

コレクションの要素数を返す。

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

ツリー順で決定される)コレクションからのインデックスindexとともにアイテムを返す。

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

コレクションからのIDまたは名前nameとともにアイテムを返す。

複数のマッチするアイテムが存在する場合、それらの要素すべてを含むHTMLCollectionオブジェクトが返される。

ただしbuttonformiframeinputmapmetaobjectselectおよびtextarea要素は、このメソッドのために名前を持つことができる。 それらの名前はname属性値によって与えられる。

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

The supported property names consist of the non-empty values of all the id attributes of all the elements represented by the collection, and the non-empty values of all the name attributes of all the "all"-named elements represented by the collection, in tree order, ignoring later duplicates, with the id of an element preceding its name if it contributes both, they differ from each other, and neither is the duplicate of an earlier entry.

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

The indexed property getter must return the result of getting the "all"-indexed element from this HTMLAllCollection given the passed index.

The namedItem(name) method must return the result of getting the "all"-named element(s) from this HTMLAllCollection given name.

The item(nameOrIndex) method (and the legacycaller behavior) must run the following steps:

  1. If nameOrIndex was not provided, return null.

  2. If nameOrIndex, converted to a JavaScript string value, is an array index property name, return the result of getting the "all"-indexed element from this HTMLAllCollection given the number represented by nameOrIndex.

  3. Return the result of getting the "all"-named element(s) from this HTMLAllCollection given nameOrIndex.


The following elements are "all"-named elements: a, applet, button, embed, form, frame, frameset, iframe, img, input, map, meta, object, select, and textarea

To get the "all"-indexed element from an HTMLAllCollection collection given an index index, return the indexth element in collection, or null if there is no such indexth element.

To get the "all"-named element(s) from an HTMLAllCollection collection given a name name, perform the following steps:

  1. If name is the empty string, return null.

  2. Let subCollection be an HTMLCollection object rooted at the same Document as collection, whose filter matches only elements that are either:

  3. If there is exactly one element in subCollection, then return that element.

  4. Otherwise, if subCollection is empty, return null.

  5. Otherwise, return subCollection.

2.6.2.2 The HTMLFormControlsCollection interface

HTMLFormControlsCollectionインターフェイスは、form要素で記載要素コレクションに使用される。

interface HTMLFormControlsCollection : HTMLCollection {
  // inherits length and item()
  getter (RadioNodeList or Element)? namedItem(DOMString name); // shadows inherited namedItem()
};

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

コレクションの要素数を返す。

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

コレクションからのインデックスindexとともにアイテムを返す。アイテムはツリー順にソートされる。

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

コレクションからのIDまたはname nameとともにアイテムを返す。

複数のマッチするアイテムが存在する場合、それらの要素すべてを含むRadioNodeListオブジェクトが返される。

radioNodeList . value [ = value ]

オブジェクトによって表される最初にチェックされたラジオボタンの値を返す。

設定される場合、オブジェクトによって表される与えられた値を持つ最初のラジオボタンをチェックする。

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

The supported property names consist of the non-empty values of all the id and name attributes of all the elements represented by the collection, in tree order, ignoring later duplicates, with the id of an element preceding its name if it contributes both, they differ from each other, and neither is the duplicate of an earlier entry.

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

  1. If name is the empty string, return null and stop the algorithm.
  2. 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.
  3. 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.
  4. 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.
  5. 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, return the empty string.

  3. If element is an element with no value attribute, return the string "on".

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

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

  1. If the new value is the string "on": 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 either absent, or present and equal to the new value, if any. If no such element exists, then instead let element be null.

    Otherwise: 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. If no such element exists, then instead let element be null.

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

2.6.2.3 The HTMLOptionsCollection interface

HTMLOptionsCollectionインターフェイスは、option要素のコレクションに使用される。常にselect要素がルートであり、要素の子孫をコントロールする属性およびメソッドを持つ。

interface HTMLOptionsCollection : HTMLCollection {
  // inherits item(), namedItem()
  [CEReactions] attribute unsigned long length; // shadows inherited length
  [CEReactions] setter void (unsigned long index, HTMLOptionElement? option);
  [CEReactions] void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
  [CEReactions] void remove(long index);
  attribute long selectedIndex;
};
collection . length [ = value ]

コレクションの要素数を返す。

より小さい数に設定する場合、対応するコンテナ内のoption要素数は切り捨てられる。

より大きい数に設定する場合、そのコンテナに新しい空白のoption要素を追加する。

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

コレクションからのインデックスindexとともにアイテムを返す。アイテムはツリー順にソートされる。

collection[index] = element

indexがコレクションで項目の数より大きい数である場合、対応するコンテナで新しい空白のoption要素を追加する。

nullに設定する場合、コレクションからインデックスindexで項目を削除する。

option要素に設定する場合、コレクションからインデックスindexで追加または置換する。

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

コレクションからのIDまたはname nameとともにアイテムを返す。

複数のマッチするアイテムが存在する場合、最初のものが返される。

collection . add(element [, before ] )

beforeによって与えられるノードの前の要素を挿入する。

before引数は数字でもよく、その場合elementはその数字をもつアイテムの前に挿入され、またはコレクションからの要素でもよい。その場合elementはその要素の前に挿入される。

beforeが省略された、null、または範囲外の数字の場合、elementはリストの最後に加えられるだろう。

elementに挿入された要素が親要素である場合、このメソッドは"HierarchyRequestError" DOMExceptionを投げる。

collection . remove(index)

コレクションからのインデックスindexをもつ項目を削除する。

collection . selectedIndex [ = value ]

もしあるならば、最初に選ばれたアイテムのインデックスを、または選択したアイテムが存在しない場合−1を返す。

選択を変更する設定が可能である。

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 non-empty values of all the id and name attributes of all the elements represented by the collection, in tree order, ignoring later duplicates, with the id of an element preceding its name if it contributes both, they differ from each other, and neither is the duplicate of an earlier entry.

When the user agent is to set the value of a new indexed property or set the value of an existing indexed property for a given property index index to a new value value, it must run the following algorithm:

  1. If value is null, invoke the steps for the remove method with index as the argument, and abort these steps.

  2. Let length be the number of nodes represented by the collection.

  3. Let n be index minus length.

  4. If n is greater than zero, then append a DocumentFragment consisting of n-1 new option elements with no attributes and no child nodes to the select element on which the HTMLOptionsCollection is rooted.

  5. If n is greater than or equal to zero, append value to the select element. Otherwise, replace the indexth element in the collection by value.

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

  1. If element is an ancestor of the select element on which the HTMLOptionsCollection is rooted, then throw a "HierarchyRequestError" DOMException and abort these steps.

  2. 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 "NotFoundError" DOMException and abort these steps.

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

  4. 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.

  5. 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.

  6. Pre-insert element into parent node before reference.

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, abort these steps.

  3. Let element be the indexth element in the collection.

  4. 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.6.3 The DOMStringList interface

DOMStringListインターフェイスは、文字列のリストを表現する非流行のレトロな方法である。

[Exposed=(Window,Worker)]
interface DOMStringList {
  readonly attribute unsigned long length;
  getter DOMString? item(unsigned long index);
  boolean contains(DOMString string);
};

新しいAPIは、DOMStringListよりもむしろsequence<DOMString>または同等のものを使用しなければならない。

strings . length

strings内の文字列の数を返す。

strings[index]
strings . item(index)

stringsからインデックスindexをもつ文字列を返す。

strings . contains(string)

stringsstringが含まれる場合はtrueを返し、そうでなければfalseを返す。

Each DOMStringList object has an associated list.

The supported property indices for a DOMStringList object are the numbers zero to the associated list's size minus one. If its associated list is empty, it has no supported property indices.

The length attribute's getter must return this DOMStringList object's associated list's size.

The item(index) method, when invoked, must return the indexth item in this DOMStringList object's associated list, or null if index plus one is greater than this DOMStringList object's associated list's size.

The contains(string) method, when invoked, must return true if this DOMStringList object's associated list contains string, and false otherwise.

2.6.4 Garbage collection

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

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