From 2a94a9a15bbadd802e86ff822f73007e44d2a576 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Fri, 19 Apr 2024 04:09:24 +0100 Subject: [PATCH] Upstream insertAdjacentHTML() from DOM Parsing and Serialization --- source | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/source b/source index 68971fdbad..f97f80ec94 100644 --- a/source +++ b/source @@ -112353,6 +112353,7 @@ document.body.appendChild(frame) [CEReactions] attribute [LegacyNullToEmptyString] HTMLString innerHTML; [CEReactions] attribute [LegacyNullToEmptyString] HTMLString outerHTML; + [CEReactions] undefined insertAdjacentHTML(DOMString position, HTMLString string); }; partial interface ShadowRoot { @@ -112861,6 +112862,139 @@ enum DOMParserSupportedType { +

The insertAdjacentHTML() method

+ +

The insertAdjacentHTML() + method has a number of outstanding issues in the DOM Parsing and Serialization issue tracker, documenting various problems + with its specification.

+ +
+
element.insertAdjacentHTML(position, string)
+
+

Parses string as HTML or XML and inserts the resulting nodes into the tree in + the position given by the position argument, as follows:

+ +
+
"beforebegin"
+
Before the element itself (i.e., after element's previous sibling)
+ +
"afterbegin"
+
Just inside the element, before its first child.
+ +
"beforeend"
+
Just inside the element, after its last child.
+ +
"afterend"
+
After the element itself (i.e., before element's next sibling)
+
+ +

Throws a "SyntaxError" DOMException if the arguments + have invalid values (e.g., in the case of an XML document, + if the given string is not well-formed).

+ +

Throws a "NoModificationAllowedError" DOMException + if the given position isn't possible (e.g. inserting elements after the root element of a + Document).

+
+
+ +

This method performs no sanitization to remove potentially-dangerous elements + and attributes like script or event handler content attributes.

+ +
+ +

Element's insertAdjacentHTML(position, + string) method steps are:

+ +
    +
  1. Let context be null.

  2. + +
  3. Use the first matching item from this list:

    +
    +
    If position is an ASCII case-insensitive match for the string "beforebegin"
    +
    If position is an ASCII case-insensitive match for the string "afterend"
    +
    +
      +
    1. Set context to this's parent.

    2. + +
    3. If context is null or a Document, throw a + "NoModificationAllowedError" DOMException.

    4. +
    +
    + +
    If position is an ASCII case-insensitive match for the string "afterbegin"
    +
    If position is an ASCII case-insensitive match for the string "beforeend"
    +
    Set context to this.
    + +
    Otherwise
    +

    Throw a "SyntaxError" DOMException.

    +
    +
  4. + +
  5. +

    If context is not an Element or all of the following are true:

    + +
      +
    • context's node document is an HTML document;

    • +
    • context's local name is + "html"; and

    • +
    • context's namespace is the + HTML namespace,

    • +
    + +

    set context to the result of creating an + element given this's node document, body, and + the HTML namespace.

    +
  6. + +
  7. +

    Let fragment be the result of invoking the fragment parsing algorithm + steps with context and string.

    +
  8. + +
  9. Use the first matching item from this list: +
    +
    If position is an ASCII case-insensitive match for the string "beforebegin"
    +
    +

    Insert fragment into + this's parent before this.

    +
    + +
    If position is an ASCII case-insensitive match for the string "afterend"
    +
    +

    Insert fragment into + this before its first child.

    +
    + +
    If position is an ASCII case-insensitive match for the string "afterbegin"
    +
    +

    Append fragment to + this.

    +
    + +
    If position is an ASCII case-insensitive match for the string "beforeend"
    +
    +

    Insert fragment into + this's parent before this's + next sibling.

    +
    +
    +
  10. +
+ +

As with other direct Node-manipulation APIs (and unlike innerHTML), insertAdjacentHTML() does not include any special + handling for template elements. In most cases you will want to use templateEl.content.insertAdjacentHTML() instead of directly + manipulating the child nodes of a template element.

+ +
+

Timers

The setTimeout() and