From 4674ad0caa3bb1841d07fa8dda3f80204f795dbc Mon Sep 17 00:00:00 2001 From: Yoav Weiss Date: Tue, 3 Nov 2015 12:36:03 +0100 Subject: [PATCH] Add DOMTokenList hook to validate to added token Add the required hooks so that iframe@sandbox, link@rel and hopefully future features would be able to use DOMTokenList.add() for feature detection, by making sure that an added token is valid, and therefore supported. Closes https://www.w3.org/Bugs/Public/show_bug.cgi?id=29061 --- dom.bs | 38 ++++++++++++++++++++++++++++++++++---- dom.html | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/dom.bs b/dom.bs index 5d64abfc..9fdf2f55 100644 --- a/dom.bs +++ b/dom.bs @@ -8679,6 +8679,25 @@ interface DOMTokenList {

A {{DOMTokenList}} object also has an associated element and an attribute's local name. +Specifications may define +supported tokens for a {{DOMTokenList}}'s +associated attribute. + +

A {{DOMTokenList}} object's +validation steps for a given +token are: + +

    +
  1. If the associated attribute does not define supported tokens, return true. + +

  2. Let lowercase token be a copy of token, + converted to ASCII lowercase. + +

  3. If lowercase token is present in supported tokens, return true. + +

  4. Return false. +

+

A {{DOMTokenList}} object's update steps are to set an attribute value for the associated element using associated @@ -8702,10 +8721,11 @@ interface DOMTokenList {

tokenlist . add(tokens…)
-

Adds all arguments passed, except those already present. +

Adds all valid arguments passed, except those already present.

Throws a {{SyntaxError}} exception if one if the arguments is the empty string.

Throws an {{InvalidCharacterError}} exception if one of the arguments contains any ASCII whitespace. +

Returns false if any invalid arguments passed, true otherwise.

tokenlist . remove(tokens…)
@@ -8717,8 +8737,9 @@ interface DOMTokenList {
tokenlist . toggle(token [, force])

If force is not given, "toggles" token, removing it if it's present and - adding it if it's not. If force is true, adds token (same as {{add()}}). If - force is false, removes token (same as {{DOMTokenList/remove()}}). + adding it if it's not present and is valid. If force is true, adds token + if it is valid (same as {{add()}}). If force is false, removes token (same + as {{DOMTokenList/remove()}}).

Returns true if token is now present, and false otherwise.

Throws a {{SyntaxError}} exception if token is empty.

Throws an {{InvalidCharacterError}} exception if token contains any spaces. @@ -8763,10 +8784,15 @@ method, when invoked, must run these steps:

  • If one of tokens contains any ASCII whitespace, then throw an {{InvalidCharacterError}} exception. +

  • Let valid be true. +
  • For each token in tokens, in given order, that is not in - tokens, append token to tokens. + tokens, run validation steps with token. If the return value is false, + set valid to false. Otherwise, append token to tokens.

  • Run the update steps. + +

  • Return valid.

    The @@ -8810,6 +8836,9 @@ method, when invoked, must run these steps:

    1. If force is passed and is false, return false. +

    2. Otherwise, run validation steps with token. If the return value is + false, return false. +

    3. Otherwise, append token to tokens, run the update steps, and return true.

    @@ -9145,6 +9174,7 @@ Travis Leithead, Vidur Apparao, Warren He, Yehuda Katz, +Yoav Weiss, Yoichi Osato, and Zack Weinberg for being awesome! diff --git a/dom.html b/dom.html index b45e05e6..0dd2dd81 100644 --- a/dom.html +++ b/dom.html @@ -69,7 +69,7 @@

    DOM

    -

    Living Standard — Last Updated

    +

    Living Standard — Last Updated

    Participate: @@ -4028,6 +4028,19 @@

    A DOMTokenList object has an associated ordered set of tokens, which is initially empty.

    A DOMTokenList object also has an associated element and an attribute’s local name.

    +

    Specifications may define supported tokens for a DOMTokenList's +associated attribute.

    +

    A DOMTokenList object’s validation steps for a given token are:

    +
      +
    1. +

      If the associated attribute does not define supported tokens, return true.

      +
    2. +

      Let lowercase token be a copy of token, converted to ASCII lowercase.

      +
    3. +

      If lowercase token is present in supported tokens, return true.

      +
    4. +

      Return false.

      +

    A DOMTokenList object’s update steps are to set an attribute value for the associated element using associated attribute’s local name and the result of running the ordered set serializer for tokens.

    tokenlist . length @@ -4044,9 +4057,10 @@

    Throws an InvalidCharacterError exception if token contains any ASCII whitespace.

    tokenlist . add(tokens…)
    -

    Adds all arguments passed, except those already present.

    +

    Adds all valid arguments passed, except those already present.

    Throws a SyntaxError exception if one if the arguments is the empty string.

    Throws an InvalidCharacterError exception if one of the arguments contains any ASCII whitespace.

    +

    Returns false if any invalid arguments passed, true otherwise.

    tokenlist . remove(tokens…)

    Removes arguments passed, if they are present.

    @@ -4055,7 +4069,8 @@

    tokenlist . toggle(token [, force])

    If force is not given, "toggles" token, removing it if it’s present and - adding it if it’s not. If force is true, adds token (same as add()). If force is false, removes token (same as remove()).

    + adding it if it’s not present and is valid. If force is true, adds token if it is valid (same as add()). If force is false, removes token (same + as remove()).

    Returns true if token is now present, and false otherwise.

    Throws a SyntaxError exception if token is empty.

    Throws an InvalidCharacterError exception if token contains any spaces.

    @@ -4089,10 +4104,14 @@

    If one of tokens is the empty string, throw a SyntaxError exception.

  • If one of tokens contains any ASCII whitespace, then throw an InvalidCharacterError exception.

    +
  • Let valid be true.
  • -

    For each token in tokens, in given order, that is not in tokens, append token to tokens.

    +

    For each token in tokens, in given order, that is not in tokens, run validation steps with token. If the return value is false, + set valid to false. Otherwise, append token to tokens.

  • Run the update steps.

    +
  • +

    Return valid.

    The remove(tokens…) method, when invoked, must run these steps:

      @@ -4124,6 +4143,9 @@

    1. If force is passed and is false, return false.

      +
    2. +

      Otherwise, run validation steps with token. If the return value is + false, return false.

    3. Otherwise, append token to tokens, run the update steps, and return true.

      @@ -4371,6 +4393,7 @@

      Acknowledgmen Vidur Apparao, Warren He, Yehuda Katz, +Yoav Weiss, Yoichi Osato, and Zack Weinberg for being awesome!

      @@ -5261,6 +5284,7 @@

      substring data, in §4.9
    4. substringData(offset, count), in §4.9
    5. subtree, in §4.3.1 +
    6. supported tokens, in §7.1
    7. surroundContents(newParent), in §5.2
    8. systemId @@ -5340,6 +5364,7 @@

      UserDataHandler, in §8.2
    9. validate, in §2.5
    10. validate and extract, in §2.5 +
    11. validation steps, in §7.1
    12. value