From a5666e60ee13e568581e11f6437b6517c461649c Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 15 May 2026 17:06:36 +0200 Subject: [PATCH] Editorial: modernize HTMLOptionsCollection Fixes #3652. --- source | 151 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 94 insertions(+), 57 deletions(-) diff --git a/source b/source index 291c45fff57..8f8b4b0f426 100644 --- a/source +++ b/source @@ -9820,8 +9820,8 @@ interface HTMLOptionsCollection : HTMLCollection

Let n be valuecurrent.

-
  • Append n new option elements with no attributes and no child - nodes to the select element on which this is rooted.

  • +
  • Append new option elements to the select element on which + this is rooted given n.

  • @@ -9851,73 +9851,88 @@ interface HTMLOptionsCollection : HTMLCollection
    -

    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:

    +

    To append new option elements to a select element + select given a non-negative integer count:

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

    2. +
    3. Let fragment be a new DocumentFragment whose node + document is select's node document.

    4. -
    5. Let length be the number of nodes represented by the - collection.

    6. +
    7. Append count new option elements to fragment.

    8. + +
    9. Append fragment to + select.

    10. +
    +
    + +
    +

    To set the value of a new indexed property + or set the value of an existing indexed property for an + HTMLOptionsCollection collection, given a property index index + and a new value value:

    + +
      +
    1. If value is null, then remove + an option from collection given index and return.

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

    4. -
    5. Let delta be index minus length.

    6. +
    7. Let delta be indexlength.

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

    10. +
    11. If delta is greater than 0, then append new option elements to + the select element on which collection is rooted given + delta.

    12. -
    13. If delta is greater than or equal to zero, append value to the select - element. Otherwise, replace the indexth element in the collection by value.

    14. +
    15. If delta is greater than or equal to 0, then append value to the select element + on which collection is rooted. Otherwise, replace the indexth element in + collection by value.

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

    + method steps are:

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

    2. + this is rooted, then throw a "HierarchyRequestError" + DOMException.

    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 "NotFoundError" DOMException.

    4. + select element on which this is rooted, then throw a + "NotFoundError" DOMException.

      + +
    5. If element and before are the same element, then return.

    6. -
    7. If element and before are the same element, then - return.

    8. +
    9. Let reference be null.

    10. -
    11. 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.

    12. +
    13. If before is a node, then set reference to before. + Otherwise, if before is an integer and there is a beforeth node in + this, then set reference to that node.

    14. -
    15. 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.

    16. +
    17. Let parent be reference's parent node if reference is + not null; otherwise the select element on which this is rooted.

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

      + reference.

    -

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

    +

    To remove an option from an + HTMLOptionsCollection collection given an integer index:

      -
    1. If the number of nodes represented by the collection is zero, return.

    2. +
    3. If the number of nodes represented by + collection is 0, then return.

    4. -
    5. If index is not a number greater than or equal to 0 and less than the - number of nodes represented by the collection, return.

    6. +
    7. If index is not a number greater than or equal to 0 and less than the number + of nodes represented by collection, + then return.

    8. @@ -9931,18 +9946,31 @@ interface HTMLOptionsCollection : HTMLCollection -
    9. Let element be the indexth element in the - collection.

    10. +
    11. Let element be the indexth element in + collection.

    12. Remove element from its parent node.

    +
    +

    The remove(index) method steps are + to remove an option from + this given index.

    +
    +

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

    + data-x="dom-HTMLOptionsCollection-selectedIndex">selectedIndex getter steps are to + return the selected index of the select + element on which this is rooted.

    +
    + +
    +

    The selectedIndex setter steps + are to set the selected index of the select element on which + this is rooted to the given value.

    @@ -57370,23 +57398,21 @@ interface HTMLSelectElement : HTMLElement { selectedness set to true.

    -
    -

    The selectedIndex getter steps are to return the index of the first option element in - this's list of options in tree - order that has its selectedness set to - true, if any. If there isn't one, then return −1.

    -
    +

    A select element's selected index is + the index of the first option element in + its list of options in tree order + that has its selectedness set to true. If there + isn't one, then it is −1.

    -

    The selectedIndex setter steps are:

    +

    To set the selected index of a select element + select to a value value:

    1. Let firstMatchingOption be null.

    2. -

      For each option of this's For each option of select's list of options:

        @@ -57394,7 +57420,7 @@ interface HTMLSelectElement : HTMLElement { to false.

      1. If firstMatchingOption is null and option's index is equal to the given value, then set + data-x="concept-option-index">index is equal to value, then set firstMatchingOption to option.

    3. @@ -57405,7 +57431,7 @@ interface HTMLSelectElement : HTMLElement { true.

    4. Run update a select's selectedcontent given - this.

    5. + select.

    @@ -57414,6 +57440,17 @@ interface HTMLSelectElement : HTMLElement { select element having no multiple attribute and a display size of 1.

    +
    +

    The selectedIndex getter steps are to return + this's selected index.

    +
    + +
    +

    The selectedIndex setter steps are to set + the selected index of this to the given value.

    +
    +

    The value getter steps are to return the value of the