Changeset 204150 in webkit
- Timestamp:
- Aug 4, 2016, 3:43:50 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r204148 r204150 1 2016-08-04 Chris Dumez <cdumez@apple.com> 2 3 Move insertAdjacent*() API from HTMLElement to Element 4 https://bugs.webkit.org/show_bug.cgi?id=160567 5 6 Reviewed by Sam Weinig. 7 8 Rebaseline several tests to reflect behavior change. 9 10 * fast/dom/HTMLElement/insertAdjacentHTML-errors-expected.txt: 11 * fast/dom/HTMLElement/script-tests/insertAdjacentHTML-errors.js: 12 * fast/dynamic/insertAdjacentElement-expected.txt: 13 1 14 2016-08-04 Benjamin Poulain <benjamin@webkit.org> 2 15 -
trunk/LayoutTests/fast/dom/HTMLElement/insertAdjacentHTML-errors-expected.txt
r203333 r204150 4 4 5 5 6 PASS div.insertAdjacentHTML('beforeBegin', 'text') is undefined.7 PASS div.insertAdjacentHTML('afterEnd', 'text') is undefined.6 PASS div.insertAdjacentHTML('beforeBegin', 'text') threw exception NoModificationAllowedError (DOM Exception 7): The object can not be modified.. 7 PASS div.insertAdjacentHTML('afterEnd', 'text') threw exception NoModificationAllowedError (DOM Exception 7): The object can not be modified.. 8 8 PASS div.insertAdjacentHTML('FOO', 'text') threw exception SyntaxError (DOM Exception 12): The string did not match the expected pattern.. 9 9 PASS document.documentElement.insertAdjacentHTML('afterEnd', 'text') threw exception NoModificationAllowedError (DOM Exception 7): The object can not be modified.. -
trunk/LayoutTests/fast/dom/HTMLElement/script-tests/insertAdjacentHTML-errors.js
r203333 r204150 3 3 var div = document.createElement("div"); 4 4 5 should BeUndefined("div.insertAdjacentHTML('beforeBegin', 'text')");6 should BeUndefined("div.insertAdjacentHTML('afterEnd', 'text')");5 shouldThrow("div.insertAdjacentHTML('beforeBegin', 'text')"); 6 shouldThrow("div.insertAdjacentHTML('afterEnd', 'text')"); 7 7 8 8 shouldThrow("div.insertAdjacentHTML('FOO', 'text')", '"SyntaxError (DOM Exception 12): The string did not match the expected pattern."'); -
trunk/LayoutTests/fast/dynamic/insertAdjacentElement-expected.txt
r204122 r204150 1 1 Caught expected exception: SyntaxError (DOM Exception 12): The string did not match the expected pattern. 2 Caught expected exception: TypeError: Argument 2 ('element') to HTMLElement.insertAdjacentElement must be an instance of Element2 Caught expected exception: TypeError: Argument 2 ('element') to Element.insertAdjacentElement must be an instance of Element 3 3 1 (black) 2 (green) 3 (green) 4 (black) 4 4 -
trunk/LayoutTests/imported/w3c/ChangeLog
r204126 r204150 1 2016-08-04 Chris Dumez <cdumez@apple.com> 2 3 Move insertAdjacent*() API from HTMLElement to Element 4 https://bugs.webkit.org/show_bug.cgi?id=160567 5 6 Reviewed by Sam Weinig. 7 8 Rebaseline several W3C tests now that more checks are passing. 9 10 * web-platform-tests/dom/interfaces-expected.txt: 11 * web-platform-tests/domparsing/insert_adjacent_html-expected.txt: 12 1 13 2016-08-04 Chris Dumez <cdumez@apple.com> 2 14 -
trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt
r204126 r204150 765 765 PASS Element interface: operation getElementsByTagNameNS(DOMString,DOMString) 766 766 PASS Element interface: operation getElementsByClassName(DOMString) 767 FAIL Element interface: operation insertAdjacentElement(DOMString,Element) assert_own_property: interface prototype object missing non-static operation expected property "insertAdjacentElement" missing 768 FAIL Element interface: operation insertAdjacentText(DOMString,DOMString) assert_own_property: interface prototype object missing non-static operation expected property "insertAdjacentText" missing 767 PASS Element interface: operation insertAdjacentElement(DOMString,Element) 768 PASS Element interface: operation insertAdjacentText(DOMString,DOMString) 769 769 PASS Element interface: attribute children 770 770 PASS Element interface: attribute firstElementChild … … 836 836 PASS Element interface: element must inherit property "getElementsByClassName" with the proper type (31) 837 837 PASS Element interface: calling getElementsByClassName(DOMString) on element with too few arguments must throw TypeError 838 FAIL Element interface: element must inherit property "insertAdjacentElement" with the proper type (32) assert_inherits: property "insertAdjacentElement" not found in prototype chain 839 FAIL Element interface: calling insertAdjacentElement(DOMString,Element) on element with too few arguments must throw TypeError assert_inherits: property "insertAdjacentElement" not found in prototype chain 840 FAIL Element interface: element must inherit property "insertAdjacentText" with the proper type (33) assert_inherits: property "insertAdjacentText" not found in prototype chain 841 FAIL Element interface: calling insertAdjacentText(DOMString,DOMString) on element with too few arguments must throw TypeError assert_inherits: property "insertAdjacentText" not found in prototype chain 838 PASS Element interface: element must inherit property "insertAdjacentElement" with the proper type (32) 839 PASS Element interface: calling insertAdjacentElement(DOMString,Element) on element with too few arguments must throw TypeError 840 PASS Element interface: element must inherit property "insertAdjacentText" with the proper type (33) 841 PASS Element interface: calling insertAdjacentText(DOMString,DOMString) on element with too few arguments must throw TypeError 842 842 PASS Element interface: element must inherit property "children" with the proper type (34) 843 843 PASS Element interface: element must inherit property "firstElementChild" with the proper type (35) -
trunk/LayoutTests/imported/w3c/web-platform-tests/domparsing/insert_adjacent_html-expected.txt
r203164 r204150 9 9 PASS afterend content again, with next sibling 10 10 PASS Should throw when inserting with invalid position string 11 FAIL When the parent node is null, insertAdjacentHTML should throw for beforebegin and afterend (text) assert_throws: function "function () { element.insertAdjacentHTML("afterend", "") }" did not throw 12 FAIL When the parent node is null, insertAdjacentHTML should throw for beforebegin and afterend (comments) assert_throws: function "function () { element.insertAdjacentHTML("afterend", "<!-..." did not throw 13 FAIL When the parent node is null, insertAdjacentHTML should throw for beforebegin and afterend (elements) assert_throws: function "function () { element.insertAdjacentHTML("afterend", "<di..." did not throw 11 PASS When the parent node is null, insertAdjacentHTML should throw for beforebegin and afterend (text) 12 PASS When the parent node is null, insertAdjacentHTML should throw for beforebegin and afterend (comments) 13 PASS When the parent node is null, insertAdjacentHTML should throw for beforebegin and afterend (elements) 14 14 PASS When the parent node is a document, insertAdjacentHTML should throw for beforebegin and afterend (text) 15 15 PASS When the parent node is a document, insertAdjacentHTML should throw for beforebegin and afterend (comments) -
trunk/Source/WebCore/ChangeLog
r204149 r204150 1 2016-08-04 Chris Dumez <cdumez@apple.com> 2 3 Move insertAdjacent*() API from HTMLElement to Element 4 https://bugs.webkit.org/show_bug.cgi?id=160567 5 6 Reviewed by Sam Weinig. 7 8 Move insertAdjacent*() API from HTMLElement to Element: 9 - https://w3c.github.io/DOM-Parsing/#extensions-to-the-element-interface 10 - https://dom.spec.whatwg.org/#element 11 12 Firefox and Chrome both have insertAdjacentHTML() on Element. 13 Chrome has insertAdjacentText() / insertAdjacentElement() on Element as 14 well. Firefox does not have this API at all. 15 16 Also align insertAdjacentHTML() with the specification so that we 17 now throw a NO_MODIFICATION_ALLOWED_ERR if called with "beforebegin" / 18 "afterend" on a parent-less element. This is as per: 19 - https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml 20 21 Previously, WebKit would just silently ignore such calls. The new 22 behavior with consistent with both Firefox and Chrome. 23 24 No new tests, rebaselined existing tests. 25 26 * dom/Element.cpp: 27 (WebCore::Element::insertAdjacent): 28 (WebCore::Element::insertAdjacentElement): 29 (WebCore::contextElementForInsertion): 30 (WebCore::Element::insertAdjacentHTML): 31 (WebCore::Element::insertAdjacentText): 32 * dom/Element.h: 33 * dom/Element.idl: 34 * html/HTMLElement.cpp: 35 (WebCore::HTMLElement::insertAdjacent): Deleted. 36 (WebCore::HTMLElement::insertAdjacentElement): Deleted. 37 (WebCore::contextElementForInsertion): Deleted. 38 (WebCore::HTMLElement::insertAdjacentHTML): Deleted. 39 (WebCore::HTMLElement::insertAdjacentText): Deleted. 40 * html/HTMLElement.h: 41 * html/HTMLElement.idl: 42 1 43 2016-08-04 Anders Carlsson <andersca@apple.com> 2 44 -
trunk/Source/WebCore/dom/Element.cpp
r203852 r204150 3482 3482 } 3483 3483 3484 3485 Node* Element::insertAdjacent(const String& where, Ref<Node>&& newChild, ExceptionCode& ec) 3486 { 3487 // In Internet Explorer if the element has no parent and where is "beforeBegin" or "afterEnd", 3488 // a document fragment is created and the elements appended in the correct order. This document 3489 // fragment isn't returned anywhere. 3490 // 3491 // This is impossible for us to implement as the DOM tree does not allow for such structures, 3492 // Opera also appears to disallow such usage. 3493 3494 if (equalLettersIgnoringASCIICase(where, "beforebegin")) { 3495 ContainerNode* parent = this->parentNode(); 3496 return (parent && parent->insertBefore(newChild, this, ec)) ? newChild.ptr() : nullptr; 3497 } 3498 3499 if (equalLettersIgnoringASCIICase(where, "afterbegin")) 3500 return insertBefore(newChild, firstChild(), ec) ? newChild.ptr() : nullptr; 3501 3502 if (equalLettersIgnoringASCIICase(where, "beforeend")) 3503 return appendChild(newChild, ec) ? newChild.ptr() : nullptr; 3504 3505 if (equalLettersIgnoringASCIICase(where, "afterend")) { 3506 ContainerNode* parent = this->parentNode(); 3507 return (parent && parent->insertBefore(newChild, nextSibling(), ec)) ? newChild.ptr() : nullptr; 3508 } 3509 3510 ec = SYNTAX_ERR; 3511 return nullptr; 3512 } 3513 3514 Element* Element::insertAdjacentElement(const String& where, Element& newChild, ExceptionCode& ec) 3515 { 3516 Node* returnValue = insertAdjacent(where, newChild, ec); 3517 ASSERT_WITH_SECURITY_IMPLICATION(!returnValue || is<Element>(*returnValue)); 3518 return downcast<Element>(returnValue); 3519 } 3520 3521 // Step 1 of https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml. 3522 static Element* contextElementForInsertion(const String& where, Element* element, ExceptionCode& ec) 3523 { 3524 if (equalLettersIgnoringASCIICase(where, "beforebegin") || equalLettersIgnoringASCIICase(where, "afterend")) { 3525 auto* parent = element->parentElement(); 3526 if (!parent) { 3527 ec = NO_MODIFICATION_ALLOWED_ERR; 3528 return nullptr; 3529 } 3530 return parent; 3531 } 3532 if (equalLettersIgnoringASCIICase(where, "afterbegin") || equalLettersIgnoringASCIICase(where, "beforeend")) 3533 return element; 3534 ec = SYNTAX_ERR; 3535 return nullptr; 3536 } 3537 3538 void Element::insertAdjacentHTML(const String& where, const String& markup, ExceptionCode& ec) 3539 { 3540 Element* contextElement = contextElementForInsertion(where, this, ec); 3541 if (!contextElement) 3542 return; 3543 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(*contextElement, markup, AllowScriptingContent, ec); 3544 if (!fragment) 3545 return; 3546 insertAdjacent(where, fragment.releaseNonNull(), ec); 3547 } 3548 3549 void Element::insertAdjacentText(const String& where, const String& text, ExceptionCode& ec) 3550 { 3551 insertAdjacent(where, document().createTextNode(text), ec); 3552 } 3553 3484 3554 } // namespace WebCore -
trunk/Source/WebCore/dom/Element.h
r203852 r204150 296 296 virtual Element* focusDelegate(); 297 297 298 Element* insertAdjacentElement(const String& where, Element& newChild, ExceptionCode&); 299 void insertAdjacentHTML(const String& where, const String& html, ExceptionCode&); 300 void insertAdjacentText(const String& where, const String& text, ExceptionCode&); 301 298 302 const RenderStyle* computedStyle(PseudoId = NOPSEUDO) override; 299 303 … … 591 595 void updateLabel(TreeScope&, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue); 592 596 597 Node* insertAdjacent(const String& where, Ref<Node>&& newChild, ExceptionCode&); 598 593 599 void scrollByUnits(int units, ScrollGranularity); 594 600 -
trunk/Source/WebCore/dom/Element.idl
r204131 r204150 144 144 #endif 145 145 146 [RaisesException] Element insertAdjacentElement(DOMString where, Element element); 147 [RaisesException] void insertAdjacentHTML(DOMString where, DOMString html); 148 [RaisesException] void insertAdjacentText(DOMString where, DOMString text); 149 146 150 [Conditional=POINTER_LOCK] void requestPointerLock(); 147 151 -
trunk/Source/WebCore/html/HTMLElement.cpp
r204122 r204150 631 631 } 632 632 633 Node* HTMLElement::insertAdjacent(const String& where, Ref<Node>&& newChild, ExceptionCode& ec)634 {635 // In Internet Explorer if the element has no parent and where is "beforeBegin" or "afterEnd",636 // a document fragment is created and the elements appended in the correct order. This document637 // fragment isn't returned anywhere.638 //639 // This is impossible for us to implement as the DOM tree does not allow for such structures,640 // Opera also appears to disallow such usage.641 642 if (equalLettersIgnoringASCIICase(where, "beforebegin")) {643 ContainerNode* parent = this->parentNode();644 return (parent && parent->insertBefore(newChild, this, ec)) ? newChild.ptr() : nullptr;645 }646 647 if (equalLettersIgnoringASCIICase(where, "afterbegin"))648 return insertBefore(newChild, firstChild(), ec) ? newChild.ptr() : nullptr;649 650 if (equalLettersIgnoringASCIICase(where, "beforeend"))651 return appendChild(newChild, ec) ? newChild.ptr() : nullptr;652 653 if (equalLettersIgnoringASCIICase(where, "afterend")) {654 ContainerNode* parent = this->parentNode();655 return (parent && parent->insertBefore(newChild, nextSibling(), ec)) ? newChild.ptr() : nullptr;656 }657 658 ec = SYNTAX_ERR;659 return nullptr;660 }661 662 Element* HTMLElement::insertAdjacentElement(const String& where, Element& newChild, ExceptionCode& ec)663 {664 Node* returnValue = insertAdjacent(where, newChild, ec);665 ASSERT_WITH_SECURITY_IMPLICATION(!returnValue || is<Element>(*returnValue));666 return downcast<Element>(returnValue);667 }668 669 // Step 3 of http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in-html-documents.html#insertadjacenthtml()670 static Element* contextElementForInsertion(const String& where, Element* element, ExceptionCode& ec)671 {672 if (equalLettersIgnoringASCIICase(where, "beforebegin") || equalLettersIgnoringASCIICase(where, "afterend")) {673 ContainerNode* parent = element->parentNode();674 if (parent && !is<Element>(*parent)) {675 ec = NO_MODIFICATION_ALLOWED_ERR;676 return nullptr;677 }678 ASSERT_WITH_SECURITY_IMPLICATION(!parent || is<Element>(*parent));679 return downcast<Element>(parent);680 }681 if (equalLettersIgnoringASCIICase(where, "afterbegin") || equalLettersIgnoringASCIICase(where, "beforeend"))682 return element;683 ec = SYNTAX_ERR;684 return nullptr;685 }686 687 void HTMLElement::insertAdjacentHTML(const String& where, const String& markup, ExceptionCode& ec)688 {689 Element* contextElement = contextElementForInsertion(where, this, ec);690 if (!contextElement)691 return;692 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(*contextElement, markup, AllowScriptingContent, ec);693 if (!fragment)694 return;695 insertAdjacent(where, fragment.releaseNonNull(), ec);696 }697 698 void HTMLElement::insertAdjacentText(const String& where, const String& text, ExceptionCode& ec)699 {700 insertAdjacent(where, document().createTextNode(text), ec);701 }702 703 633 void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment, MutableStyleProperties& style) 704 634 { -
trunk/Source/WebCore/html/HTMLElement.h
r200448 r204150 49 49 void setInnerText(const String&, ExceptionCode&); 50 50 void setOuterText(const String&, ExceptionCode&); 51 52 Element* insertAdjacentElement(const String& where, Element& newChild, ExceptionCode&);53 void insertAdjacentHTML(const String& where, const String& html, ExceptionCode&);54 void insertAdjacentText(const String& where, const String& text, ExceptionCode&);55 51 56 52 virtual bool hasCustomFocusLogic() const; … … 131 127 virtual HTMLFormElement* virtualForm() const; 132 128 133 Node* insertAdjacent(const String& where, Ref<Node>&& newChild, ExceptionCode&);134 129 Ref<DocumentFragment> textToFragment(const String&, ExceptionCode&); 135 130 -
trunk/Source/WebCore/html/HTMLElement.idl
r203803 r204150 45 45 [TreatNullAs=EmptyString, SetterRaisesException] attribute DOMString outerText; 46 46 47 [RaisesException] Element insertAdjacentElement(DOMString where, Element element);48 49 [RaisesException] void insertAdjacentHTML(DOMString where, DOMString html);50 [RaisesException] void insertAdjacentText(DOMString where, DOMString text);51 52 47 [SetterRaisesException] attribute DOMString contentEditable; 53 48 readonly attribute boolean isContentEditable;
Note:
See TracChangeset
for help on using the changeset viewer.