+2015-09-10 Chris Dumez <cdumez@apple.com>
+
+ Node.appendChild(null) / replaceChild(null, null) / removeChild(null) / insertBefore(null, ref) should throw a TypeError
+ https://bugs.webkit.org/show_bug.cgi?id=148971
+ <rdar://problem/22560883>
+ <rdar://problem/22559225>
+
+ Reviewed by Ryosuke Niwa.
+
+ Update / rebaseline tests now that we throw a different exception type.
+
+ * fast/dom/Document/replaceChild-null-oldChild-expected.txt:
+ * fast/dom/Document/script-tests/replaceChild-null-oldChild.js:
+ * fast/dom/Node/fragment-mutation-expected.txt:
+ * fast/dom/Node/fragment-mutation.html:
+ * fast/dom/incompatible-operations-expected.txt:
+ * fast/dom/incompatible-operations.html:
+ * fast/dom/move-nodes-across-documents.html:
+ * fast/dom/processing-instruction-appendChild-exceptions-expected.txt:
+ * fast/dom/processing-instruction-appendChild-exceptions.xhtml:
+ * fast/dom/setter-type-enforcement-expected.txt:
+ * fast/dom/timer-clear-interval-in-handler-and-generate-error-expected.txt:
+ * fast/inspector-support/uncaught-dom8-exception.html:
+
2015-09-10 Brady Eidson <beidson@apple.com>
Mark some more W3C IDB tests as flaky.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-PASS document.replaceChild(document.firstChild, null) threw exception Error: NotFoundError: DOM Exception 8.
+PASS document.replaceChild(document.firstChild, null) threw exception TypeError: Type error.
PASS successfullyParsed is true
TEST COMPLETE
description('Test behavior of Document.replaceChild() when oldChild is null.');
-shouldThrow('document.replaceChild(document.firstChild, null)', '"Error: NotFoundError: DOM Exception 8"');
+shouldThrow('document.replaceChild(document.firstChild, null)', '"TypeError: Type error"');
Inserting an element in front of the next item in fragment should not affect the result: PASS
Appending an element at the end of the fragment should not affect the result: PASS
-Continually re-appending removed element to the fragment should eventually throw NOT_FOUND_ERR: PASS
+Continually re-appending removed element to the fragment should eventually throw a TypeError: PASS
This test creates a fragment containing three elements: "B", "U", and "P", attempts to insertBefore this fragment and studies effects of mutation events on the fragment.
Inserting an element in front of the next item in fragment should not affect the result: PASS
Appending an element at the end of the fragment should not affect the result: PASS
-Continually re-appending removed element to the fragment should eventually throw NOT_FOUND_ERR: PASS
+Continually re-appending removed element to the fragment should eventually throw a TypeError: PASS
return result;
}
-function expectException(code)
+function expectTypeError()
{
return function(stash, exception) {
if (!exception)
- return "FAIL, expected exception with code " + code + ". The resulting fragment was: \"" + produceNodeNameString(stash) + "\".";
+ return "FAIL, expected TypeError. The resulting fragment was: \"" + produceNodeNameString(stash) + "\".";
- if (code == exception.code)
+ if (exception.name = "TypeError")
return "PASS";
- return "FAIL, expected exception code: " + code + ", was: " + exception + ".";
+ return "FAIL, expected TypeError, was: " + exception.name + ".";
}
}
frag.appendChild(extra);
}, expectNodes("BUP"));
- testFragment(method, "Continually re-appending removed element to the fragment should eventually throw NOT_FOUND_ERR", function(evt, frag, stash)
+ testFragment(method, "Continually re-appending removed element to the fragment should eventually throw a TypeError", function(evt, frag, stash)
{
stash.insertBefore(frag.lastChild, stash.firstChild);
- }, expectException(8), true);
+ }, expectTypeError(), true);
printLog(methodName);
}
function runTests()
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-PASS aNode.appendChild(aDOMImplementation) threw exception Error: NotFoundError: DOM Exception 8.
-PASS aNode.appendChild('knort') threw exception Error: NotFoundError: DOM Exception 8.
-PASS aNode.appendChild(void 0) threw exception Error: NotFoundError: DOM Exception 8.
+PASS aNode.appendChild(aDOMImplementation) threw exception TypeError: Type error.
+PASS aNode.appendChild('knort') threw exception TypeError: Type error.
+PASS aNode.appendChild(void 0) threw exception TypeError: Type error.
PASS aNode.isSameNode(aDOMImplementation) is false
PASS aNode.isSameNode('foo') is false
PASS aNode.isSameNode(void 0) is false
var aSecondNode = document.createElement("div");
aNode.appendChild(aSecondNode);
-shouldThrow("aNode.appendChild(aDOMImplementation)", "'Error: NotFoundError: DOM Exception 8'");
+shouldThrow("aNode.appendChild(aDOMImplementation)", "'TypeError: Type error'");
-shouldThrow("aNode.appendChild('knort')", "'Error: NotFoundError: DOM Exception 8'");
+shouldThrow("aNode.appendChild('knort')", "'TypeError: Type error'");
-shouldThrow("aNode.appendChild(void 0)", "'Error: NotFoundError: DOM Exception 8'");
+shouldThrow("aNode.appendChild(void 0)", "'TypeError: Type error'");
shouldBeFalse("aNode.isSameNode(aDOMImplementation)");
shouldBeFalse("aNode.isSameNode('foo')");
runTest(function() {
iframeDoc.appendChild(document.doctype);
console.log(document.doctype);
- }, 'NotFoundError');
+ }, 'TypeError');
// When setting a boundary of the range in a different
// document, the call should succeed and the range should be collapsed.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-PASS pi.appendChild(null) threw exception Error: HierarchyRequestError: DOM Exception 3.
+PASS pi.appendChild(null) threw exception TypeError: Type error.
PASS pi.appendChild(div) threw exception Error: HierarchyRequestError: DOM Exception 3.
PASS pi.appendChild(textNode) threw exception Error: HierarchyRequestError: DOM Exception 3.
PASS successfullyParsed is true
<![CDATA[
description("Test that appropriate exceptions are thrown when adding children to a ProcessingInstruction.");
var pi = document.createProcessingInstruction('target', 'data');
-shouldThrow("pi.appendChild(null)", "'Error: HierarchyRequestError: DOM Exception 3'");
+shouldThrow("pi.appendChild(null)", "'TypeError: Type error'");
var div = document.createElement('div');
shouldThrow("pi.appendChild(div)", "'Error: HierarchyRequestError: DOM Exception 3'");
var textNode = document.createTextNode('sometext');
-CONSOLE MESSAGE: line 10: NotFoundError: DOM Exception 8: An attempt was made to reference a Node in a context where it does not exist.
+CONSOLE MESSAGE: line 10: TypeError: Type error
-CONSOLE MESSAGE: line 34: NotFoundError: DOM Exception 8: An attempt was made to reference a Node in a context where it does not exist.
-CONSOLE MESSAGE: line 34: NotFoundError: DOM Exception 8: An attempt was made to reference a Node in a context where it does not exist.
+CONSOLE MESSAGE: line 34: TypeError: Type error
+CONSOLE MESSAGE: line 34: TypeError: Type error
PASS. DRT didn't crash.
{
if (window.testRunner)
testRunner.dumpAsText();
- document.appendChild();
+ document.body.removeAttributeNode(document.createAttribute("doesNotExist"));
}
</script>
+2015-09-10 Chris Dumez <cdumez@apple.com>
+
+ Node.appendChild(null) / replaceChild(null, null) / removeChild(null) / insertBefore(null, ref) should throw a TypeError
+ https://bugs.webkit.org/show_bug.cgi?id=148971
+ <rdar://problem/22560883>
+ <rdar://problem/22559225>
+
+ Reviewed by Ryosuke Niwa.
+
+ Rebaseline W3C tests now that more checks are passing.
+
+ * web-platform-tests/dom/interfaces-expected.txt:
+ * web-platform-tests/dom/nodes/Node-appendChild-expected.txt:
+ * web-platform-tests/dom/nodes/Node-insertBefore-expected.txt:
+ * web-platform-tests/dom/nodes/Node-removeChild-expected.txt:
+ * web-platform-tests/dom/nodes/Node-replaceChild-expected.txt:
+ * web-platform-tests/html/dom/interfaces-expected.txt:
+
2015-09-09 Dewei Zhu <dewei_zhu@apple.com>
Document.characterSet should return "UTF-8" by default.
[native code]
}" did not throw
PASS Node interface: xmlDoc must inherit property "insertBefore" with the proper type (40)
-FAIL Node interface: calling insertBefore(Node,Node) on xmlDoc with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
+FAIL Node interface: calling insertBefore(Node,Node) on xmlDoc with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
[native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
PASS Node interface: xmlDoc must inherit property "appendChild" with the proper type (41)
-FAIL Node interface: calling appendChild(Node) on xmlDoc with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling appendChild(Node) on xmlDoc with too few arguments must throw TypeError
PASS Node interface: xmlDoc must inherit property "replaceChild" with the proper type (42)
-FAIL Node interface: calling replaceChild(Node,Node) on xmlDoc with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" did not throw
+PASS Node interface: calling replaceChild(Node,Node) on xmlDoc with too few arguments must throw TypeError
PASS Node interface: xmlDoc must inherit property "removeChild" with the proper type (43)
-FAIL Node interface: calling removeChild(Node) on xmlDoc with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling removeChild(Node) on xmlDoc with too few arguments must throw TypeError
PASS EventTarget interface: xmlDoc must inherit property "addEventListener" with the proper type (0)
FAIL EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on xmlDoc with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
[native code]
[native code]
}" did not throw
PASS Node interface: document.createDocumentFragment() must inherit property "insertBefore" with the proper type (40)
-FAIL Node interface: calling insertBefore(Node,Node) on document.createDocumentFragment() with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
+FAIL Node interface: calling insertBefore(Node,Node) on document.createDocumentFragment() with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
[native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+}" did not throw
PASS Node interface: document.createDocumentFragment() must inherit property "appendChild" with the proper type (41)
-FAIL Node interface: calling appendChild(Node) on document.createDocumentFragment() with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling appendChild(Node) on document.createDocumentFragment() with too few arguments must throw TypeError
PASS Node interface: document.createDocumentFragment() must inherit property "replaceChild" with the proper type (42)
-FAIL Node interface: calling replaceChild(Node,Node) on document.createDocumentFragment() with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" did not throw
+PASS Node interface: calling replaceChild(Node,Node) on document.createDocumentFragment() with too few arguments must throw TypeError
PASS Node interface: document.createDocumentFragment() must inherit property "removeChild" with the proper type (43)
-FAIL Node interface: calling removeChild(Node) on document.createDocumentFragment() with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling removeChild(Node) on document.createDocumentFragment() with too few arguments must throw TypeError
PASS EventTarget interface: document.createDocumentFragment() must inherit property "addEventListener" with the proper type (0)
FAIL EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on document.createDocumentFragment() with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
[native code]
[native code]
}" did not throw
PASS Node interface: document.doctype must inherit property "insertBefore" with the proper type (40)
-FAIL Node interface: calling insertBefore(Node,Node) on document.doctype with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
+FAIL Node interface: calling insertBefore(Node,Node) on document.doctype with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
[native code]
}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
PASS Node interface: document.doctype must inherit property "appendChild" with the proper type (41)
-FAIL Node interface: calling appendChild(Node) on document.doctype with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling appendChild(Node) on document.doctype with too few arguments must throw TypeError
PASS Node interface: document.doctype must inherit property "replaceChild" with the proper type (42)
-FAIL Node interface: calling replaceChild(Node,Node) on document.doctype with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling replaceChild(Node,Node) on document.doctype with too few arguments must throw TypeError
PASS Node interface: document.doctype must inherit property "removeChild" with the proper type (43)
-FAIL Node interface: calling removeChild(Node) on document.doctype with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling removeChild(Node) on document.doctype with too few arguments must throw TypeError
PASS EventTarget interface: document.doctype must inherit property "addEventListener" with the proper type (0)
FAIL EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on document.doctype with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
[native code]
[native code]
}" did not throw
PASS Node interface: element must inherit property "insertBefore" with the proper type (40)
-FAIL Node interface: calling insertBefore(Node,Node) on element with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
+FAIL Node interface: calling insertBefore(Node,Node) on element with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
[native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+}" did not throw
PASS Node interface: element must inherit property "appendChild" with the proper type (41)
-FAIL Node interface: calling appendChild(Node) on element with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling appendChild(Node) on element with too few arguments must throw TypeError
PASS Node interface: element must inherit property "replaceChild" with the proper type (42)
-FAIL Node interface: calling replaceChild(Node,Node) on element with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" did not throw
+PASS Node interface: calling replaceChild(Node,Node) on element with too few arguments must throw TypeError
PASS Node interface: element must inherit property "removeChild" with the proper type (43)
-FAIL Node interface: calling removeChild(Node) on element with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling removeChild(Node) on element with too few arguments must throw TypeError
PASS EventTarget interface: element must inherit property "addEventListener" with the proper type (0)
FAIL EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on element with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
[native code]
[native code]
}" did not throw
PASS Node interface: document.createTextNode("abc") must inherit property "insertBefore" with the proper type (40)
-FAIL Node interface: calling insertBefore(Node,Node) on document.createTextNode("abc") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
+FAIL Node interface: calling insertBefore(Node,Node) on document.createTextNode("abc") with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
[native code]
}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
PASS Node interface: document.createTextNode("abc") must inherit property "appendChild" with the proper type (41)
-FAIL Node interface: calling appendChild(Node) on document.createTextNode("abc") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling appendChild(Node) on document.createTextNode("abc") with too few arguments must throw TypeError
PASS Node interface: document.createTextNode("abc") must inherit property "replaceChild" with the proper type (42)
-FAIL Node interface: calling replaceChild(Node,Node) on document.createTextNode("abc") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling replaceChild(Node,Node) on document.createTextNode("abc") with too few arguments must throw TypeError
PASS Node interface: document.createTextNode("abc") must inherit property "removeChild" with the proper type (43)
-FAIL Node interface: calling removeChild(Node) on document.createTextNode("abc") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling removeChild(Node) on document.createTextNode("abc") with too few arguments must throw TypeError
PASS EventTarget interface: document.createTextNode("abc") must inherit property "addEventListener" with the proper type (0)
FAIL EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on document.createTextNode("abc") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
[native code]
[native code]
}" did not throw
PASS Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "insertBefore" with the proper type (40)
-FAIL Node interface: calling insertBefore(Node,Node) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
+FAIL Node interface: calling insertBefore(Node,Node) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
[native code]
}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
PASS Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "appendChild" with the proper type (41)
-FAIL Node interface: calling appendChild(Node) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling appendChild(Node) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError
PASS Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "replaceChild" with the proper type (42)
-FAIL Node interface: calling replaceChild(Node,Node) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling replaceChild(Node,Node) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError
PASS Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "removeChild" with the proper type (43)
-FAIL Node interface: calling removeChild(Node) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling removeChild(Node) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError
PASS EventTarget interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "addEventListener" with the proper type (0)
FAIL EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on xmlDoc.createProcessingInstruction("abc", "def") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
[native code]
[native code]
}" did not throw
PASS Node interface: document.createComment("abc") must inherit property "insertBefore" with the proper type (40)
-FAIL Node interface: calling insertBefore(Node,Node) on document.createComment("abc") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
+FAIL Node interface: calling insertBefore(Node,Node) on document.createComment("abc") with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
[native code]
}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
PASS Node interface: document.createComment("abc") must inherit property "appendChild" with the proper type (41)
-FAIL Node interface: calling appendChild(Node) on document.createComment("abc") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling appendChild(Node) on document.createComment("abc") with too few arguments must throw TypeError
PASS Node interface: document.createComment("abc") must inherit property "replaceChild" with the proper type (42)
-FAIL Node interface: calling replaceChild(Node,Node) on document.createComment("abc") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling replaceChild(Node,Node) on document.createComment("abc") with too few arguments must throw TypeError
PASS Node interface: document.createComment("abc") must inherit property "removeChild" with the proper type (43)
-FAIL Node interface: calling removeChild(Node) on document.createComment("abc") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling removeChild(Node) on document.createComment("abc") with too few arguments must throw TypeError
PASS EventTarget interface: document.createComment("abc") must inherit property "addEventListener" with the proper type (0)
FAIL EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on document.createComment("abc") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
[native code]
-FAIL WebIDL tests assert_throws: function "function () { document.body.appendChild(null) }" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS WebIDL tests
PASS Appending to a leaf node.
-FAIL Appending null to a text node assert_throws: function "function () { node.appendChild(null) }" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Appending null to a text node
PASS Appending to a text node
-FAIL Appending null to a comment assert_throws: function "function () { node.appendChild(null) }" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Appending null to a comment
PASS Appending to a comment
-FAIL Appending null to a doctype assert_throws: function "function () { node.appendChild(null) }" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Appending null to a doctype
PASS Appending to a doctype
PASS Appending a document
PASS Adopting an orphan
-FAIL Calling insertBefore with a non-Node first argument must throw TypeError. assert_throws: function "function () { document.body.insertBefore(null, null) }" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
-FAIL Calling insertBefore with a non-Node first argument on a leaf node DocumentType must throw TypeError. assert_throws: function "function () { node.insertBefore(null, null) }" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Calling insertBefore with a non-Node first argument must throw TypeError.
+PASS Calling insertBefore with a non-Node first argument on a leaf node DocumentType must throw TypeError.
PASS Calling insertBefore an a leaf node DocumentType must throw HIERARCHY_REQUEST_ERR.
-FAIL Calling insertBefore with a non-Node first argument on a leaf node Text must throw TypeError. assert_throws: function "function () { node.insertBefore(null, null) }" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Calling insertBefore with a non-Node first argument on a leaf node Text must throw TypeError.
PASS Calling insertBefore an a leaf node Text must throw HIERARCHY_REQUEST_ERR.
-FAIL Calling insertBefore with a non-Node first argument on a leaf node Comment must throw TypeError. assert_throws: function "function () { node.insertBefore(null, null) }" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Calling insertBefore with a non-Node first argument on a leaf node Comment must throw TypeError.
PASS Calling insertBefore an a leaf node Comment must throw HIERARCHY_REQUEST_ERR.
-FAIL Calling insertBefore with a non-Node first argument on a leaf node ProcessingInstruction must throw TypeError. assert_throws: function "function () { node.insertBefore(null, null) }" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
+PASS Calling insertBefore with a non-Node first argument on a leaf node ProcessingInstruction must throw TypeError.
PASS Calling insertBefore an a leaf node ProcessingInstruction must throw HIERARCHY_REQUEST_ERR.
PASS Calling insertBefore with an inclusive ancestor of the context object must throw HIERARCHY_REQUEST_ERR.
PASS Calling insertBefore with a reference child whose parent is not the context node must throw a NotFoundError.
PASS Passing a detached comment from a synthetic document to removeChild should not affect it.
PASS Passing a non-detached comment from a synthetic document to removeChild should not affect it.
PASS Calling removeChild on a comment from a synthetic document with no children should throw NOT_FOUND_ERR.
-FAIL Passing a value that is not a Node reference to removeChild should throw TypeError. assert_throws: function "function () { document.body.removeChild(null) }" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Passing a value that is not a Node reference to removeChild should throw TypeError.
b
-FAIL Passing null to replaceChild should throw a TypeError. assert_throws: function "function () {
- a.replaceChild(null, null);
- }" did not throw
+PASS Passing null to replaceChild should throw a TypeError.
FAIL If child's parent is not the context node, a NotFoundError exception should be thrown assert_throws: function "function () {
a.replaceChild(a, c);
}" threw object "Error: HierarchyRequestError: DOM Exception 3" that is not a DOMException NotFoundError: property "code" is equal to 3, expected 8
[native code]
}" did not throw
PASS Node interface: iframe.contentDocument must inherit property "insertBefore" with the proper type (40)
-FAIL Node interface: calling insertBefore(Node,Node) on iframe.contentDocument with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
+FAIL Node interface: calling insertBefore(Node,Node) on iframe.contentDocument with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
[native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
PASS Node interface: iframe.contentDocument must inherit property "appendChild" with the proper type (41)
-FAIL Node interface: calling appendChild(Node) on iframe.contentDocument with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling appendChild(Node) on iframe.contentDocument with too few arguments must throw TypeError
PASS Node interface: iframe.contentDocument must inherit property "replaceChild" with the proper type (42)
-FAIL Node interface: calling replaceChild(Node,Node) on iframe.contentDocument with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" did not throw
+PASS Node interface: calling replaceChild(Node,Node) on iframe.contentDocument with too few arguments must throw TypeError
PASS Node interface: iframe.contentDocument must inherit property "removeChild" with the proper type (43)
-FAIL Node interface: calling removeChild(Node) on iframe.contentDocument with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling removeChild(Node) on iframe.contentDocument with too few arguments must throw TypeError
PASS EventTarget interface: iframe.contentDocument must inherit property "addEventListener" with the proper type (0)
FAIL EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on iframe.contentDocument with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
[native code]
[native code]
}" did not throw
PASS Node interface: document.implementation.createDocument(null, "", null) must inherit property "insertBefore" with the proper type (40)
-FAIL Node interface: calling insertBefore(Node,Node) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
+FAIL Node interface: calling insertBefore(Node,Node) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
[native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+}" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
PASS Node interface: document.implementation.createDocument(null, "", null) must inherit property "appendChild" with the proper type (41)
-FAIL Node interface: calling appendChild(Node) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling appendChild(Node) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError
PASS Node interface: document.implementation.createDocument(null, "", null) must inherit property "replaceChild" with the proper type (42)
-FAIL Node interface: calling replaceChild(Node,Node) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" did not throw
+PASS Node interface: calling replaceChild(Node,Node) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError
PASS Node interface: document.implementation.createDocument(null, "", null) must inherit property "removeChild" with the proper type (43)
-FAIL Node interface: calling removeChild(Node) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling removeChild(Node) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError
PASS EventTarget interface: document.implementation.createDocument(null, "", null) must inherit property "addEventListener" with the proper type (0)
FAIL EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
[native code]
[native code]
}" did not throw
PASS Node interface: document.createElement("noscript") must inherit property "insertBefore" with the proper type (40)
-FAIL Node interface: calling insertBefore(Node,Node) on document.createElement("noscript") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
+FAIL Node interface: calling insertBefore(Node,Node) on document.createElement("noscript") with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
[native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+}" did not throw
PASS Node interface: document.createElement("noscript") must inherit property "appendChild" with the proper type (41)
-FAIL Node interface: calling appendChild(Node) on document.createElement("noscript") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling appendChild(Node) on document.createElement("noscript") with too few arguments must throw TypeError
PASS Node interface: document.createElement("noscript") must inherit property "replaceChild" with the proper type (42)
-FAIL Node interface: calling replaceChild(Node,Node) on document.createElement("noscript") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" did not throw
+PASS Node interface: calling replaceChild(Node,Node) on document.createElement("noscript") with too few arguments must throw TypeError
PASS Node interface: document.createElement("noscript") must inherit property "removeChild" with the proper type (43)
-FAIL Node interface: calling removeChild(Node) on document.createElement("noscript") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
- [native code]
-}" threw object "Error: NotFoundError: DOM Exception 8" ("NotFoundError") expected object "TypeError" ("TypeError")
+PASS Node interface: calling removeChild(Node) on document.createElement("noscript") with too few arguments must throw TypeError
PASS EventTarget interface: document.createElement("noscript") must inherit property "addEventListener" with the proper type (0)
FAIL EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on document.createElement("noscript") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
[native code]
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-PASS (document.appendChild()).foobar() threw exception Error: NotFoundError: DOM Exception 8.
+PASS (document.appendChild()).foobar() threw exception TypeError: Type error.
PASS successfullyParsed is true
TEST COMPLETE
);
// Should be a DOM exception, not just some "TypeError: Null value".
-shouldThrow('(document.appendChild()).foobar()', '"Error: NotFoundError: DOM Exception 8"');
+shouldThrow('(document.appendChild()).foobar()', '"TypeError: Type error"');
+2015-09-10 Chris Dumez <cdumez@apple.com>
+
+ Node.appendChild(null) / replaceChild(null, null) / removeChild(null) / insertBefore(null, ref) should throw a TypeError
+ https://bugs.webkit.org/show_bug.cgi?id=148971
+ <rdar://problem/22560883>
+ <rdar://problem/22559225>
+
+ Reviewed by Ryosuke Niwa.
+
+ Node.appendChild(null) / replaceChild(null, null) / removeChild(null)
+ and insertBefore(null, ref) should throw a TypeError instead of a
+ NotFoundError, as per the specification:
+ https://dom.spec.whatwg.org/#node
+
+ The parameters are not nullable so the Web IDL specification says
+ we should throw a TypeError in this case.
+
+ This patch moves the null-checking from ContainerNode to the methods
+ on Node. The null-checking is supposed to be done by the bindings code
+ but our generator currently does not support this so we do the null
+ checking as close to the bindings as possible. The bindings code is
+ calling the methods on Node. This also makes sure we throw a TypeError
+ for null-argument when the Node is not a ContainerNode. For e.g.
+ Text.appendChild(null) should throw a TypeError too.
+
+ The methods on ContainerNode now take references insteaad of pointer
+ parameters now that the null-checking is done at the call site in
+ Node. This lead to a lot of code update as those methods are used
+ a lot throughout the code base.
+
+ No new tests, already covered by pre-existing layout tests.
+
2015-09-10 Daniel Bates <dabates@apple.com>
Write a test to ensure we don't regress processing of tasks when page defers loading
{
m_embedShadowElement = YouTubeEmbedShadowElement::create(m_parentElement->document());
- root->appendChild(m_embedShadowElement.get());
+ root->appendChild(*m_embedShadowElement);
- RefPtr<HTMLIFrameElement> iframeElement = HTMLIFrameElement::create(HTMLNames::iframeTag, m_parentElement->document());
+ Ref<HTMLIFrameElement> iframeElement = HTMLIFrameElement::create(HTMLNames::iframeTag, m_parentElement->document());
if (m_attributes.contains("width"))
iframeElement->setAttribute(HTMLNames::widthAttr, AtomicString("100%", AtomicString::ConstructFromLiteral));
// Disable frame flattening for this iframe.
iframeElement->setAttribute(HTMLNames::scrollingAttr, AtomicString("no", AtomicString::ConstructFromLiteral));
- m_embedShadowElement->appendChild(iframeElement);
+ m_embedShadowElement->appendChild(WTF::move(iframeElement));
return true;
}
- (DOMDocumentFragment *)createDocumentFragmentWithText:(NSString *)text
{
// FIXME: Since this is not a contextual fragment, it won't handle whitespace properly.
- return kit(createFragmentFromText(core(self)->createRange(), text).get());
+ return kit(createFragmentFromText(core(self)->createRange(), text).ptr());
}
@end
setValue(v, ec);
}
-RefPtr<Node> Attr::cloneNodeInternal(Document& targetDocument, CloningOperation)
+Ref<Node> Attr::cloneNodeInternal(Document& targetDocument, CloningOperation)
{
- RefPtr<Attr> clone = adoptRef(new Attr(targetDocument, qualifiedName(), value()));
- cloneChildNodes(clone.get());
- return clone.release();
+ Ref<Attr> clone = adoptRef(*new Attr(targetDocument, qualifiedName(), value()));
+ cloneChildNodes(clone);
+ return WTF::move(clone);
}
// DOM Section 1.1.1
virtual String nodeValue() const override { return value(); }
virtual void setNodeValue(const String&, ExceptionCode&) override;
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
virtual bool isAttributeNode() const override { return true; }
virtual bool childTypeAllowed(NodeType) const override;
return CDATA_SECTION_NODE;
}
-RefPtr<Node> CDATASection::cloneNodeInternal(Document& targetDocument, CloningOperation)
+Ref<Node> CDATASection::cloneNodeInternal(Document& targetDocument, CloningOperation)
{
return create(targetDocument, data());
}
virtual String nodeName() const override;
virtual NodeType nodeType() const override;
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
virtual bool childTypeAllowed(NodeType) const override;
virtual Ref<Text> virtualCreate(const String&) override;
};
return COMMENT_NODE;
}
-RefPtr<Node> Comment::cloneNodeInternal(Document& targetDocument, CloningOperation)
+Ref<Node> Comment::cloneNodeInternal(Document& targetDocument, CloningOperation)
{
return create(targetDocument, data());
}
virtual String nodeName() const override;
virtual NodeType nodeType() const override;
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
virtual bool childTypeAllowed(NodeType) const override;
};
if (!is<DocumentFragment>(node)) {
nodes.append(node);
if (ContainerNode* oldParent = node.parentNode())
- oldParent->removeChild(&node, ec);
+ oldParent->removeChild(node, ec);
return;
}
removeDetachedChildren();
}
-static inline bool isChildTypeAllowed(ContainerNode* newParent, Node* child)
+static inline bool isChildTypeAllowed(ContainerNode& newParent, Node& child)
{
- if (!child->isDocumentFragment())
- return newParent->childTypeAllowed(child->nodeType());
+ if (!child.isDocumentFragment())
+ return newParent.childTypeAllowed(child.nodeType());
- for (Node* node = child->firstChild(); node; node = node->nextSibling()) {
- if (!newParent->childTypeAllowed(node->nodeType()))
+ for (Node* node = child.firstChild(); node; node = node->nextSibling()) {
+ if (!newParent.childTypeAllowed(node->nodeType()))
return false;
}
return true;
#endif
}
-static inline bool containsConsideringHostElements(const Node* newChild, const Node* newParent)
+static inline bool containsConsideringHostElements(const Node& newChild, const Node& newParent)
{
- return (newParent->isInShadowTree() || isInTemplateContent(newParent))
- ? newChild->containsIncludingHostElements(newParent)
- : newChild->contains(newParent);
+ return (newParent.isInShadowTree() || isInTemplateContent(&newParent))
+ ? newChild.containsIncludingHostElements(&newParent)
+ : newChild.contains(&newParent);
}
-static inline ExceptionCode checkAcceptChild(ContainerNode* newParent, Node* newChild, Node* oldChild)
+static inline ExceptionCode checkAcceptChild(ContainerNode& newParent, Node& newChild, Node* oldChild)
{
- // Not mentioned in spec: throw NOT_FOUND_ERR if newChild is null
- if (!newChild)
- return NOT_FOUND_ERR;
-
// Use common case fast path if possible.
- if ((newChild->isElementNode() || newChild->isTextNode()) && newParent->isElementNode()) {
- ASSERT(!newParent->isReadOnlyNode());
- ASSERT(!newParent->isDocumentTypeNode());
+ if ((newChild.isElementNode() || newChild.isTextNode()) && newParent.isElementNode()) {
+ ASSERT(!newParent.isReadOnlyNode());
+ ASSERT(!newParent.isDocumentTypeNode());
ASSERT(isChildTypeAllowed(newParent, newChild));
if (containsConsideringHostElements(newChild, newParent))
return HIERARCHY_REQUEST_ERR;
}
// This should never happen, but also protect release builds from tree corruption.
- ASSERT(!newChild->isPseudoElement());
- if (newChild->isPseudoElement())
+ ASSERT(!newChild.isPseudoElement());
+ if (newChild.isPseudoElement())
return HIERARCHY_REQUEST_ERR;
- if (newParent->isReadOnlyNode())
+ if (newParent.isReadOnlyNode())
return NO_MODIFICATION_ALLOWED_ERR;
if (containsConsideringHostElements(newChild, newParent))
return HIERARCHY_REQUEST_ERR;
- if (oldChild && is<Document>(*newParent)) {
- if (!downcast<Document>(*newParent).canReplaceChild(newChild, oldChild))
+ if (oldChild && is<Document>(newParent)) {
+ if (!downcast<Document>(newParent).canReplaceChild(newChild, *oldChild))
return HIERARCHY_REQUEST_ERR;
} else if (!isChildTypeAllowed(newParent, newChild))
return HIERARCHY_REQUEST_ERR;
return 0;
}
-static inline bool checkAcceptChildGuaranteedNodeTypes(ContainerNode* newParent, Node* newChild, ExceptionCode& ec)
+static inline bool checkAcceptChildGuaranteedNodeTypes(ContainerNode& newParent, Node& newChild, ExceptionCode& ec)
{
- ASSERT(!newParent->isReadOnlyNode());
- ASSERT(!newParent->isDocumentTypeNode());
+ ASSERT(!newParent.isReadOnlyNode());
+ ASSERT(!newParent.isDocumentTypeNode());
ASSERT(isChildTypeAllowed(newParent, newChild));
- if (newChild->contains(newParent)) {
+ if (newChild.contains(&newParent)) {
ec = HIERARCHY_REQUEST_ERR;
return false;
}
return true;
}
-static inline bool checkAddChild(ContainerNode* newParent, Node* newChild, ExceptionCode& ec)
+static inline bool checkAddChild(ContainerNode& newParent, Node& newChild, ExceptionCode& ec)
{
- ec = checkAcceptChild(newParent, newChild, 0);
- if (ec)
- return false;
-
- return true;
+ ec = checkAcceptChild(newParent, newChild, nullptr);
+ return !ec;
}
-static inline bool checkReplaceChild(ContainerNode* newParent, Node* newChild, Node* oldChild, ExceptionCode& ec)
+static inline bool checkReplaceChild(ContainerNode& newParent, Node& newChild, Node& oldChild, ExceptionCode& ec)
{
- ec = checkAcceptChild(newParent, newChild, oldChild);
- if (ec)
- return false;
-
- return true;
+ ec = checkAcceptChild(newParent, newChild, &oldChild);
+ return !ec;
}
-bool ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& ec)
+bool ContainerNode::insertBefore(Ref<Node>&& newChild, Node* refChild, ExceptionCode& ec)
{
// Check that this node is not "floating".
// If it is, it can be deleted as a side effect of sending mutation events.
// insertBefore(node, 0) is equivalent to appendChild(node)
if (!refChild)
- return appendChild(newChild, ec);
+ return appendChild(WTF::move(newChild), ec);
// Make sure adding the new child is OK.
- if (!checkAddChild(this, newChild.get(), ec))
+ if (!checkAddChild(*this, newChild, ec))
return false;
// NOT_FOUND_ERR: Raised if refChild is not a child of this node
return false;
}
- if (refChild->previousSibling() == newChild || refChild == newChild) // nothing to do
+ if (refChild->previousSibling() == newChild.ptr() || refChild == newChild.ptr()) // nothing to do
return true;
Ref<Node> next(*refChild);
NodeVector targets;
- collectChildrenAndRemoveFromOldParent(*newChild.get(), targets, ec);
+ collectChildrenAndRemoveFromOldParent(newChild, targets, ec);
if (ec)
return false;
if (targets.isEmpty())
return true;
// We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
- if (!checkAcceptChildGuaranteedNodeTypes(this, newChild.get(), ec))
+ if (!checkAcceptChildGuaranteedNodeTypes(*this, newChild, ec))
return false;
InspectorInstrumentation::willInsertDOMNode(document(), *this);
newChild->setNeedsStyleRecalc(ReconstructRenderTree);
}
-bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode& ec)
+bool ContainerNode::replaceChild(Ref<Node>&& newChild, Node& oldChild, ExceptionCode& ec)
{
// Check that this node is not "floating".
// If it is, it can be deleted as a side effect of sending mutation events.
ec = 0;
- if (oldChild == newChild) // nothing to do
+ if (&oldChild == newChild.ptr()) // nothing to do
return true;
- if (!oldChild) {
- ec = NOT_FOUND_ERR;
- return false;
- }
-
// Make sure replacing the old child with the new is ok
- if (!checkReplaceChild(this, newChild.get(), oldChild, ec))
+ if (!checkReplaceChild(*this, newChild, oldChild, ec))
return false;
// NOT_FOUND_ERR: Raised if oldChild is not a child of this node.
- if (oldChild->parentNode() != this) {
+ if (oldChild.parentNode() != this) {
ec = NOT_FOUND_ERR;
return false;
}
ChildListMutationScope mutation(*this);
- RefPtr<Node> next = oldChild->nextSibling();
+ RefPtr<Node> next = oldChild.nextSibling();
// Remove the node we're replacing
- Ref<Node> removedChild(*oldChild);
+ Ref<Node> removedChild(oldChild);
removeChild(oldChild, ec);
if (ec)
return false;
- if (next && (next->previousSibling() == newChild || next == newChild)) // nothing to do
+ if (next && (next->previousSibling() == newChild.ptr() || next == newChild.ptr())) // nothing to do
return true;
// Does this one more time because removeChild() fires a MutationEvent.
- if (!checkReplaceChild(this, newChild.get(), oldChild, ec))
+ if (!checkReplaceChild(*this, newChild, oldChild, ec))
return false;
NodeVector targets;
- collectChildrenAndRemoveFromOldParent(*newChild.get(), targets, ec);
+ collectChildrenAndRemoveFromOldParent(newChild, targets, ec);
if (ec)
return false;
// Does this yet another check because collectChildrenAndRemoveFromOldParent() fires a MutationEvent.
- if (!checkReplaceChild(this, newChild.get(), oldChild, ec))
+ if (!checkReplaceChild(*this, newChild, oldChild, ec))
return false;
InspectorInstrumentation::willInsertDOMNode(document(), *this);
disconnectSubframesIfNeeded(*this, RootAndDescendants);
}
-bool ContainerNode::removeChild(Node* oldChild, ExceptionCode& ec)
+bool ContainerNode::removeChild(Node& oldChild, ExceptionCode& ec)
{
// Check that this node is not "floating".
// If it is, it can be deleted as a side effect of sending mutation events.
}
// NOT_FOUND_ERR: Raised if oldChild is not a child of this node.
- if (!oldChild || oldChild->parentNode() != this) {
+ if (oldChild.parentNode() != this) {
ec = NOT_FOUND_ERR;
return false;
}
- Ref<Node> child(*oldChild);
+ Ref<Node> child(oldChild);
document().removeFocusedNodeOfSubtree(child.ptr());
dispatchSubtreeModifiedEvent();
}
-bool ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec)
+bool ContainerNode::appendChild(Ref<Node>&& newChild, ExceptionCode& ec)
{
Ref<ContainerNode> protect(*this);
ec = 0;
// Make sure adding the new child is ok
- if (!checkAddChild(this, newChild.get(), ec))
+ if (!checkAddChild(*this, newChild, ec))
return false;
- if (newChild == m_lastChild) // nothing to do
- return newChild;
+ if (newChild.ptr() == m_lastChild) // nothing to do
+ return true;
NodeVector targets;
- collectChildrenAndRemoveFromOldParent(*newChild.get(), targets, ec);
+ collectChildrenAndRemoveFromOldParent(newChild, targets, ec);
if (ec)
return false;
return true;
// We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
- if (!checkAcceptChildGuaranteedNodeTypes(this, newChild.get(), ec))
+ if (!checkAcceptChildGuaranteedNodeTypes(*this, newChild, ec))
return false;
InspectorInstrumentation::willInsertDOMNode(document(), *this);
invalidateNodeListAndCollectionCachesInAncestors();
}
-void ContainerNode::cloneChildNodes(ContainerNode* clone)
+void ContainerNode::cloneChildNodes(ContainerNode& clone)
{
ExceptionCode ec = 0;
- Document& targetDocument = clone->document();
+ Document& targetDocument = clone.document();
for (Node* child = firstChild(); child && !ec; child = child->nextSibling()) {
- RefPtr<Node> clonedChild = child->cloneNodeInternal(targetDocument, CloningOperation::SelfWithTemplateContent);
- clone->appendChild(clonedChild, ec);
+ Ref<Node> clonedChild = child->cloneNodeInternal(targetDocument, CloningOperation::SelfWithTemplateContent);
+ clone.appendChild(clonedChild.copyRef(), ec);
- if (!ec && is<ContainerNode>(child))
- downcast<ContainerNode>(child)->cloneChildNodes(downcast<ContainerNode>(clonedChild.get()));
+ if (!ec && is<ContainerNode>(*child))
+ downcast<ContainerNode>(*child).cloneChildNodes(downcast<ContainerNode>(clonedChild.get()));
}
}
if (ec || !node)
return;
- appendChild(node.release(), ec);
+ appendChild(node.releaseNonNull(), ec);
}
void ContainerNode::prepend(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
if (ec || !node)
return;
- insertBefore(node.release(), firstChild(), ec);
+ insertBefore(node.releaseNonNull(), firstChild(), ec);
}
HTMLCollection* ContainerNode::cachedHTMLCollection(CollectionType type)
WEBCORE_EXPORT unsigned countChildNodes() const;
WEBCORE_EXPORT Node* traverseToChildAt(unsigned) const;
- bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& = ASSERT_NO_EXCEPTION);
- bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode& = ASSERT_NO_EXCEPTION);
- WEBCORE_EXPORT bool removeChild(Node* child, ExceptionCode& = ASSERT_NO_EXCEPTION);
- WEBCORE_EXPORT bool appendChild(PassRefPtr<Node> newChild, ExceptionCode& = ASSERT_NO_EXCEPTION);
+ bool insertBefore(Ref<Node>&& newChild, Node* refChild, ExceptionCode& = ASSERT_NO_EXCEPTION);
+ bool replaceChild(Ref<Node>&& newChild, Node& oldChild, ExceptionCode& = ASSERT_NO_EXCEPTION);
+ WEBCORE_EXPORT bool removeChild(Node& child, ExceptionCode& = ASSERT_NO_EXCEPTION);
+ WEBCORE_EXPORT bool appendChild(Ref<Node>&& newChild, ExceptionCode& = ASSERT_NO_EXCEPTION);
// These methods are only used during parsing.
// They don't send DOM mutation events or handle reparenting.
void removeChildren();
void takeAllChildrenFrom(ContainerNode*);
- void cloneChildNodes(ContainerNode* clone);
+ void cloneChildNodes(ContainerNode& clone);
enum ChildChangeType { ElementInserted, ElementRemoved, TextInserted, TextRemoved, TextChanged, AllChildrenRemoved, NonContentsChildChanged };
enum ChildChangeSource { ChildChangeSourceParser, ChildChangeSourceAPI };
}
if (doctype)
- doc->appendChild(doctype);
+ doc->appendChild(*doctype);
if (documentElement)
- doc->appendChild(documentElement.release());
+ doc->appendChild(documentElement.releaseNonNull());
return doc;
}
}
}
if (source->parentNode()) {
- source->parentNode()->removeChild(source.get(), ec);
+ source->parentNode()->removeChild(*source, ec);
if (ec)
return nullptr;
}
if (!headElement)
return;
m_titleElement = createElement(titleTag, false);
- headElement->appendChild(m_titleElement, ASSERT_NO_EXCEPTION);
+ headElement->appendChild(*m_titleElement, ASSERT_NO_EXCEPTION);
}
// The DOM API has no method of specifying direction, so assume LTR.
newBody = downcast<HTMLElement>(node.get());
}
- HTMLElement* b = bodyOrFrameset();
- if (!b)
- documentElement()->appendChild(newBody.release(), ec);
+ if (auto* body = bodyOrFrameset())
+ documentElement()->replaceChild(newBody.releaseNonNull(), *body, ec);
else
- documentElement()->replaceChild(newBody.release(), b, ec);
+ documentElement()->appendChild(newBody.releaseNonNull(), ec);
}
HTMLHeadElement* Document::head()
return false;
}
-bool Document::canReplaceChild(Node* newChild, Node* oldChild)
+bool Document::canReplaceChild(Node& newChild, Node& oldChild)
{
- if (!oldChild)
- // ContainerNode::replaceChild will raise a NOT_FOUND_ERR.
- return true;
-
- if (oldChild->nodeType() == newChild->nodeType())
+ if (oldChild.nodeType() == newChild.nodeType())
return true;
int numDoctypes = 0;
// First, check how many doctypes and elements we have, not counting
// the child we're about to remove.
for (Node* c = firstChild(); c; c = c->nextSibling()) {
- if (c == oldChild)
+ if (c == &oldChild)
continue;
switch (c->nodeType()) {
}
// Then, see how many doctypes and elements might be added by the new child.
- if (newChild->isDocumentFragment()) {
- for (Node* c = newChild->firstChild(); c; c = c->nextSibling()) {
+ if (newChild.isDocumentFragment()) {
+ for (Node* c = newChild.firstChild(); c; c = c->nextSibling()) {
switch (c->nodeType()) {
case ATTRIBUTE_NODE:
case CDATA_SECTION_NODE:
}
}
} else {
- switch (newChild->nodeType()) {
+ switch (newChild.nodeType()) {
case ATTRIBUTE_NODE:
case CDATA_SECTION_NODE:
case DOCUMENT_FRAGMENT_NODE:
return true;
}
-RefPtr<Node> Document::cloneNodeInternal(Document&, CloningOperation type)
+Ref<Node> Document::cloneNodeInternal(Document&, CloningOperation type)
{
Ref<Document> clone = cloneDocumentWithoutChildren();
clone->cloneDataFromDocument(*this);
case CloningOperation::SelfWithTemplateContent:
break;
case CloningOperation::Everything:
- cloneChildNodes(clone.ptr());
+ cloneChildNodes(clone);
break;
}
return WTF::move(clone);
void nodeChildrenWillBeRemoved(ContainerNode&);
// nodeWillBeRemoved is only safe when removing one node at a time.
void nodeWillBeRemoved(Node&);
- bool canReplaceChild(Node* newChild, Node* oldChild);
+ bool canReplaceChild(Node& newChild, Node& oldChild);
void textInserted(Node*, unsigned offset, unsigned length);
void textRemoved(Node*, unsigned offset, unsigned length);
virtual String nodeName() const override final;
virtual NodeType nodeType() const override final;
virtual bool childTypeAllowed(NodeType) const override final;
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override final;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override final;
void cloneDataFromDocument(const Document&);
virtual void refScriptExecutionContext() override final { ref(); }
}
}
-RefPtr<Node> DocumentFragment::cloneNodeInternal(Document& targetDocument, CloningOperation type)
+Ref<Node> DocumentFragment::cloneNodeInternal(Document& targetDocument, CloningOperation type)
{
- RefPtr<DocumentFragment> clone = create(targetDocument);
+ Ref<DocumentFragment> clone = create(targetDocument);
switch (type) {
case CloningOperation::OnlySelf:
case CloningOperation::SelfWithTemplateContent:
break;
case CloningOperation::Everything:
- cloneChildNodes(clone.get());
+ cloneChildNodes(clone);
break;
}
- return clone;
+ return WTF::move(clone);
}
void DocumentFragment::parseHTML(const String& source, Element* contextElement, ParserContentPolicy parserContentPolicy)
private:
virtual NodeType nodeType() const override final;
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
virtual bool childTypeAllowed(NodeType) const override;
};
return DOCUMENT_TYPE_NODE;
}
-RefPtr<Node> DocumentType::cloneNodeInternal(Document& documentTarget, CloningOperation)
+Ref<Node> DocumentType::cloneNodeInternal(Document& documentTarget, CloningOperation)
{
return create(documentTarget, m_name, m_publicId, m_systemId);
}
virtual URL baseURI() const override;
virtual String nodeName() const override;
virtual NodeType nodeType() const override;
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
String m_name;
String m_publicId;
EventDispatcher::dispatchSimulatedClick(this, underlyingEvent, eventOptions, visualOptions);
}
-RefPtr<Node> Element::cloneNodeInternal(Document& targetDocument, CloningOperation type)
+Ref<Node> Element::cloneNodeInternal(Document& targetDocument, CloningOperation type)
{
switch (type) {
case CloningOperation::OnlySelf:
case CloningOperation::SelfWithTemplateContent:
return cloneElementWithoutChildren(targetDocument);
case CloningOperation::Everything:
- return cloneElementWithChildren(targetDocument);
+ break;
}
- ASSERT_NOT_REACHED();
- return nullptr;
+ return cloneElementWithChildren(targetDocument);
}
-RefPtr<Element> Element::cloneElementWithChildren(Document& targetDocument)
+Ref<Element> Element::cloneElementWithChildren(Document& targetDocument)
{
- RefPtr<Element> clone = cloneElementWithoutChildren(targetDocument);
- cloneChildNodes(clone.get());
- return clone.release();
+ Ref<Element> clone = cloneElementWithoutChildren(targetDocument);
+ cloneChildNodes(clone);
+ return clone;
}
-RefPtr<Element> Element::cloneElementWithoutChildren(Document& targetDocument)
+Ref<Element> Element::cloneElementWithoutChildren(Document& targetDocument)
{
- RefPtr<Element> clone = cloneElementWithoutAttributesAndChildren(targetDocument);
+ Ref<Element> clone = cloneElementWithoutAttributesAndChildren(targetDocument);
// This will catch HTML elements in the wrong namespace that are not correctly copied.
// This is a sanity check as HTML overloads some of the DOM methods.
ASSERT(isHTMLElement() == clone->isHTMLElement());
clone->cloneDataFromElement(*this);
- return clone.release();
+ return clone;
}
-RefPtr<Element> Element::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
+Ref<Element> Element::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
{
return targetDocument.createElement(tagQName(), false);
}
if (ec)
return;
- parent->replaceChild(fragment.release(), this, ec);
+ parent->replaceChild(fragment.releaseNonNull(), *this, ec);
RefPtr<Node> node = next ? next->previousSibling() : nullptr;
if (!ec && is<Text>(node.get()))
mergeWithNextTextNode(downcast<Text>(*node), ec);
container = downcast<HTMLTemplateElement>(*this).content();
#endif
- replaceChildrenWithFragment(*container, fragment.release(), ec);
+ replaceChildrenWithFragment(*container, fragment.releaseNonNull(), ec);
}
}
virtual String nodeName() const override;
- RefPtr<Element> cloneElementWithChildren(Document&);
- RefPtr<Element> cloneElementWithoutChildren(Document&);
+ Ref<Element> cloneElementWithChildren(Document&);
+ Ref<Element> cloneElementWithoutChildren(Document&);
void normalizeAttributes();
String nodeNamePreservingCase() const;
// cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren
// are used instead.
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
- virtual RefPtr<Element> cloneElementWithoutAttributesAndChildren(Document&);
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document&);
void addShadowRoot(Ref<ShadowRoot>&&);
void removeShadowRoot();
return ENTITY_REFERENCE_NODE;
}
-RefPtr<Node> EntityReference::cloneNodeInternal(Document& targetDocument, CloningOperation)
+Ref<Node> EntityReference::cloneNodeInternal(Document& targetDocument, CloningOperation)
{
return create(targetDocument, m_entityName);
}
virtual String nodeName() const override;
virtual NodeType nodeType() const override;
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
String m_entityName;
};
bool Node::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& ec)
{
+ if (!newChild) {
+ ec = TypeError;
+ return false;
+ }
if (!is<ContainerNode>(*this)) {
ec = HIERARCHY_REQUEST_ERR;
return false;
}
- return downcast<ContainerNode>(*this).insertBefore(newChild, refChild, ec);
+ return downcast<ContainerNode>(*this).insertBefore(*newChild, refChild, ec);
}
bool Node::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode& ec)
{
+ if (!newChild || !oldChild) {
+ ec = TypeError;
+ return false;
+ }
if (!is<ContainerNode>(*this)) {
ec = HIERARCHY_REQUEST_ERR;
return false;
}
- return downcast<ContainerNode>(*this).replaceChild(newChild, oldChild, ec);
+ return downcast<ContainerNode>(*this).replaceChild(*newChild, *oldChild, ec);
}
bool Node::removeChild(Node* oldChild, ExceptionCode& ec)
{
+ if (!oldChild) {
+ ec = TypeError;
+ return false;
+ }
if (!is<ContainerNode>(*this)) {
ec = NOT_FOUND_ERR;
return false;
}
- return downcast<ContainerNode>(*this).removeChild(oldChild, ec);
+ return downcast<ContainerNode>(*this).removeChild(*oldChild, ec);
}
bool Node::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec)
{
+ if (!newChild) {
+ ec = TypeError;
+ return false;
+ }
if (!is<ContainerNode>(*this)) {
ec = HIERARCHY_REQUEST_ERR;
return false;
}
- return downcast<ContainerNode>(*this).appendChild(newChild, ec);
+ return downcast<ContainerNode>(*this).appendChild(*newChild, ec);
}
static HashSet<RefPtr<Node>> nodeSetPreTransformedFromNodeOrStringVector(const Vector<NodeOrString>& nodeOrStringVector)
else
viablePreviousSibling = parent->firstChild();
- parent->insertBefore(node.release(), viablePreviousSibling.get(), ec);
+ parent->insertBefore(node.releaseNonNull(), viablePreviousSibling.get(), ec);
}
void Node::after(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
if (ec || !node)
return;
- parent->insertBefore(node.release(), viableNextSibling.get(), ec);
+ parent->insertBefore(node.releaseNonNull(), viableNextSibling.get(), ec);
}
void Node::replaceWith(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
return;
if (parentNode() == parent)
- parent->replaceChild(node.release(), this, ec);
+ parent->replaceChild(node.releaseNonNull(), *this, ec);
else
- parent->insertBefore(node.release(), viableNextSibling.get(), ec);
+ parent->insertBefore(node.releaseNonNull(), viableNextSibling.get(), ec);
}
void Node::remove(ExceptionCode& ec)
{
if (ContainerNode* parent = parentNode())
- parent->removeChild(this, ec);
+ parent->removeChild(*this, ec);
}
void Node::normalize()
SelfWithTemplateContent,
Everything,
};
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) = 0;
- RefPtr<Node> cloneNode(bool deep) { return cloneNodeInternal(document(), deep ? CloningOperation::Everything : CloningOperation::OnlySelf); }
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) = 0;
+ Ref<Node> cloneNode(bool deep) { return cloneNodeInternal(document(), deep ? CloningOperation::Everything : CloningOperation::OnlySelf); }
virtual const AtomicString& localName() const;
virtual const AtomicString& namespaceURI() const;
return PROCESSING_INSTRUCTION_NODE;
}
-RefPtr<Node> ProcessingInstruction::cloneNodeInternal(Document& targetDocument, CloningOperation)
+Ref<Node> ProcessingInstruction::cloneNodeInternal(Document& targetDocument, CloningOperation)
{
// FIXME: Is it a problem that this does not copy m_localHref?
// What about other data members?
virtual String nodeName() const override;
virtual NodeType nodeType() const override;
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
virtual void removedFrom(ContainerNode&) override;
// (or just delete the stuff in between)
if ((action == Extract || action == Clone) && leftContents)
- fragment->appendChild(leftContents, ec);
+ fragment->appendChild(*leftContents, ec);
if (processStart) {
NodeVector nodes;
}
if ((action == Extract || action == Clone) && rightContents)
- fragment->appendChild(rightContents, ec);
+ fragment->appendChild(*rightContents, ec);
return fragment;
}
endOffset = std::min(endOffset, static_cast<CharacterData*>(container)->length());
startOffset = std::min(startOffset, endOffset);
if (action == Extract || action == Clone) {
- RefPtr<CharacterData> c = static_pointer_cast<CharacterData>(container->cloneNode(true));
+ RefPtr<CharacterData> c = static_cast<CharacterData*>(container->cloneNode(true).ptr());
deleteCharacterData(c, startOffset, endOffset, ec);
if (fragment) {
result = fragment;
endOffset = std::min(endOffset, static_cast<ProcessingInstruction*>(container)->data().length());
startOffset = std::min(startOffset, endOffset);
if (action == Extract || action == Clone) {
- RefPtr<ProcessingInstruction> c = static_pointer_cast<ProcessingInstruction>(container->cloneNode(true));
+ RefPtr<ProcessingInstruction> c = static_cast<ProcessingInstruction*>(container->cloneNode(true).ptr());
c->setData(c->data().substring(startOffset, endOffset - startOffset), ec);
if (fragment) {
result = fragment;
return;
container = &startContainer();
- container->parentNode()->insertBefore(newNode.release(), newText.get(), ec);
+ container->parentNode()->insertBefore(newNode.releaseNonNull(), newText.get(), ec);
if (ec)
return;
ec = 0;
while (Node* n = newParent->firstChild()) {
- downcast<ContainerNode>(*newParent).removeChild(n, ec);
+ downcast<ContainerNode>(*newParent).removeChild(*n, ec);
if (ec)
return;
}
}
if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, host(), AllowScriptingContent, ec))
- replaceChildrenWithFragment(*this, fragment.release(), ec);
+ replaceChildrenWithFragment(*this, fragment.releaseNonNull(), ec);
}
bool ShadowRoot::childTypeAllowed(NodeType type) const
invalidateDistribution();
}
-RefPtr<Node> ShadowRoot::cloneNodeInternal(Document&, CloningOperation)
+Ref<Node> ShadowRoot::cloneNodeInternal(Document&, CloningOperation)
{
- return nullptr; // ShadowRoots should never be cloned.
+ RELEASE_ASSERT_NOT_REACHED();
+ return *static_cast<Node*>(nullptr); // ShadowRoots should never be cloned.
}
void ShadowRoot::removeAllEventListeners()
virtual bool childTypeAllowed(NodeType) const override;
virtual void childrenChanged(const ChildChange&) override;
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
// FIXME: This shouldn't happen. https://bugs.webkit.org/show_bug.cgi?id=88834
bool isOrphan() const { return !m_host; }
dispatchModifiedEvent(oldStr);
if (parentNode())
- parentNode()->insertBefore(newText.ptr(), nextSibling(), ec);
+ parentNode()->insertBefore(newText.copyRef(), nextSibling(), ec);
if (ec)
return 0;
RefPtr<Text> protectedThis(this); // Mutation event handlers could cause our last ref to go away
RefPtr<ContainerNode> parent = parentNode(); // Protect against mutation handlers moving this node during traversal
for (RefPtr<Node> n = startText; n && n != this && n->isTextNode() && n->parentNode() == parent;) {
- RefPtr<Node> nodeToRemove(n.release());
+ Ref<Node> nodeToRemove(n.releaseNonNull());
n = nodeToRemove->nextSibling();
- parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION);
+ parent->removeChild(WTF::move(nodeToRemove), IGNORE_EXCEPTION);
}
if (this != endText) {
Node* onePastEndText = endText->nextSibling();
for (RefPtr<Node> n = nextSibling(); n && n != onePastEndText && n->isTextNode() && n->parentNode() == parent;) {
- RefPtr<Node> nodeToRemove(n.release());
+ Ref<Node> nodeToRemove(n.releaseNonNull());
n = nodeToRemove->nextSibling();
- parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION);
+ parent->removeChild(WTF::move(nodeToRemove), IGNORE_EXCEPTION);
}
}
if (newText.isEmpty()) {
if (parent && parentNode() == parent)
- parent->removeChild(this, IGNORE_EXCEPTION);
- return 0;
+ parent->removeChild(*this, IGNORE_EXCEPTION);
+ return nullptr;
}
setData(newText, IGNORE_EXCEPTION);
- return protectedThis.release();
+ return protectedThis;
}
String Text::nodeName() const
return TEXT_NODE;
}
-RefPtr<Node> Text::cloneNodeInternal(Document& targetDocument, CloningOperation)
+Ref<Node> Text::cloneNodeInternal(Document& targetDocument, CloningOperation)
{
return create(targetDocument, data());
}
private:
virtual String nodeName() const override;
virtual NodeType nodeType() const override;
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
virtual bool childTypeAllowed(NodeType) const override;
virtual Ref<Text> virtualCreate(const String&);
namespace WebCore {
-AppendNodeCommand::AppendNodeCommand(PassRefPtr<ContainerNode> parent, PassRefPtr<Node> node, EditAction editingAction)
+AppendNodeCommand::AppendNodeCommand(PassRefPtr<ContainerNode> parent, Ref<Node>&& node, EditAction editingAction)
: SimpleEditCommand(parent->document(), editingAction)
, m_parent(parent)
- , m_node(node)
+ , m_node(WTF::move(node))
{
ASSERT(m_parent);
- ASSERT(m_node);
ASSERT(!m_node->parentNode());
ASSERT(m_parent->hasEditableStyle() || !m_parent->renderer());
if (!m_parent->hasEditableStyle() && m_parent->renderer())
return;
- m_parent->appendChild(m_node.get(), IGNORE_EXCEPTION);
+ m_parent->appendChild(m_node.copyRef(), IGNORE_EXCEPTION);
if (shouldPostAccessibilityNotification())
- sendAXTextChangedIgnoringLineBreaks(m_node.get(), applyEditType());
+ sendAXTextChangedIgnoringLineBreaks(m_node.ptr(), applyEditType());
}
void AppendNodeCommand::doUnapply()
// Need to notify this before actually deleting the text
if (shouldPostAccessibilityNotification())
- sendAXTextChangedIgnoringLineBreaks(m_node.get(), unapplyEditType());
+ sendAXTextChangedIgnoringLineBreaks(m_node.ptr(), unapplyEditType());
m_node->remove(IGNORE_EXCEPTION);
}
void AppendNodeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_parent.get(), nodes);
- addNodeAndDescendants(m_node.get(), nodes);
+ addNodeAndDescendants(m_node.ptr(), nodes);
}
#endif
class AppendNodeCommand : public SimpleEditCommand {
public:
- static Ref<AppendNodeCommand> create(PassRefPtr<ContainerNode> parent, PassRefPtr<Node> node, EditAction editingAction)
+ static Ref<AppendNodeCommand> create(PassRefPtr<ContainerNode> parent, Ref<Node>&& node, EditAction editingAction)
{
- return adoptRef(*new AppendNodeCommand(parent, node, editingAction));
+ return adoptRef(*new AppendNodeCommand(parent, WTF::move(node), editingAction));
}
private:
- AppendNodeCommand(PassRefPtr<ContainerNode> parent, PassRefPtr<Node>, EditAction);
+ AppendNodeCommand(PassRefPtr<ContainerNode> parent, Ref<Node>&&, EditAction);
virtual void doApply() override;
virtual void doUnapply() override;
#endif
RefPtr<ContainerNode> m_parent;
- RefPtr<Node> m_node;
+ Ref<Node> m_node;
};
} // namespace WebCore
void CompositeEditCommand::appendNode(PassRefPtr<Node> node, PassRefPtr<ContainerNode> parent)
{
ASSERT(canHaveChildrenForEditing(parent.get()));
- applyCommandToComposite(AppendNodeCommand::create(parent, node, editingAction()));
+ ASSERT(node);
+ applyCommandToComposite(AppendNodeCommand::create(parent, *node, editingAction()));
}
void CompositeEditCommand::removeChildrenInRange(PassRefPtr<Node> node, unsigned from, unsigned to)
{
if (!node || !node->nonShadowBoundaryParentNode())
return;
- applyCommandToComposite(RemoveNodeCommand::create(node, shouldAssumeContentIsAlwaysEditable));
+ applyCommandToComposite(RemoveNodeCommand::create(*node, shouldAssumeContentIsAlwaysEditable));
}
void CompositeEditCommand::removeNodePreservingChildren(PassRefPtr<Node> node, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
return node.release();
}
-PassRefPtr<Element> createBlockPlaceholderElement(Document& document)
+Ref<Element> createBlockPlaceholderElement(Document& document)
{
return document.createElement(brTag, false);
}
// We need to merge into m_upstreamStart's block, but it's been emptied out and collapsed by deletion.
if (!mergeDestination.deepEquivalent().deprecatedNode() || !mergeDestination.deepEquivalent().deprecatedNode()->isDescendantOf(enclosingBlock(m_upstreamStart.containerNode())) || m_startsAtEmptyLine) {
- insertNodeAt(createBreakElement(document()).get(), m_upstreamStart);
+ insertNodeAt(createBreakElement(document()).ptr(), m_upstreamStart);
mergeDestination = VisiblePosition(m_upstreamStart);
}
removePreviouslySelectedEmptyTableRows();
- RefPtr<Node> placeholder = m_needPlaceholder ? createBreakElement(document()).get() : 0;
+ RefPtr<Node> placeholder = m_needPlaceholder ? createBreakElement(document()).ptr() : nullptr;
if (placeholder) {
if (m_sanitizeMarkup)
RefPtr<Range> context = document().createRange();
context->selectNodeContents(elem, ec);
- RefPtr<DocumentFragment> fragment = createFragmentFromText(*context.get(), text);
- elem->appendChild(fragment, ec);
+ Ref<DocumentFragment> fragment = createFragmentFromText(*context.get(), text);
+ elem->appendChild(WTF::move(fragment), ec);
// restore element to document
if (parent) {
return true;
}
-static bool executeInsertNode(Frame& frame, PassRefPtr<Node> content)
+static bool executeInsertNode(Frame& frame, Ref<Node>&& content)
{
RefPtr<DocumentFragment> fragment = DocumentFragment::create(*frame.document());
ExceptionCode ec = 0;
- fragment->appendChild(content, ec);
+ fragment->appendChild(WTF::move(content), ec);
if (ec)
return false;
return executeInsertFragment(frame, fragment.release());
static bool executeInsertHorizontalRule(Frame& frame, Event*, EditorCommandSource, const String& value)
{
- RefPtr<HTMLHRElement> rule = HTMLHRElement::create(*frame.document());
+ Ref<HTMLHRElement> rule = HTMLHRElement::create(*frame.document());
if (!value.isEmpty())
rule->setIdAttribute(value);
- return executeInsertNode(frame, rule.release());
+ return executeInsertNode(frame, WTF::move(rule));
}
static bool executeInsertHTML(Frame& frame, Event*, EditorCommandSource, const String& value)
static bool executeInsertImage(Frame& frame, Event*, EditorCommandSource, const String& value)
{
// FIXME: If userInterface is true, we should display a dialog box and let the user choose a local image.
- RefPtr<HTMLImageElement> image = HTMLImageElement::create(*frame.document());
+ Ref<HTMLImageElement> image = HTMLImageElement::create(*frame.document());
image->setSrc(value);
- return executeInsertNode(frame, image.release());
+ return executeInsertNode(frame, WTF::move(image));
}
static bool executeInsertLineBreak(Frame& frame, Event* event, EditorCommandSource source, const String&)
// Insert an extra br or '\n' if the just inserted one collapsed.
if (!isStartOfParagraph(positionBeforeNode(nodeToInsert.get())))
- insertNodeBefore(nodeToInsert->cloneNode(false).get(), nodeToInsert.get());
+ insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert.get());
setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInsert.get()), DOWNSTREAM, endingSelection().isDirectional()));
// If we're inserting after all of the rendered text in a text node, or into a non-text node,
return;
ASSERT(isEditableNode(*parent));
- parent->insertBefore(m_insertChild.get(), m_refChild.get(), IGNORE_EXCEPTION);
+ parent->insertBefore(*m_insertChild, m_refChild.get(), IGNORE_EXCEPTION);
if (shouldPostAccessibilityNotification()) {
Position position = is<Text>(m_insertChild.get()) ? Position(downcast<Text>(m_insertChild.get()), 0) : createLegacyEditingPosition(m_insertChild.get(), 0);
// created. All of the nodes, starting at visiblePos, are about to be added to the new paragraph
// element. If the first node to be inserted won't be one that will hold an empty line open, add a br.
if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visiblePos))
- appendNode(createBreakElement(document()).get(), blockToInsert.get());
+ appendNode(createBreakElement(document()), blockToInsert.get());
// Move the start node and the siblings of the start node.
if (VisiblePosition(insertionPosition) != VisiblePosition(positionBeforeNode(blockToInsert.get()))) {
m_atChild = m_element2->firstChild();
- Vector<RefPtr<Node>> children;
+ Vector<Ref<Node>> children;
for (Node* child = m_element1->firstChild(); child; child = child->nextSibling())
- children.append(child);
+ children.append(*child);
size_t size = children.size();
for (size_t i = 0; i < size; ++i)
- m_element2->insertBefore(children[i].release(), m_atChild.get(), IGNORE_EXCEPTION);
+ m_element2->insertBefore(WTF::move(children[i]), m_atChild.get(), IGNORE_EXCEPTION);
m_element1->remove(IGNORE_EXCEPTION);
}
ExceptionCode ec = 0;
- parent->insertBefore(m_element1.get(), m_element2.get(), ec);
+ parent->insertBefore(*m_element1, m_element2.get(), ec);
if (ec)
return;
- Vector<RefPtr<Node>> children;
+ Vector<Ref<Node>> children;
for (Node* child = m_element2->firstChild(); child && child != atChild; child = child->nextSibling())
- children.append(child);
+ children.append(*child);
size_t size = children.size();
for (size_t i = 0; i < size; ++i)
- m_element1->appendChild(children[i].release(), ec);
+ m_element1->appendChild(WTF::move(children[i]), ec);
}
#ifndef NDEBUG
namespace WebCore {
-RemoveNodeCommand::RemoveNodeCommand(PassRefPtr<Node> node, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
+RemoveNodeCommand::RemoveNodeCommand(Ref<Node>&& node, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
: SimpleEditCommand(node->document())
- , m_node(node)
+ , m_node(WTF::move(node))
, m_shouldAssumeContentIsAlwaysEditable(shouldAssumeContentIsAlwaysEditable)
{
- ASSERT(m_node);
ASSERT(m_node->parentNode());
}
if (!parent || !parent->hasEditableStyle())
return;
- parent->insertBefore(m_node.get(), refChild.get(), IGNORE_EXCEPTION);
+ parent->insertBefore(m_node.copyRef(), refChild.get(), IGNORE_EXCEPTION);
}
#ifndef NDEBUG
{
addNodeAndDescendants(m_parent.get(), nodes);
addNodeAndDescendants(m_refChild.get(), nodes);
- addNodeAndDescendants(m_node.get(), nodes);
+ addNodeAndDescendants(m_node.ptr(), nodes);
}
#endif
class RemoveNodeCommand : public SimpleEditCommand {
public:
- static Ref<RemoveNodeCommand> create(PassRefPtr<Node> node, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
+ static Ref<RemoveNodeCommand> create(Ref<Node>&& node, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
{
- return adoptRef(*new RemoveNodeCommand(node, shouldAssumeContentIsAlwaysEditable));
+ return adoptRef(*new RemoveNodeCommand(WTF::move(node), shouldAssumeContentIsAlwaysEditable));
}
private:
- explicit RemoveNodeCommand(PassRefPtr<Node>, ShouldAssumeContentIsAlwaysEditable);
+ RemoveNodeCommand(Ref<Node>&&, ShouldAssumeContentIsAlwaysEditable);
virtual void doApply() override;
virtual void doUnapply() override;
void getNodesInCommand(HashSet<Node*>&) override;
#endif
- RefPtr<Node> m_node;
+ Ref<Node> m_node;
RefPtr<ContainerNode> m_parent;
RefPtr<Node> m_refChild;
ShouldAssumeContentIsAlwaysEditable m_shouldAssumeContentIsAlwaysEditable;
ASSERT(m_elementToReplace);
}
-static void swapInNodePreservingAttributesAndChildren(HTMLElement* newNode, HTMLElement* nodeToReplace)
+static void swapInNodePreservingAttributesAndChildren(HTMLElement& newNode, HTMLElement& nodeToReplace)
{
- ASSERT(nodeToReplace->inDocument());
- RefPtr<ContainerNode> parentNode = nodeToReplace->parentNode();
+ ASSERT(nodeToReplace.inDocument());
+ RefPtr<ContainerNode> parentNode = nodeToReplace.parentNode();
// FIXME: Fix this to send the proper MutationRecords when MutationObservers are present.
- newNode->cloneDataFromElement(*nodeToReplace);
+ newNode.cloneDataFromElement(nodeToReplace);
NodeVector children;
- getChildNodes(*nodeToReplace, children);
+ getChildNodes(nodeToReplace, children);
for (auto& child : children)
- newNode->appendChild(child.ptr(), ASSERT_NO_EXCEPTION);
+ newNode.appendChild(WTF::move(child), ASSERT_NO_EXCEPTION);
- parentNode->insertBefore(newNode, nodeToReplace, ASSERT_NO_EXCEPTION);
+ parentNode->insertBefore(newNode, &nodeToReplace, ASSERT_NO_EXCEPTION);
parentNode->removeChild(nodeToReplace, ASSERT_NO_EXCEPTION);
}
return;
if (!m_spanElement)
m_spanElement = createHTMLElement(m_elementToReplace->document(), spanTag);
- swapInNodePreservingAttributesAndChildren(m_spanElement.get(), m_elementToReplace.get());
+ swapInNodePreservingAttributesAndChildren(*m_spanElement, *m_elementToReplace);
}
void ReplaceNodeWithSpanCommand::doUnapply()
{
if (!m_spanElement->inDocument())
return;
- swapInNodePreservingAttributesAndChildren(m_elementToReplace.get(), m_spanElement.get());
+ swapInNodePreservingAttributesAndChildren(*m_elementToReplace, *m_spanElement);
}
#ifndef NDEBUG
if (!parent)
return;
- parent->removeChild(node.get(), ASSERT_NO_EXCEPTION);
+ parent->removeChild(*node, ASSERT_NO_EXCEPTION);
}
void ReplacementFragment::insertNodeBefore(PassRefPtr<Node> node, Node* refNode)
if (!parent)
return;
- parent->insertBefore(node, refNode, ASSERT_NO_EXCEPTION);
+ parent->insertBefore(*node, refNode, ASSERT_NO_EXCEPTION);
}
PassRefPtr<StyledElement> ReplacementFragment::insertFragmentForTestRendering(Node* rootEditableElement)
{
RefPtr<StyledElement> holder = createDefaultParagraphElement(document());
- holder->appendChild(m_fragment, ASSERT_NO_EXCEPTION);
+ holder->appendChild(*m_fragment, ASSERT_NO_EXCEPTION);
rootEditableElement->appendChild(holder.get(), ASSERT_NO_EXCEPTION);
document().updateLayoutIgnorePendingStylesheets();
return;
while (RefPtr<Node> node = holder->firstChild()) {
- holder->removeChild(node.get(), ASSERT_NO_EXCEPTION);
- m_fragment->appendChild(node.get(), ASSERT_NO_EXCEPTION);
+ holder->removeChild(*node, ASSERT_NO_EXCEPTION);
+ m_fragment->appendChild(*node, ASSERT_NO_EXCEPTION);
}
removeNode(holder);
}
while (RefPtr<Node> listItem = listElement->firstChild()) {
- listElement->removeChild(listItem.get(), ASSERT_NO_EXCEPTION);
+ listElement->removeChild(*listItem, ASSERT_NO_EXCEPTION);
if (isStart || isMiddle) {
insertNodeBefore(listItem, lastNode);
insertedNodes.respondToNodeInsertion(listItem.get());
if (m_atChild->parentNode() != m_element2)
return;
- Vector<RefPtr<Node>> children;
+ Vector<Ref<Node>> children;
for (Node* node = m_element2->firstChild(); node != m_atChild; node = node->nextSibling())
- children.append(node);
+ children.append(*node);
ExceptionCode ec = 0;
ContainerNode* parent = m_element2->parentNode();
if (!parent || !parent->hasEditableStyle())
return;
- parent->insertBefore(m_element1.get(), m_element2.get(), ec);
+ parent->insertBefore(*m_element1, m_element2.get(), ec);
if (ec)
return;
size_t size = children.size();
for (size_t i = 0; i < size; ++i)
- m_element1->appendChild(children[i], ec);
+ m_element1->appendChild(WTF::move(children[i]), ec);
}
void SplitElementCommand::doApply()
if (!m_element1 || !m_element1->hasEditableStyle() || !m_element2->hasEditableStyle())
return;
- Vector<RefPtr<Node>> children;
+ Vector<Ref<Node>> children;
for (Node* node = m_element1->firstChild(); node; node = node->nextSibling())
- children.append(node);
+ children.append(*node);
RefPtr<Node> refChild = m_element2->firstChild();
size_t size = children.size();
for (size_t i = 0; i < size; ++i)
- m_element2->insertBefore(children[i].get(), refChild.get(), IGNORE_EXCEPTION);
+ m_element2->insertBefore(WTF::move(children[i]), refChild.get(), IGNORE_EXCEPTION);
// Recover the id attribute of the original element.
const AtomicString& id = m_element1->getIdAttribute();
void SplitTextNodeCommand::insertText1AndTrimText2()
{
ExceptionCode ec = 0;
- m_text2->parentNode()->insertBefore(m_text1.get(), m_text2.get(), ec);
+ m_text2->parentNode()->insertBefore(*m_text1, m_text2.get(), ec);
if (ec)
return;
m_text2->deleteData(0, m_offset, ec);
void WrapContentsInDummySpanCommand::executeApply()
{
- Vector<RefPtr<Node>> children;
+ Vector<Ref<Node>> children;
for (Node* child = m_element->firstChild(); child; child = child->nextSibling())
- children.append(child);
+ children.append(*child);
size_t size = children.size();
for (size_t i = 0; i < size; ++i)
- m_dummySpan->appendChild(children[i].release(), IGNORE_EXCEPTION);
+ m_dummySpan->appendChild(WTF::move(children[i]), IGNORE_EXCEPTION);
- m_element->appendChild(m_dummySpan.get(), IGNORE_EXCEPTION);
+ m_element->appendChild(*m_dummySpan, IGNORE_EXCEPTION);
}
void WrapContentsInDummySpanCommand::doApply()
if (!m_dummySpan || !m_element->hasEditableStyle())
return;
- Vector<RefPtr<Node>> children;
+ Vector<Ref<Node>> children;
for (Node* child = m_dummySpan->firstChild(); child; child = child->nextSibling())
- children.append(child);
+ children.append(*child);
size_t size = children.size();
for (size_t i = 0; i < size; ++i)
- m_element->appendChild(children[i].release(), IGNORE_EXCEPTION);
+ m_element->appendChild(WTF::move(children[i]), IGNORE_EXCEPTION);
m_dummySpan->remove(IGNORE_EXCEPTION);
}
if (!typingStyle || !typingStyle->style())
return &position.deprecatedNode()->renderer()->style();
- RefPtr<Element> styleElement = frame->document()->createElement(HTMLNames::spanTag, false);
+ Ref<Element> styleElement = frame->document()->createElement(HTMLNames::spanTag, false);
String styleText = typingStyle->style()->asText() + " display: inline";
styleElement->setAttribute(HTMLNames::styleAttr, styleText);
styleElement->appendChild(frame->document()->createEditingTextNode(""), ASSERT_NO_EXCEPTION);
- position.deprecatedNode()->parentNode()->appendChild(styleElement, ASSERT_NO_EXCEPTION);
+ position.deprecatedNode()->parentNode()->appendChild(styleElement.copyRef(), ASSERT_NO_EXCEPTION);
- nodeToRemove = styleElement.get();
+ nodeToRemove = styleElement.ptr();
frame->document()->updateStyleIfNeeded();
return styleElement->renderer() ? &styleElement->renderer()->style() : nullptr;
return !childRenderer->nextSibling();
}
-PassRefPtr<HTMLElement> createDefaultParagraphElement(Document& document)
+Ref<HTMLElement> createDefaultParagraphElement(Document& document)
{
switch (document.frame()->editor().defaultParagraphSeparator()) {
case EditorParagraphSeparatorIsDiv:
return HTMLDivElement::create(document);
case EditorParagraphSeparatorIsP:
- return HTMLParagraphElement::create(document);
+ break;
}
-
- ASSERT_NOT_REACHED();
- return 0;
+ return HTMLParagraphElement::create(document);
}
-PassRefPtr<HTMLElement> createBreakElement(Document& document)
+Ref<HTMLElement> createBreakElement(Document& document)
{
return HTMLBRElement::create(document);
}
return positionInParentBeforeNode(node);
}
-PassRefPtr<Element> createTabSpanElement(Document& document, PassRefPtr<Node> prpTabTextNode)
+Ref<Element> createTabSpanElement(Document& document, PassRefPtr<Node> prpTabTextNode)
{
RefPtr<Node> tabTextNode = prpTabTextNode;
if (!tabTextNode)
tabTextNode = document.createEditingTextNode("\t");
- spanElement->appendChild(tabTextNode.release(), ASSERT_NO_EXCEPTION);
+ spanElement->appendChild(tabTextNode.releaseNonNull(), ASSERT_NO_EXCEPTION);
- return spanElement.release();
+ return spanElement.releaseNonNull();
}
-PassRefPtr<Element> createTabSpanElement(Document& document, const String& tabText)
+Ref<Element> createTabSpanElement(Document& document, const String& tabText)
{
return createTabSpanElement(document, document.createTextNode(tabText));
}
-PassRefPtr<Element> createTabSpanElement(Document& document)
+Ref<Element> createTabSpanElement(Document& document)
{
return createTabSpanElement(document, PassRefPtr<Node>());
}
// Functions returning HTMLElement
-WEBCORE_EXPORT PassRefPtr<HTMLElement> createDefaultParagraphElement(Document&);
-PassRefPtr<HTMLElement> createBreakElement(Document&);
+WEBCORE_EXPORT Ref<HTMLElement> createDefaultParagraphElement(Document&);
+Ref<HTMLElement> createBreakElement(Document&);
PassRefPtr<HTMLElement> createOrderedListElement(Document&);
PassRefPtr<HTMLElement> createUnorderedListElement(Document&);
PassRefPtr<HTMLElement> createListItemElement(Document&);
// Element
// -------------------------------------------------------------------------
-PassRefPtr<Element> createTabSpanElement(Document&);
-PassRefPtr<Element> createTabSpanElement(Document&, PassRefPtr<Node> tabTextNode);
-PassRefPtr<Element> createTabSpanElement(Document&, const String& tabText);
-PassRefPtr<Element> createBlockPlaceholderElement(Document&);
+Ref<Element> createTabSpanElement(Document&);
+Ref<Element> createTabSpanElement(Document&, PassRefPtr<Node> tabTextNode);
+Ref<Element> createTabSpanElement(Document&, const String& tabText);
+Ref<Element> createBlockPlaceholderElement(Document&);
Element* editableRootForPosition(const Position&, EditableType = ContentIsEditable);
Element* unsplittableElementForPosition(const Position&);
if (fragment) {
if (newFragment && newFragment->firstChild()) {
ExceptionCode ec;
- fragment->appendChild(newFragment->firstChild(), ec);
+ fragment->appendChild(*newFragment->firstChild(), ec);
}
} else
fragment = newFragment;
return fragment;
}
} else {
- RefPtr<Element> anchor = frame.document()->createElement(HTMLNames::aTag, false);
+ Ref<Element> anchor = frame.document()->createElement(HTMLNames::aTag, false);
anchor->setAttribute(HTMLNames::hrefAttr, url.string());
anchor->appendChild(frame.document()->createTextNode([[(NSURL *)url absoluteString] precomposedStringWithCanonicalMapping]));
RefPtr<DocumentFragment> newFragment = frame.document()->createDocumentFragment();
- newFragment->appendChild(anchor.release());
+ newFragment->appendChild(WTF::move(anchor));
addFragment(newFragment);
return true;
}
if (!resource)
return nullptr;
- RefPtr<Element> imageElement = m_frame.document()->createElement(HTMLNames::imgTag, false);
+ Ref<Element> imageElement = m_frame.document()->createElement(HTMLNames::imgTag, false);
// FIXME: The code in createFragmentAndAddResources calls setDefersLoading(true). Don't we need that here?
if (DocumentLoader* loader = m_frame.loader().documentLoader())
loader->addArchiveResource(resource.get());
imageElement->setAttribute(HTMLNames::srcAttr, [URL isFileURL] ? [URL absoluteString] : resource->url());
RefPtr<DocumentFragment> fragment = m_frame.document()->createDocumentFragment();
- fragment->appendChild(imageElement.release());
+ fragment->appendChild(WTF::move(imageElement));
return fragment.release();
}
for (size_t i = 0; i < size; i++) {
String text = paths[i];
#if ENABLE(ATTACHMENT_ELEMENT)
- RefPtr<HTMLAttachmentElement> attachment = HTMLAttachmentElement::create(attachmentTag, document);
+ Ref<HTMLAttachmentElement> attachment = HTMLAttachmentElement::create(attachmentTag, document);
attachment->setFile(File::create([[NSURL fileURLWithPath:text] path]).ptr());
- fragment->appendChild(attachment.release());
+ fragment->appendChild(WTF::move(attachment));
#else
text = frame.editor().client()->userVisibleString([NSURL fileURLWithPath:text]);
- RefPtr<HTMLElement> paragraph = createDefaultParagraphElement(document);
+ Ref<HTMLElement> paragraph = createDefaultParagraphElement(document);
paragraph->appendChild(document.createTextNode(text));
- fragment->appendChild(paragraph.release());
+ fragment->appendChild(WTF::move(paragraph));
#endif
}
if (url.string().isEmpty())
return false;
- RefPtr<Element> anchor = frame.document()->createElement(HTMLNames::aTag, false);
+ Ref<Element> anchor = frame.document()->createElement(HTMLNames::aTag, false);
anchor->setAttribute(HTMLNames::hrefAttr, url.string());
anchor->appendChild(frame.document()->createTextNode([title precomposedStringWithCanonicalMapping]));
fragment = frame.document()->createDocumentFragment();
- fragment->appendChild(anchor.release());
+ fragment->appendChild(WTF::move(anchor));
return true;
}
if (DocumentLoader* loader = m_frame.loader().documentLoader())
loader->addArchiveResource(resource.get());
- RefPtr<Element> imageElement = document().createElement(HTMLNames::imgTag, false);
+ Ref<Element> imageElement = document().createElement(HTMLNames::imgTag, false);
imageElement->setAttribute(HTMLNames::srcAttr, resource->url().string());
RefPtr<DocumentFragment> fragment = document().createDocumentFragment();
- fragment->appendChild(imageElement.release());
+ fragment->appendChild(WTF::move(imageElement));
return fragment.release();
}
return accumulator.serializeNodes(const_cast<Node&>(node), childrenOnly, tagNamesToSkip);
}
-static void fillContainerFromString(ContainerNode* paragraph, const String& string)
+static void fillContainerFromString(ContainerNode& paragraph, const String& string)
{
- Document& document = paragraph->document();
+ Document& document = paragraph.document();
if (string.isEmpty()) {
- paragraph->appendChild(createBlockPlaceholderElement(document), ASSERT_NO_EXCEPTION);
+ paragraph.appendChild(createBlockPlaceholderElement(document), ASSERT_NO_EXCEPTION);
return;
}
// append the non-tab textual part
if (!s.isEmpty()) {
if (!tabText.isEmpty()) {
- paragraph->appendChild(createTabSpanElement(document, tabText), ASSERT_NO_EXCEPTION);
+ paragraph.appendChild(createTabSpanElement(document, tabText), ASSERT_NO_EXCEPTION);
tabText = emptyString();
}
- RefPtr<Node> textNode = document.createTextNode(stringWithRebalancedWhitespace(s, first, i + 1 == numEntries));
- paragraph->appendChild(textNode.release(), ASSERT_NO_EXCEPTION);
+ Ref<Node> textNode = document.createTextNode(stringWithRebalancedWhitespace(s, first, i + 1 == numEntries));
+ paragraph.appendChild(WTF::move(textNode), ASSERT_NO_EXCEPTION);
}
// there is a tab after every entry, except the last entry
if (i + 1 != numEntries)
tabText.append('\t');
else if (!tabText.isEmpty())
- paragraph->appendChild(createTabSpanElement(document, tabText), ASSERT_NO_EXCEPTION);
+ paragraph.appendChild(createTabSpanElement(document, tabText), ASSERT_NO_EXCEPTION);
first = false;
}
return container->renderer()->style().preserveNewline();
}
-PassRefPtr<DocumentFragment> createFragmentFromText(Range& context, const String& text)
+Ref<DocumentFragment> createFragmentFromText(Range& context, const String& text)
{
Document& document = context.ownerDocument();
- RefPtr<DocumentFragment> fragment = document.createDocumentFragment();
+ Ref<DocumentFragment> fragment = document.createDocumentFragment();
if (text.isEmpty())
- return fragment.release();
+ return fragment;
String string = text;
string.replace("\r\n", "\n");
if (contextPreservesNewline(context)) {
fragment->appendChild(document.createTextNode(string), ASSERT_NO_EXCEPTION);
if (string.endsWith('\n')) {
- RefPtr<Element> element = createBreakElement(document);
+ Ref<Element> element = createBreakElement(document);
element->setAttribute(classAttr, AppleInterchangeNewline);
- fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION);
+ fragment->appendChild(WTF::move(element), ASSERT_NO_EXCEPTION);
}
- return fragment.release();
+ return fragment;
}
// A string with no newlines gets added inline, rather than being put into a paragraph.
if (string.find('\n') == notFound) {
- fillContainerFromString(fragment.get(), string);
- return fragment.release();
+ fillContainerFromString(fragment, string);
+ return fragment;
}
// Break string into paragraphs. Extra line breaks turn into empty paragraphs.
element->setAttribute(classAttr, AppleInterchangeNewline);
} else if (useLineBreak) {
element = createBreakElement(document);
- fillContainerFromString(fragment.get(), s);
+ fillContainerFromString(fragment, s);
} else {
if (useClonesOfEnclosingBlock)
element = block->cloneElementWithoutChildren(document);
else
element = createDefaultParagraphElement(document);
- fillContainerFromString(element.get(), s);
+ fillContainerFromString(*element, s);
}
- fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION);
+ fragment->appendChild(element.releaseNonNull(), ASSERT_NO_EXCEPTION);
}
- return fragment.release();
+ return fragment;
}
String documentTypeString(const Document& document)
RefPtr<Node> nextChild;
for (RefPtr<Node> child = element.firstChild(); child; child = nextChild) {
nextChild = child->nextSibling();
- element.removeChild(child.get(), ASSERT_NO_EXCEPTION);
- fragment.insertBefore(child, &element, ASSERT_NO_EXCEPTION);
+ element.removeChild(*child, ASSERT_NO_EXCEPTION);
+ fragment.insertBefore(*child, &element, ASSERT_NO_EXCEPTION);
}
- fragment.removeChild(&element, ASSERT_NO_EXCEPTION);
+ fragment.removeChild(element, ASSERT_NO_EXCEPTION);
}
PassRefPtr<DocumentFragment> createContextualFragment(const String& markup, HTMLElement* element, ParserContentPolicy parserContentPolicy, ExceptionCode& ec)
return hasOneChild(node) && node.firstChild()->isTextNode();
}
-void replaceChildrenWithFragment(ContainerNode& container, PassRefPtr<DocumentFragment> fragment, ExceptionCode& ec)
+void replaceChildrenWithFragment(ContainerNode& container, Ref<DocumentFragment>&& fragment, ExceptionCode& ec)
{
Ref<ContainerNode> containerNode(container);
ChildListMutationScope mutation(containerNode);
return;
}
- if (hasOneTextChild(containerNode) && hasOneTextChild(*fragment)) {
+ if (hasOneTextChild(containerNode) && hasOneTextChild(fragment)) {
downcast<Text>(*containerNode->firstChild()).setData(downcast<Text>(*fragment->firstChild()).data(), ec);
return;
}
if (hasOneChild(containerNode)) {
- containerNode->replaceChild(fragment, containerNode->firstChild(), ec);
+ containerNode->replaceChild(WTF::move(fragment), *containerNode->firstChild(), ec);
return;
}
containerNode->removeChildren();
- containerNode->appendChild(fragment, ec);
+ containerNode->appendChild(WTF::move(fragment), ec);
}
void replaceChildrenWithText(ContainerNode& container, const String& text, ExceptionCode& ec)
Ref<Text> textNode = Text::create(containerNode->document(), text);
if (hasOneChild(containerNode)) {
- containerNode->replaceChild(WTF::move(textNode), containerNode->firstChild(), ec);
+ containerNode->replaceChild(WTF::move(textNode), *containerNode->firstChild(), ec);
return;
}
enum EAbsoluteURLs { DoNotResolveURLs, ResolveAllURLs, ResolveNonLocalURLs };
enum EFragmentSerialization { HTMLFragmentSerialization, XMLFragmentSerialization };
-WEBCORE_EXPORT PassRefPtr<DocumentFragment> createFragmentFromText(Range& context, const String& text);
+WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromText(Range& context, const String& text);
WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromMarkup(Document&, const String& markup, const String& baseURL, ParserContentPolicy = AllowScriptingContent);
PassRefPtr<DocumentFragment> createFragmentForInnerOuterHTML(const String&, Element*, ParserContentPolicy, ExceptionCode&);
PassRefPtr<DocumentFragment> createFragmentForTransformToFragment(const String&, const String& sourceMIMEType, Document* outputDoc);
// These methods are used by HTMLElement & ShadowRoot to replace the
// children with respected fragment/text.
-void replaceChildrenWithFragment(ContainerNode&, PassRefPtr<DocumentFragment>, ExceptionCode&);
+void replaceChildrenWithFragment(ContainerNode&, Ref<DocumentFragment>&&, ExceptionCode&);
void replaceChildrenWithText(ContainerNode&, const String&, ExceptionCode&);
-String createMarkup(const Range&, Vector<Node*>* = 0, EAnnotateForInterchange = DoNotAnnotateForInterchange, bool convertBlocksToInlines = false, EAbsoluteURLs = DoNotResolveURLs);
-String createMarkup(const Node&, EChildrenOnly = IncludeNode, Vector<Node*>* = 0, EAbsoluteURLs = DoNotResolveURLs, Vector<QualifiedName>* tagNamesToSkip = 0, EFragmentSerialization = HTMLFragmentSerialization);
+String createMarkup(const Range&, Vector<Node*>* = nullptr, EAnnotateForInterchange = DoNotAnnotateForInterchange, bool convertBlocksToInlines = false, EAbsoluteURLs = DoNotResolveURLs);
+String createMarkup(const Node&, EChildrenOnly = IncludeNode, Vector<Node*>* = nullptr, EAbsoluteURLs = DoNotResolveURLs, Vector<QualifiedName>* tagNamesToSkip = 0, EFragmentSerialization = HTMLFragmentSerialization);
WEBCORE_EXPORT String createFullMarkup(const Node&);
WEBCORE_EXPORT String createFullMarkup(const Range&);
{
DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, valueContainerPseudo, ("-webkit-date-and-time-value", AtomicString::ConstructFromLiteral));
- RefPtr<HTMLDivElement> valueContainer = HTMLDivElement::create(element().document());
+ Ref<HTMLDivElement> valueContainer = HTMLDivElement::create(element().document());
valueContainer->setPseudo(valueContainerPseudo);
- element().userAgentShadowRoot()->appendChild(valueContainer.get());
+ element().userAgentShadowRoot()->appendChild(WTF::move(valueContainer));
updateAppearance();
}
ASSERT(element().shadowRoot());
Document& document = element().document();
- RefPtr<HTMLDivElement> wrapperElement = HTMLDivElement::create(document);
+ Ref<HTMLDivElement> wrapperElement = HTMLDivElement::create(document);
wrapperElement->setPseudo(AtomicString("-webkit-color-swatch-wrapper", AtomicString::ConstructFromLiteral));
- RefPtr<HTMLDivElement> colorSwatch = HTMLDivElement::create(document);
+ Ref<HTMLDivElement> colorSwatch = HTMLDivElement::create(document);
colorSwatch->setPseudo(AtomicString("-webkit-color-swatch", AtomicString::ConstructFromLiteral));
- wrapperElement->appendChild(colorSwatch.release(), ASSERT_NO_EXCEPTION);
- element().userAgentShadowRoot()->appendChild(wrapperElement.release(), ASSERT_NO_EXCEPTION);
+ wrapperElement->appendChild(WTF::move(colorSwatch), ASSERT_NO_EXCEPTION);
+ element().userAgentShadowRoot()->appendChild(WTF::move(wrapperElement), ASSERT_NO_EXCEPTION);
updateColorSwatch();
}
RefPtr<Element> rowElement = m_tableElement->insertRow(-1, IGNORE_EXCEPTION);
rowElement->setAttribute(HTMLNames::classAttr, "ftpDirectoryEntryRow");
- RefPtr<Element> element = document()->createElement(tdTag, false);
+ Ref<Element> element = document()->createElement(tdTag, false);
element->appendChild(Text::create(*document(), String(&noBreakSpace, 1)), IGNORE_EXCEPTION);
if (isDirectory)
element->setAttribute(HTMLNames::classAttr, "ftpDirectoryIcon ftpDirectoryTypeDirectory");
else
element->setAttribute(HTMLNames::classAttr, "ftpDirectoryIcon ftpDirectoryTypeFile");
- rowElement->appendChild(element, IGNORE_EXCEPTION);
+ rowElement->appendChild(WTF::move(element), IGNORE_EXCEPTION);
element = createTDForFilename(filename);
element->setAttribute(HTMLNames::classAttr, "ftpDirectoryFileName");
- rowElement->appendChild(element, IGNORE_EXCEPTION);
+ rowElement->appendChild(WTF::move(element), IGNORE_EXCEPTION);
element = document()->createElement(tdTag, false);
element->appendChild(Text::create(*document(), date), IGNORE_EXCEPTION);
element->setAttribute(HTMLNames::classAttr, "ftpDirectoryFileDate");
- rowElement->appendChild(element, IGNORE_EXCEPTION);
+ rowElement->appendChild(WTF::move(element), IGNORE_EXCEPTION);
element = document()->createElement(tdTag, false);
element->appendChild(Text::create(*document(), size), IGNORE_EXCEPTION);
element->setAttribute(HTMLNames::classAttr, "ftpDirectoryFileSize");
- rowElement->appendChild(element, IGNORE_EXCEPTION);
+ rowElement->appendChild(WTF::move(element), IGNORE_EXCEPTION);
}
Ref<Element> FTPDirectoryDocumentParser::createTDForFilename(const String& filename)
else
fullURL = fullURL + '/' + filename;
- RefPtr<Element> anchorElement = document()->createElement(aTag, false);
+ Ref<Element> anchorElement = document()->createElement(aTag, false);
anchorElement->setAttribute(HTMLNames::hrefAttr, fullURL);
anchorElement->appendChild(Text::create(*document(), filename), IGNORE_EXCEPTION);
Ref<Element> tdElement = document()->createElement(tdTag, false);
- tdElement->appendChild(anchorElement, IGNORE_EXCEPTION);
+ tdElement->appendChild(WTF::move(anchorElement), IGNORE_EXCEPTION);
return tdElement;
}
// If that fails for some reason, cram it on the end of the document as a last
// ditch effort
if (auto* body = document()->bodyOrFrameset())
- body->appendChild(m_tableElement, IGNORE_EXCEPTION);
+ body->appendChild(*m_tableElement, IGNORE_EXCEPTION);
else
- document()->appendChild(m_tableElement, IGNORE_EXCEPTION);
+ document()->appendChild(*m_tableElement, IGNORE_EXCEPTION);
return true;
}
// FIXME: Make this "basic document" more acceptable
- RefPtr<Element> bodyElement = document()->createElement(bodyTag, false);
+ Ref<Element> bodyElement = document()->createElement(bodyTag, false);
- document()->appendChild(bodyElement, IGNORE_EXCEPTION);
+ document()->appendChild(bodyElement.copyRef(), IGNORE_EXCEPTION);
- RefPtr<Element> tableElement = document()->createElement(tableTag, false);
- m_tableElement = downcast<HTMLTableElement>(tableElement.get());
+ Ref<Element> tableElement = document()->createElement(tableTag, false);
+ m_tableElement = downcast<HTMLTableElement>(tableElement.ptr());
m_tableElement->setAttribute(HTMLNames::idAttr, "ftpDirectoryTable");
m_tableElement->setAttribute(HTMLNames::styleAttr, "width:100%");
- bodyElement->appendChild(m_tableElement, IGNORE_EXCEPTION);
+ bodyElement->appendChild(WTF::move(tableElement), IGNORE_EXCEPTION);
document()->processViewport("width=device-width", ViewportArguments::ViewportMeta);
}
Ref<DetailsSummaryElement> DetailsSummaryElement::create(Document& document)
{
- RefPtr<HTMLSummaryElement> summary = HTMLSummaryElement::create(summaryTag, document);
+ Ref<HTMLSummaryElement> summary = HTMLSummaryElement::create(summaryTag, document);
summary->appendChild(Text::create(document, defaultDetailsSummaryText()), ASSERT_NO_EXCEPTION);
Ref<DetailsSummaryElement> detailsSummary = adoptRef(*new DetailsSummaryElement(document));
- detailsSummary->appendChild(summary);
+ detailsSummary->appendChild(WTF::move(summary));
return detailsSummary;
}
// Add text nodes and <br> elements.
ec = 0;
- RefPtr<DocumentFragment> fragment = textToFragment(text, ec);
+ Ref<DocumentFragment> fragment = textToFragment(text, ec);
if (!ec)
- replaceChildrenWithFragment(*this, fragment.release(), ec);
+ replaceChildrenWithFragment(*this, WTF::move(fragment), ec);
}
void HTMLElement::setOuterText(const String& text, ExceptionCode& ec)
ec = HIERARCHY_REQUEST_ERR;
if (ec)
return;
- parent->replaceChild(newChild.release(), this, ec);
+ parent->replaceChild(newChild.releaseNonNull(), *this, ec);
RefPtr<Node> node = next ? next->previousSibling() : nullptr;
if (!ec && is<Text>(node.get()))
mergeWithNextTextNode(downcast<Text>(*prev), ec);
}
-Node* HTMLElement::insertAdjacent(const String& where, Node* newChild, ExceptionCode& ec)
+Node* HTMLElement::insertAdjacent(const String& where, Ref<Node>&& newChild, ExceptionCode& ec)
{
// In Internet Explorer if the element has no parent and where is "beforeBegin" or "afterEnd",
// a document fragment is created and the elements appended in the correct order. This document
if (equalIgnoringCase(where, "beforeBegin")) {
ContainerNode* parent = this->parentNode();
- return (parent && parent->insertBefore(newChild, this, ec)) ? newChild : nullptr;
+ return (parent && parent->insertBefore(newChild.copyRef(), this, ec)) ? newChild.ptr() : nullptr;
}
if (equalIgnoringCase(where, "afterBegin"))
- return insertBefore(newChild, firstChild(), ec) ? newChild : nullptr;
+ return insertBefore(newChild.copyRef(), firstChild(), ec) ? newChild.ptr() : nullptr;
if (equalIgnoringCase(where, "beforeEnd"))
- return appendChild(newChild, ec) ? newChild : nullptr;
+ return appendChild(newChild.copyRef(), ec) ? newChild.ptr() : nullptr;
if (equalIgnoringCase(where, "afterEnd")) {
ContainerNode* parent = this->parentNode();
- return (parent && parent->insertBefore(newChild, nextSibling(), ec)) ? newChild : nullptr;
+ return (parent && parent->insertBefore(newChild.copyRef(), nextSibling(), ec)) ? newChild.ptr() : nullptr;
}
// IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative.
return nullptr;
}
- Node* returnValue = insertAdjacent(where, newChild, ec);
+ Node* returnValue = insertAdjacent(where, *newChild, ec);
ASSERT_WITH_SECURITY_IMPLICATION(!returnValue || is<Element>(*returnValue));
return downcast<Element>(returnValue);
}
RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, contextElement, AllowScriptingContent, ec);
if (!fragment)
return;
- insertAdjacent(where, fragment.get(), ec);
+ insertAdjacent(where, fragment.releaseNonNull(), ec);
}
void HTMLElement::insertAdjacentText(const String& where, const String& text, ExceptionCode& ec)
{
- RefPtr<Text> textNode = document().createTextNode(text);
- insertAdjacent(where, textNode.get(), ec);
+ insertAdjacent(where, document().createTextNode(text), ec);
}
void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment, MutableStyleProperties& style)
virtual HTMLFormElement* virtualForm() const;
- Node* insertAdjacent(const String& where, Node* newChild, ExceptionCode&);
+ Node* insertAdjacent(const String& where, Ref<Node>&& newChild, ExceptionCode&);
Ref<DocumentFragment> textToFragment(const String&, ExceptionCode&);
void dirAttributeChanged(const AtomicString&);
if (!imageControls)
return;
- ensureUserAgentShadowRoot().appendChild(imageControls);
+ ensureUserAgentShadowRoot().appendChild(imageControls.releaseNonNull());
auto* renderObject = renderer();
if (!renderObject)
if (Node* node = shadowRoot->firstChild()) {
ASSERT_WITH_SECURITY_IMPLICATION(node->isImageControlsRootElement());
- shadowRoot->removeChild(node);
+ shadowRoot->removeChild(*node);
}
auto* renderObject = renderer();
}
private:
- virtual RefPtr<Element> cloneElementWithoutAttributesAndChildren(Document& targetDocument) override
+ virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document& targetDocument) override
{
return create(targetDocument);
}
Vector<String> keys;
getSupportedKeySizes(keys);
- RefPtr<HTMLSelectElement> select = KeygenSelectElement::create(document);
+ Ref<HTMLSelectElement> select = KeygenSelectElement::create(document);
for (size_t i = 0; i < keys.size(); ++i) {
- RefPtr<HTMLOptionElement> option = HTMLOptionElement::create(document);
- select->appendChild(option, IGNORE_EXCEPTION);
+ Ref<HTMLOptionElement> option = HTMLOptionElement::create(document);
+ select->appendChild(option.copyRef(), IGNORE_EXCEPTION);
option->appendChild(Text::create(document, keys[i]), IGNORE_EXCEPTION);
}
- ensureUserAgentShadowRoot().appendChild(select, IGNORE_EXCEPTION);
+ ensureUserAgentShadowRoot().appendChild(WTF::move(select), IGNORE_EXCEPTION);
}
Ref<HTMLKeygenElement> HTMLKeygenElement::create(const QualifiedName& tagName, Document& document, HTMLFormElement* form)
{
ASSERT(!m_value);
- RefPtr<MeterInnerElement> inner = MeterInnerElement::create(document());
- root->appendChild(inner);
+ Ref<MeterInnerElement> inner = MeterInnerElement::create(document());
+ root->appendChild(inner.copyRef());
- RefPtr<MeterBarElement> bar = MeterBarElement::create(document());
+ Ref<MeterBarElement> bar = MeterBarElement::create(document());
m_value = MeterValueElement::create(document());
m_value->setWidthPercentage(0);
m_value->updatePseudo();
- bar->appendChild(m_value, ASSERT_NO_EXCEPTION);
+ bar->appendChild(*m_value, ASSERT_NO_EXCEPTION);
- inner->appendChild(bar, ASSERT_NO_EXCEPTION);
+ inner->appendChild(WTF::move(bar), ASSERT_NO_EXCEPTION);
}
} // namespace
{
RefPtr<HTMLOptionElement> element = adoptRef(new HTMLOptionElement(optionTag, document));
- RefPtr<Text> text = Text::create(document, data.isNull() ? "" : data);
+ Ref<Text> text = Text::create(document, data.isNull() ? "" : data);
ec = 0;
- element->appendChild(text.release(), ec);
+ element->appendChild(WTF::move(text), ec);
if (ec)
- return 0;
+ return nullptr;
if (!value.isNull())
element->setValue(value);
element->setAttribute(selectedAttr, emptyAtom);
element->setSelected(selected);
- return element.release();
+ return element;
}
bool HTMLOptionElement::isFocusable() const
{
ASSERT(!m_value);
- RefPtr<ProgressInnerElement> inner = ProgressInnerElement::create(document());
- root->appendChild(inner);
+ Ref<ProgressInnerElement> inner = ProgressInnerElement::create(document());
+ root->appendChild(inner.copyRef());
- RefPtr<ProgressBarElement> bar = ProgressBarElement::create(document());
- RefPtr<ProgressValueElement> value = ProgressValueElement::create(document());
- m_value = value.get();
+ Ref<ProgressBarElement> bar = ProgressBarElement::create(document());
+ Ref<ProgressValueElement> value = ProgressValueElement::create(document());
+ m_value = value.ptr();
m_value->setWidthPercentage(HTMLProgressElement::IndeterminatePosition * 100);
- bar->appendChild(m_value, ASSERT_NO_EXCEPTION);
+ bar->appendChild(*m_value, ASSERT_NO_EXCEPTION);
- inner->appendChild(bar, ASSERT_NO_EXCEPTION);
+ inner->appendChild(WTF::move(bar), ASSERT_NO_EXCEPTION);
}
bool HTMLProgressElement::shouldAppearIndeterminate() const
dispatchEvent(Event::create(eventNames().loadEvent, false, false));
}
-RefPtr<Element> HTMLScriptElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
+Ref<Element> HTMLScriptElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
{
- return adoptRef(new HTMLScriptElement(tagQName(), targetDocument, false, alreadyStarted()));
+ return adoptRef(*new HTMLScriptElement(tagQName(), targetDocument, false, alreadyStarted()));
}
}
virtual void dispatchLoadEvent() override;
- virtual RefPtr<Element> cloneElementWithoutAttributesAndChildren(Document&) override;
+ virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document&) override;
};
} //namespace
// Make sure the element is ref'd and deref'd so we don't leak it.
Ref<HTMLElement> protectNewChild(*element);
- insertBefore(element, beforeElement, ec);
+ insertBefore(*element, beforeElement, ec);
updateValidity();
}
// Removing children fires mutation events, which might mutate the DOM further, so we first copy out a list
// of elements that we intend to remove then attempt to remove them one at a time.
- Vector<RefPtr<Element>> itemsToRemove;
+ Vector<Ref<Element>> itemsToRemove;
size_t optionIndex = 0;
for (auto& item : items) {
if (is<HTMLOptionElement>(*item) && optionIndex++ >= newLen) {
ASSERT(item->parentNode());
- itemsToRemove.append(item);
+ itemsToRemove.append(*item);
}
}
{
deleteCaption();
if (newCaption)
- insertBefore(newCaption, firstChild(), ec);
+ insertBefore(*newCaption, firstChild(), ec);
}
HTMLTableSectionElement* HTMLTableElement::tHead() const
if (child->isElementNode() && !child->hasTagName(captionTag) && !child->hasTagName(colgroupTag))
break;
- insertBefore(newHead, child, ec);
+ insertBefore(*newHead, child, ec);
}
HTMLTableSectionElement* HTMLTableElement::tFoot() const
if (child->isElementNode() && !child->hasTagName(captionTag) && !child->hasTagName(colgroupTag) && !child->hasTagName(theadTag))
break;
- insertBefore(newFoot, child, ec);
+ insertBefore(*newFoot, child, ec);
}
-RefPtr<HTMLElement> HTMLTableElement::createTHead()
+Ref<HTMLTableSectionElement> HTMLTableElement::createTHead()
{
if (HTMLTableSectionElement* existingHead = tHead())
- return existingHead;
- RefPtr<HTMLTableSectionElement> head = HTMLTableSectionElement::create(theadTag, document());
- setTHead(head, IGNORE_EXCEPTION);
+ return *existingHead;
+ Ref<HTMLTableSectionElement> head = HTMLTableSectionElement::create(theadTag, document());
+ setTHead(head.ptr(), IGNORE_EXCEPTION);
return head;
}
void HTMLTableElement::deleteTHead()
{
- removeChild(tHead(), IGNORE_EXCEPTION);
+ if (auto* tHead = this->tHead())
+ removeChild(*tHead, IGNORE_EXCEPTION);
}
-RefPtr<HTMLElement> HTMLTableElement::createTFoot()
+Ref<HTMLTableSectionElement> HTMLTableElement::createTFoot()
{
if (HTMLTableSectionElement* existingFoot = tFoot())
- return existingFoot;
- RefPtr<HTMLTableSectionElement> foot = HTMLTableSectionElement::create(tfootTag, document());
- setTFoot(foot, IGNORE_EXCEPTION);
+ return *existingFoot;
+ Ref<HTMLTableSectionElement> foot = HTMLTableSectionElement::create(tfootTag, document());
+ setTFoot(foot.ptr(), IGNORE_EXCEPTION);
return foot;
}
void HTMLTableElement::deleteTFoot()
{
- removeChild(tFoot(), IGNORE_EXCEPTION);
+ if (auto* tFoot = this->tFoot())
+ removeChild(*tFoot, IGNORE_EXCEPTION);
}
-RefPtr<HTMLElement> HTMLTableElement::createTBody()
+Ref<HTMLTableSectionElement> HTMLTableElement::createTBody()
{
- RefPtr<HTMLTableSectionElement> body = HTMLTableSectionElement::create(tbodyTag, document());
- Node* referenceElement = lastBody() ? lastBody()->nextSibling() : 0;
- insertBefore(body, referenceElement, ASSERT_NO_EXCEPTION);
+ Ref<HTMLTableSectionElement> body = HTMLTableSectionElement::create(tbodyTag, document());
+ Node* referenceElement = lastBody() ? lastBody()->nextSibling() : nullptr;
+ insertBefore(body.copyRef(), referenceElement, ASSERT_NO_EXCEPTION);
return body;
}
-RefPtr<HTMLElement> HTMLTableElement::createCaption()
+Ref<HTMLTableCaptionElement> HTMLTableElement::createCaption()
{
if (HTMLTableCaptionElement* existingCaption = caption())
- return existingCaption;
- RefPtr<HTMLTableCaptionElement> caption = HTMLTableCaptionElement::create(captionTag, document());
- setCaption(caption, IGNORE_EXCEPTION);
+ return *existingCaption;
+ Ref<HTMLTableCaptionElement> caption = HTMLTableCaptionElement::create(captionTag, document());
+ setCaption(caption.ptr(), IGNORE_EXCEPTION);
return caption;
}
void HTMLTableElement::deleteCaption()
{
- removeChild(caption(), IGNORE_EXCEPTION);
+ if (auto* caption = this->caption())
+ removeChild(*caption, IGNORE_EXCEPTION);
}
HTMLTableSectionElement* HTMLTableElement::lastBody() const
else {
parent = lastBody();
if (!parent) {
- RefPtr<HTMLTableSectionElement> newBody = HTMLTableSectionElement::create(tbodyTag, document());
- RefPtr<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document());
- newBody->appendChild(newRow, ec);
- appendChild(newBody.release(), ec);
- return newRow;
+ Ref<HTMLTableSectionElement> newBody = HTMLTableSectionElement::create(tbodyTag, document());
+ Ref<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document());
+ newBody->appendChild(newRow.copyRef(), ec);
+ appendChild(WTF::move(newBody), ec);
+ return WTF::move(newRow);
}
}
- RefPtr<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document());
- parent->insertBefore(newRow, row.get(), ec);
- return newRow;
+ Ref<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document());
+ parent->insertBefore(newRow.copyRef(), row.get(), ec);
+ return WTF::move(newRow);
}
void HTMLTableElement::deleteRow(int index, ExceptionCode& ec)
{
- HTMLTableRowElement* row = 0;
+ HTMLTableRowElement* row = nullptr;
if (index == -1)
row = HTMLTableRowsCollection::lastRow(*this);
else {
HTMLTableSectionElement* tFoot() const;
void setTFoot(PassRefPtr<HTMLTableSectionElement>, ExceptionCode&);
- RefPtr<HTMLElement> createTHead();
+ Ref<HTMLTableSectionElement> createTHead();
void deleteTHead();
- RefPtr<HTMLElement> createTFoot();
+ Ref<HTMLTableSectionElement> createTFoot();
void deleteTFoot();
- RefPtr<HTMLElement> createTBody();
- RefPtr<HTMLElement> createCaption();
+ Ref<HTMLTableSectionElement> createTBody();
+ Ref<HTMLTableCaptionElement> createCaption();
void deleteCaption();
RefPtr<HTMLElement> insertRow(ExceptionCode& ec) { return insertRow(-1, ec); }
RefPtr<HTMLElement> insertRow(int index, ExceptionCode&);
#include "ExceptionCode.h"
#include "GenericCachedHTMLCollection.h"
#include "HTMLNames.h"
-#include "HTMLTableCellElement.h"
#include "HTMLTableElement.h"
#include "HTMLTableSectionElement.h"
#include "NodeList.h"
return rIndex;
}
-RefPtr<HTMLElement> HTMLTableRowElement::insertCell(int index, ExceptionCode& ec)
+RefPtr<HTMLTableCellElement> HTMLTableRowElement::insertCell(int index, ExceptionCode& ec)
{
Ref<HTMLCollection> children = cells();
int numCells = children->length();
if (index < -1 || index > numCells) {
ec = INDEX_SIZE_ERR;
- return 0;
+ return nullptr;
}
- RefPtr<HTMLTableCellElement> cell = HTMLTableCellElement::create(tdTag, document());
+ Ref<HTMLTableCellElement> cell = HTMLTableCellElement::create(tdTag, document());
if (index < 0 || index >= numCells)
- appendChild(cell, ec);
+ appendChild(cell.copyRef(), ec);
else {
Node* n;
if (index < 1)
n = firstChild();
else
n = children->item(index);
- insertBefore(cell, n, ec);
+ insertBefore(cell.copyRef(), n, ec);
}
- return cell;
+ return WTF::move(cell);
}
void HTMLTableRowElement::deleteCell(int index, ExceptionCode& ec)
index = numCells-1;
if (index >= 0 && index < numCells) {
RefPtr<Node> cell = children->item(index);
- HTMLElement::removeChild(cell.get(), ec);
+ HTMLElement::removeChild(*cell, ec);
} else
ec = INDEX_SIZE_ERR;
}
#ifndef HTMLTableRowElement_h
#define HTMLTableRowElement_h
+#include "HTMLTableCellElement.h"
#include "HTMLTablePartElement.h"
namespace WebCore {
int sectionRowIndex() const;
void setSectionRowIndex(int);
- RefPtr<HTMLElement> insertCell(ExceptionCode& ec) { return insertCell(-1, ec); }
- RefPtr<HTMLElement> insertCell(int index, ExceptionCode&);
+ RefPtr<HTMLTableCellElement> insertCell(ExceptionCode& ec) { return insertCell(-1, ec); }
+ RefPtr<HTMLTableCellElement> insertCell(int index, ExceptionCode&);
void deleteCell(int index, ExceptionCode&);
Ref<HTMLCollection> cells();
else {
row = HTMLTableRowElement::create(trTag, document());
if (numRows == index || index == -1)
- appendChild(row, ec);
+ appendChild(*row, ec);
else {
Node* n;
if (index < 1)
n = firstChild();
else
n = children->item(index);
- insertBefore(row, n, ec);
+ insertBefore(*row, n, ec);
}
}
return row;
index = numRows - 1;
if (index >= 0 && index < numRows) {
RefPtr<Node> row = children->item(index);
- HTMLElement::removeChild(row.get(), ec);
+ HTMLElement::removeChild(*row, ec);
} else
ec = INDEX_SIZE_ERR;
}
return m_content.get();
}
-RefPtr<Node> HTMLTemplateElement::cloneNodeInternal(Document& targetDocument, CloningOperation type)
+Ref<Node> HTMLTemplateElement::cloneNodeInternal(Document& targetDocument, CloningOperation type)
{
RefPtr<Node> clone;
switch (type) {
break;
}
if (m_content)
- content()->cloneChildNodes(downcast<HTMLTemplateElement>(clone.get())->content());
- return clone.release();
+ content()->cloneChildNodes(*downcast<HTMLTemplateElement>(clone.get())->content());
+ return clone.releaseNonNull();
}
void HTMLTemplateElement::didMoveToNewDocument(Document* oldDocument)
private:
HTMLTemplateElement(const QualifiedName&, Document&);
- virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
+ virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
virtual void didMoveToNewDocument(Document* oldDocument) override;
mutable RefPtr<TemplateContentDocumentFragment> m_content;
Ref<HTMLTextAreaElement> protectFromMutationEvents(*this);
// To preserve comments, remove only the text nodes, then add a single text node.
- Vector<RefPtr<Text>> textNodes;
+ Vector<Ref<Text>> textNodes;
for (Text* textNode = TextNodeTraversal::firstChild(*this); textNode; textNode = TextNodeTraversal::nextSibling(*textNode))
- textNodes.append(textNode);
+ textNodes.append(*textNode);
size_t size = textNodes.size();
for (size_t i = 0; i < size; ++i)
String placeholderText = strippedPlaceholder();
if (placeholderText.isEmpty()) {
if (m_placeholder) {
- userAgentShadowRoot()->removeChild(m_placeholder, ASSERT_NO_EXCEPTION);
- m_placeholder = 0;
+ userAgentShadowRoot()->removeChild(*m_placeholder, ASSERT_NO_EXCEPTION);
+ m_placeholder = nullptr;
}
return;
}
m_placeholder = placeholder.get();
m_placeholder->setPseudo(AtomicString("-webkit-input-placeholder", AtomicString::ConstructFromLiteral));
m_placeholder->setInlineStyleProperty(CSSPropertyDisplay, isPlaceholderVisible() ? CSSValueBlock : CSSValueNone, true);
- userAgentShadowRoot()->insertBefore(m_placeholder, innerTextElement()->nextSibling());
+ userAgentShadowRoot()->insertBefore(*m_placeholder, innerTextElement()->nextSibling());
}
m_placeholder->setInnerText(placeholderText, ASSERT_NO_EXCEPTION);
}
class ImageDocumentElement final : public HTMLImageElement {
public:
- static RefPtr<ImageDocumentElement> create(ImageDocument&);
+ static Ref<ImageDocumentElement> create(ImageDocument&);
private:
ImageDocumentElement(ImageDocument& document)
ImageDocument* m_imageDocument;
};
-inline RefPtr<ImageDocumentElement> ImageDocumentElement::create(ImageDocument& document)
+inline Ref<ImageDocumentElement> ImageDocumentElement::create(ImageDocument& document)
{
- return adoptRef(new ImageDocumentElement(document));
+ return adoptRef(*new ImageDocumentElement(document));
}
// --------
void ImageDocument::createDocumentStructure()
{
- RefPtr<Element> rootElement = Document::createElement(htmlTag, false);
- appendChild(rootElement);
- downcast<HTMLHtmlElement>(*rootElement).insertedByParser();
+ Ref<Element> rootElement = Document::createElement(htmlTag, false);
+ appendChild(rootElement.copyRef());
+ downcast<HTMLHtmlElement>(rootElement.get()).insertedByParser();
frame()->injectUserScripts(InjectAtDocumentStart);
- RefPtr<Element> body = Document::createElement(bodyTag, false);
+ Ref<Element> body = Document::createElement(bodyTag, false);
body->setAttribute(styleAttr, "margin: 0px");
if (MIMETypeRegistry::isPDFMIMEType(document().loader()->responseMIMEType()))
- downcast<HTMLBodyElement>(*body).setInlineStyleProperty(CSSPropertyBackgroundColor, "white", CSSPrimitiveValue::CSS_IDENT);
- rootElement->appendChild(body);
+ downcast<HTMLBodyElement>(body.get()).setInlineStyleProperty(CSSPropertyBackgroundColor, "white", CSSPrimitiveValue::CSS_IDENT);
+ rootElement->appendChild(body.copyRef());
- RefPtr<ImageDocumentElement> imageElement = ImageDocumentElement::create(*this);
+ Ref<ImageDocumentElement> imageElement = ImageDocumentElement::create(*this);
if (m_shouldShrinkImage)
imageElement->setAttribute(styleAttr, "-webkit-user-select:none; display:block; margin:auto;");
else
imageElement->setLoadManually(true);
imageElement->setSrc(url().string());
imageElement->cachedImage()->setResponse(loader()->response());
- body->appendChild(imageElement);
+ body->appendChild(imageElement.copyRef());
if (m_shouldShrinkImage) {
#if PLATFORM(IOS)
#endif
}
- m_imageElement = imageElement.get();
+ m_imageElement = imageElement.ptr();
}
void ImageDocument::imageUpdated()
void MediaDocumentParser::createDocumentStructure()
{
- RefPtr<Element> rootElement = document()->createElement(htmlTag, false);
- document()->appendChild(rootElement, IGNORE_EXCEPTION);
- document()->setCSSTarget(rootElement.get());
- downcast<HTMLHtmlElement>(*rootElement).insertedByParser();
+ Ref<Element> rootElement = document()->createElement(htmlTag, false);
+ document()->appendChild(rootElement.copyRef(), IGNORE_EXCEPTION);
+ document()->setCSSTarget(rootElement.ptr());
+ downcast<HTMLHtmlElement>(rootElement.get()).insertedByParser();
if (document()->frame())
document()->frame()->injectUserScripts(InjectAtDocumentStart);
#if PLATFORM(IOS)
- RefPtr<Element> headElement = document()->createElement(headTag, false);
- rootElement->appendChild(headElement, IGNORE_EXCEPTION);
+ Ref<Element> headElement = document()->createElement(headTag, false);
+ rootElement->appendChild(headElement.copyRef(), IGNORE_EXCEPTION);
- RefPtr<Element> metaElement = document()->createElement(metaTag, false);
+ Ref<Element> metaElement = document()->createElement(metaTag, false);
metaElement->setAttribute(nameAttr, "viewport");
metaElement->setAttribute(contentAttr, "width=device-width,initial-scale=1,user-scalable=no");
- headElement->appendChild(metaElement, IGNORE_EXCEPTION);
+ headElement->appendChild(WTF::move(metaElement), IGNORE_EXCEPTION);
#endif
- RefPtr<Element> body = document()->createElement(bodyTag, false);
- rootElement->appendChild(body, IGNORE_EXCEPTION);
+ Ref<Element> body = document()->createElement(bodyTag, false);
+ rootElement->appendChild(body.copyRef(), IGNORE_EXCEPTION);
- RefPtr<Element> mediaElement = document()->createElement(videoTag, false);
+ Ref<Element> mediaElement = document()->createElement(videoTag, false);
- m_mediaElement = downcast<HTMLVideoElement>(mediaElement.get());
+ m_mediaElement = downcast<HTMLVideoElement>(mediaElement.ptr());
m_mediaElement->setAttribute(controlsAttr, emptyAtom);
m_mediaElement->setAttribute(autoplayAttr, emptyAtom);
#endif
m_mediaElement->setAttribute(styleAttr, elementStyle.toString());
- RefPtr<Element> sourceElement = document()->createElement(sourceTag, false);
- HTMLSourceElement& source = downcast<HTMLSourceElement>(*sourceElement);
+ Ref<Element> sourceElement = document()->createElement(sourceTag, false);
+ HTMLSourceElement& source = downcast<HTMLSourceElement>(sourceElement.get());
source.setSrc(document()->url());
if (DocumentLoader* loader = document()->loader())
source.setType(loader->responseMIMEType());
- m_mediaElement->appendChild(sourceElement, IGNORE_EXCEPTION);
- body->appendChild(mediaElement, IGNORE_EXCEPTION);
+ m_mediaElement->appendChild(WTF::move(sourceElement), IGNORE_EXCEPTION);
+ body->appendChild(WTF::move(mediaElement), IGNORE_EXCEPTION);
Frame* frame = document()->frame();
if (!frame)
if (documentLoader)
embedElement.setAttribute(typeAttr, documentLoader->writer().mimeType());
- videoElement->parentNode()->replaceChild(&embedElement, videoElement, IGNORE_EXCEPTION);
+ videoElement->parentNode()->replaceChild(embedElement, *videoElement, IGNORE_EXCEPTION);
}
}
void PluginDocumentParser::createDocumentStructure()
{
- RefPtr<Element> rootElement = document()->createElement(htmlTag, false);
- document()->appendChild(rootElement, IGNORE_EXCEPTION);
- downcast<HTMLHtmlElement>(*rootElement).insertedByParser();
+ Ref<Element> rootElement = document()->createElement(htmlTag, false);
+ document()->appendChild(rootElement.copyRef(), IGNORE_EXCEPTION);
+ downcast<HTMLHtmlElement>(rootElement.get()).insertedByParser();
if (document()->frame())
document()->frame()->injectUserScripts(InjectAtDocumentStart);
document()->processViewport(ASCIILiteral("user-scalable=no"), ViewportArguments::PluginDocument);
#endif
- RefPtr<Element> body = document()->createElement(bodyTag, false);
+ Ref<Element> body = document()->createElement(bodyTag, false);
body->setAttribute(marginwidthAttr, AtomicString("0", AtomicString::ConstructFromLiteral));
body->setAttribute(marginheightAttr, AtomicString("0", AtomicString::ConstructFromLiteral));
#if PLATFORM(IOS)
body->setAttribute(styleAttr, AtomicString("background-color: rgb(38,38,38)", AtomicString::ConstructFromLiteral));
#endif
- rootElement->appendChild(body, IGNORE_EXCEPTION);
+ rootElement->appendChild(body.copyRef(), IGNORE_EXCEPTION);
- RefPtr<Element> embedElement = document()->createElement(embedTag, false);
+ Ref<Element> embedElement = document()->createElement(embedTag, false);
- m_embedElement = downcast<HTMLEmbedElement>(embedElement.get());
+ m_embedElement = downcast<HTMLEmbedElement>(embedElement.ptr());
m_embedElement->setAttribute(widthAttr, "100%");
m_embedElement->setAttribute(heightAttr, "100%");
downcast<PluginDocument>(*document()).setPluginElement(m_embedElement);
- body->appendChild(embedElement, IGNORE_EXCEPTION);
+ body->appendChild(WTF::move(embedElement), IGNORE_EXCEPTION);
}
void PluginDocumentParser::appendBytes(DocumentWriter&, const char*, size_t)
ASSERT(element().userAgentShadowRoot());
Document& document = element().document();
- RefPtr<HTMLDivElement> track = HTMLDivElement::create(document);
+ Ref<HTMLDivElement> track = HTMLDivElement::create(document);
track->setPseudo(AtomicString("-webkit-slider-runnable-track", AtomicString::ConstructFromLiteral));
track->appendChild(SliderThumbElement::create(document), IGNORE_EXCEPTION);
- RefPtr<HTMLElement> container = SliderContainerElement::create(document);
- container->appendChild(track.release(), IGNORE_EXCEPTION);
- element().userAgentShadowRoot()->appendChild(container.release(), IGNORE_EXCEPTION);
+ Ref<HTMLElement> container = SliderContainerElement::create(document);
+ container->appendChild(WTF::move(track), IGNORE_EXCEPTION);
+ element().userAgentShadowRoot()->appendChild(WTF::move(container), IGNORE_EXCEPTION);
}
HTMLElement* RangeInputType::sliderTrackElement() const
ASSERT(container);
ASSERT(textWrapper);
- RefPtr<SearchFieldResultsButtonElement> resultsButton = SearchFieldResultsButtonElement::create(element().document());
- m_resultsButton = resultsButton.get();
- updateResultButtonPseudoType(*m_resultsButton, element().maxResults());
- container->insertBefore(m_resultsButton, textWrapper, IGNORE_EXCEPTION);
-
- RefPtr<SearchFieldCancelButtonElement> cancelButton = SearchFieldCancelButtonElement::create(element().document());
- m_cancelButton = cancelButton.get();
- container->insertBefore(m_cancelButton, textWrapper->nextSibling(), IGNORE_EXCEPTION);
+ Ref<SearchFieldResultsButtonElement> resultsButton = SearchFieldResultsButtonElement::create(element().document());
+ m_resultsButton = resultsButton.ptr();
+ updateResultButtonPseudoType(resultsButton.get(), element().maxResults());
+ container->insertBefore(WTF::move(resultsButton), textWrapper, IGNORE_EXCEPTION);
+
+ Ref<SearchFieldCancelButtonElement> cancelButton = SearchFieldCancelButtonElement::create(element().document());
+ m_cancelButton = cancelButton.ptr();
+ container->insertBefore(WTF::move(cancelButton), textWrapper->nextSibling(), IGNORE_EXCEPTION);
}
HTMLElement* SearchInputType::resultsButtonElement() const
m_innerText = TextControlInnerTextElement::create(document);
if (!createsContainer) {
- element().userAgentShadowRoot()->appendChild(m_innerText, IGNORE_EXCEPTION);
+ element().userAgentShadowRoot()->appendChild(*m_innerText, IGNORE_EXCEPTION);
updatePlaceholderText();
return;
}
if (shouldHaveSpinButton) {
m_innerSpinButton = SpinButtonElement::create(document, *this);
- m_container->appendChild(m_innerSpinButton, IGNORE_EXCEPTION);
+ m_container->appendChild(*m_innerSpinButton, IGNORE_EXCEPTION);
}
if (shouldHaveCapsLockIndicator) {
bool shouldDrawCapsLockIndicator = this->shouldDrawCapsLockIndicator();
m_capsLockIndicator->setInlineStyleProperty(CSSPropertyDisplay, shouldDrawCapsLockIndicator ? CSSValueBlock : CSSValueNone, true);
- m_container->appendChild(m_capsLockIndicator, IGNORE_EXCEPTION);
+ m_container->appendChild(*m_capsLockIndicator, IGNORE_EXCEPTION);
}
updateAutoFillButton();
String placeholderText = element().strippedPlaceholder();
if (placeholderText.isEmpty()) {
if (m_placeholder) {
- m_placeholder->parentNode()->removeChild(m_placeholder.get(), ASSERT_NO_EXCEPTION);
+ m_placeholder->parentNode()->removeChild(*m_placeholder, ASSERT_NO_EXCEPTION);
m_placeholder = nullptr;
}
return;
m_placeholder = HTMLDivElement::create(element().document());
m_placeholder->setPseudo(AtomicString("-webkit-input-placeholder", AtomicString::ConstructFromLiteral));
m_placeholder->setInlineStyleProperty(CSSPropertyDisplay, element().isPlaceholderVisible() ? CSSValueBlock : CSSValueNone, true);
- element().userAgentShadowRoot()->insertBefore(m_placeholder, m_container ? m_container.get() : innerTextElement(), ASSERT_NO_EXCEPTION);
+ element().userAgentShadowRoot()->insertBefore(*m_placeholder, m_container ? m_container.get() : innerTextElement(), ASSERT_NO_EXCEPTION);
}
m_placeholder->setInnerText(placeholderText, ASSERT_NO_EXCEPTION);
m_container->setPseudo(AtomicString("-webkit-textfield-decoration-container", AtomicString::ConstructFromLiteral));
m_innerBlock = TextControlInnerElement::create(element().document());
- m_innerBlock->appendChild(m_innerText, IGNORE_EXCEPTION);
- m_container->appendChild(m_innerBlock, IGNORE_EXCEPTION);
+ m_innerBlock->appendChild(*m_innerText, IGNORE_EXCEPTION);
+ m_container->appendChild(*m_innerBlock, IGNORE_EXCEPTION);
- element().userAgentShadowRoot()->appendChild(m_container, IGNORE_EXCEPTION);
+ element().userAgentShadowRoot()->appendChild(*m_container, IGNORE_EXCEPTION);
}
void TextFieldInputType::createAutoFillButton()
m_autoFillButton = AutoFillButtonElement::create(element().document(), *this);
m_autoFillButton->setPseudo(AtomicString("-webkit-auto-fill-button", AtomicString::ConstructFromLiteral));
- m_container->appendChild(m_autoFillButton, IGNORE_EXCEPTION);
+ m_container->appendChild(*m_autoFillButton, IGNORE_EXCEPTION);
}
void TextFieldInputType::updateAutoFillButton()
// Need to force position:absolute because RenderMenuList doesn't assume it
// contains non-absolute or non-fixed renderers as children.
m_bubble->setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
- shadowRoot.appendChild(m_bubble.get(), ASSERT_NO_EXCEPTION);
+ shadowRoot.appendChild(*m_bubble, ASSERT_NO_EXCEPTION);
document.updateLayout();
adjustBubblePosition(m_element->renderer()->absoluteBoundingBoxRect(), m_bubble.get());
- RefPtr<HTMLDivElement> clipper = HTMLDivElement::create(document);
+ Ref<HTMLDivElement> clipper = HTMLDivElement::create(document);
clipper->setPseudo(AtomicString("-webkit-validation-bubble-arrow-clipper", AtomicString::ConstructFromLiteral));
- RefPtr<HTMLDivElement> bubbleArrow = HTMLDivElement::create(document);
+ Ref<HTMLDivElement> bubbleArrow = HTMLDivElement::create(document);
bubbleArrow->setPseudo(AtomicString("-webkit-validation-bubble-arrow", AtomicString::ConstructFromLiteral));
- clipper->appendChild(bubbleArrow.release(), ASSERT_NO_EXCEPTION);
- m_bubble->appendChild(clipper.release(), ASSERT_NO_EXCEPTION);
+ clipper->appendChild(WTF::move(bubbleArrow), ASSERT_NO_EXCEPTION);
+ m_bubble->appendChild(WTF::move(clipper), ASSERT_NO_EXCEPTION);
- RefPtr<HTMLElement> message = HTMLDivElement::create(document);
+ Ref<HTMLElement> message = HTMLDivElement::create(document);
message->setPseudo(AtomicString("-webkit-validation-bubble-message", AtomicString::ConstructFromLiteral));
- RefPtr<HTMLElement> icon = HTMLDivElement::create(document);
+ Ref<HTMLElement> icon = HTMLDivElement::create(document);
icon->setPseudo(AtomicString("-webkit-validation-bubble-icon", AtomicString::ConstructFromLiteral));
- message->appendChild(icon.release(), ASSERT_NO_EXCEPTION);
- RefPtr<HTMLElement> textBlock = HTMLDivElement::create(document);
+ message->appendChild(WTF::move(icon), ASSERT_NO_EXCEPTION);
+ Ref<HTMLElement> textBlock = HTMLDivElement::create(document);
textBlock->setPseudo(AtomicString("-webkit-validation-bubble-text-block", AtomicString::ConstructFromLiteral));
m_messageHeading = HTMLDivElement::create(document);
m_messageHeading->setPseudo(AtomicString("-webkit-validation-bubble-heading", AtomicString::ConstructFromLiteral));
- textBlock->appendChild(m_messageHeading, ASSERT_NO_EXCEPTION);
+ textBlock->appendChild(*m_messageHeading, ASSERT_NO_EXCEPTION);
m_messageBody = HTMLDivElement::create(document);
m_messageBody->setPseudo(AtomicString("-webkit-validation-bubble-body", AtomicString::ConstructFromLiteral));
- textBlock->appendChild(m_messageBody, ASSERT_NO_EXCEPTION);
- message->appendChild(textBlock.release(), ASSERT_NO_EXCEPTION);
- m_bubble->appendChild(message.release(), ASSERT_NO_EXCEPTION);
+ textBlock->appendChild(*m_messageBody, ASSERT_NO_EXCEPTION);
+ message->appendChild(WTF::move(textBlock), ASSERT_NO_EXCEPTION);
+ m_bubble->appendChild(WTF::move(message), ASSERT_NO_EXCEPTION);
setMessageDOMAndStartTimer();
if (m_bubble) {
m_messageHeading = nullptr;
m_messageBody = nullptr;
- m_element->userAgentShadowRoot()->removeChild(m_bubble.get(), ASSERT_NO_EXCEPTION);
+ m_element->userAgentShadowRoot()->removeChild(*m_bubble, ASSERT_NO_EXCEPTION);
m_bubble = nullptr;
}
m_message = String();
CaptionUserPreferences* captionPreferences = document().page()->group().captionPreferences();
Vector<RefPtr<TextTrack>> tracksForMenu = captionPreferences->sortedTrackListForMenu(trackList);
- RefPtr<Element> captionsHeader = document().createElement(h3Tag, ASSERT_NO_EXCEPTION);
+ Ref<Element> captionsHeader = document().createElement(h3Tag, ASSERT_NO_EXCEPTION);
captionsHeader->appendChild(document().createTextNode(textTrackSubtitlesText()));
- appendChild(captionsHeader);
- RefPtr<Element> captionsMenuList = document().createElement(ulTag, ASSERT_NO_EXCEPTION);
+ appendChild(WTF::move(captionsHeader));
+ Ref<Element> captionsMenuList = document().createElement(ulTag, ASSERT_NO_EXCEPTION);
for (unsigned i = 0, length = tracksForMenu.size(); i < length; ++i) {
RefPtr<TextTrack> textTrack = tracksForMenu[i];
- RefPtr<Element> menuItem = document().createElement(liTag, ASSERT_NO_EXCEPTION);
+ Ref<Element> menuItem = document().createElement(liTag, ASSERT_NO_EXCEPTION);
menuItem->appendChild(document().createTextNode(captionPreferences->displayNameForTrack(textTrack.get())));
- captionsMenuList->appendChild(menuItem);
- m_menuItems.append(menuItem);
- m_menuToTrackMap.add(menuItem, textTrack);
+ captionsMenuList->appendChild(menuItem.copyRef());
+ m_menuItems.append(menuItem.ptr());
+ m_menuToTrackMap.add(menuItem.ptr(), textTrack);
}
- appendChild(captionsMenuList);
+ appendChild(WTF::move(captionsMenuList));
#endif
}
// track cue region identifier, run the following substeps:
if (displayBox->hasChildNodes() && !contains(displayBox.get())) {
// Note: the display tree of a cue is removed when the active flag of the cue is unset.
- appendChild(displayBox, ASSERT_NO_EXCEPTION);
+ appendChild(*displayBox, ASSERT_NO_EXCEPTION);
cue->setFontSize(m_fontSize, m_videoDisplaySize.size(), m_fontSizeIsImportant);
}
} else {
// Let region be the WebVTT region whose region identifier
// matches the text track cue region identifier of cue.
- RefPtr<HTMLDivElement> regionNode = region->getDisplayTree();
+ Ref<HTMLDivElement> regionNode = region->getDisplayTree();
// Append the region to the viewport, if it was not already.
- if (!contains(regionNode.get()))
+ if (!contains(regionNode.ptr()))
appendChild(region->getDisplayTree());
region->appendTextTrackCueBox(displayBox);
if (m_textDisplayContainer)
return;
- RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaControlTextTrackContainerElement::create(document());
- m_textDisplayContainer = textDisplayContainer.get();
+ Ref<MediaControlTextTrackContainerElement> textDisplayContainer = MediaControlTextTrackContainerElement::create(document());
+ m_textDisplayContainer = textDisplayContainer.ptr();
if (m_mediaController)
m_textDisplayContainer->setMediaController(m_mediaController);
// Insert it before the first controller element so it always displays behind the controls.
- insertBefore(textDisplayContainer.release(), m_panel, IGNORE_EXCEPTION);
+ insertBefore(WTF::move(textDisplayContainer), m_panel, IGNORE_EXCEPTION);
}
void MediaControls::showTextTrackDisplay()
PassRefPtr<MediaControlsApple> MediaControlsApple::createControls(Document& document)
{
if (!document.page())
- return 0;
+ return nullptr;
RefPtr<MediaControlsApple> controls = adoptRef(new MediaControlsApple(document));
- RefPtr<MediaControlPanelElement> panel = MediaControlPanelElement::create(document);
+ Ref<MediaControlPanelElement> panel = MediaControlPanelElement::create(document);
ExceptionCode ec;
- RefPtr<MediaControlRewindButtonElement> rewindButton = MediaControlRewindButtonElement::create(document);
- controls->m_rewindButton = rewindButton.get();
- panel->appendChild(rewindButton.release(), ec);
+ Ref<MediaControlRewindButtonElement> rewindButton = MediaControlRewindButtonElement::create(document);
+ controls->m_rewindButton = rewindButton.ptr();
+ panel->appendChild(WTF::move(rewindButton), ec);
if (ec)
- return 0;
+ return nullptr;
- RefPtr<MediaControlPlayButtonElement> playButton = MediaControlPlayButtonElement::create(document);
- controls->m_playButton = playButton.get();
- panel->appendChild(playButton.release(), ec);
+ Ref<MediaControlPlayButtonElement> playButton = MediaControlPlayButtonElement::create(document);
+ controls->m_playButton = playButton.ptr();
+ panel->appendChild(WTF::move(playButton), ec);
if (ec)
- return 0;
+ return nullptr;
- RefPtr<MediaControlReturnToRealtimeButtonElement> returnToRealtimeButton = MediaControlReturnToRealtimeButtonElement::create(document);
- controls->m_returnToRealTimeButton = returnToRealtimeButton.get();
- panel->appendChild(returnToRealtimeButton.release(), ec);
+ Ref<MediaControlReturnToRealtimeButtonElement> returnToRealtimeButton = MediaControlReturnToRealtimeButtonElement::create(document);
+ controls->m_returnToRealTimeButton = returnToRealtimeButton.ptr();
+ panel->appendChild(WTF::move(returnToRealtimeButton), ec);
if (ec)
- return 0;
+ return nullptr;
if (document.page()->theme().usesMediaControlStatusDisplay()) {
- RefPtr<MediaControlStatusDisplayElement> statusDisplay = MediaControlStatusDisplayElement::create(document);
- controls->m_statusDisplay = statusDisplay.get();
- panel->appendChild(statusDisplay.release(), ec);
+ Ref<MediaControlStatusDisplayElement> statusDisplay = MediaControlStatusDisplayElement::create(document);
+ controls->m_statusDisplay = statusDisplay.ptr();
+ panel->appendChild(WTF::move(statusDisplay), ec);
if (ec)
- return 0;
+ return nullptr;
}
- RefPtr<MediaControlTimelineContainerElement> timelineContainer = MediaControlTimelineContainerElement::create(document);
+ Ref<MediaControlTimelineContainerElement> timelineContainer = MediaControlTimelineContainerElement::create(document);
- RefPtr<MediaControlCurrentTimeDisplayElement> currentTimeDisplay = MediaControlCurrentTimeDisplayElement::create(document);
- controls->m_currentTimeDisplay = currentTimeDisplay.get();
- timelineContainer->appendChild(currentTimeDisplay.release(), ec);
+ Ref<MediaControlCurrentTimeDisplayElement> currentTimeDisplay = MediaControlCurrentTimeDisplayElement::create(document);
+ controls->m_currentTimeDisplay = currentTimeDisplay.ptr();
+ timelineContainer->appendChild(WTF::move(currentTimeDisplay), ec);
if (ec)
- return 0;
+ return nullptr;
- RefPtr<MediaControlTimelineElement> timeline = MediaControlTimelineElement::create(document, controls.get());
- controls->m_timeline = timeline.get();
- timelineContainer->appendChild(timeline.release(), ec);
+ Ref<MediaControlTimelineElement> timeline = MediaControlTimelineElement::create(document, controls.get());
+ controls->m_timeline = timeline.ptr();
+ timelineContainer->appendChild(WTF::move(timeline), ec);
if (ec)
- return 0;
+ return nullptr;
- RefPtr<MediaControlTimeRemainingDisplayElement> timeRemainingDisplay = MediaControlTimeRemainingDisplayElement::create(document);
- controls->m_timeRemainingDisplay = timeRemainingDisplay.get();
- timelineContainer->appendChild(timeRemainingDisplay.release(), ec);
+ Ref<MediaControlTimeRemainingDisplayElement> timeRemainingDisplay = MediaControlTimeRemainingDisplayElement::create(document);
+ controls->m_timeRemainingDisplay = timeRemainingDisplay.ptr();
+ timelineContainer->appendChild(WTF::move(timeRemainingDisplay), ec);
if (ec)
- return 0;
+ return nullptr;
- controls->m_timelineContainer = timelineContainer.get();
- panel->appendChild(timelineContainer.release(), ec);
+ controls->m_timelineContainer = timelineContainer.ptr();
+ panel->appendChild(WTF::move(timelineContainer), ec);
if (ec)
- return 0;
+ return nullptr;
// FIXME: Only create when needed <http://webkit.org/b/57163>
- RefPtr<MediaControlSeekBackButtonElement> seekBackButton = MediaControlSeekBackButtonElement::create(document);
- controls->m_seekBackButton = seekBackButton.get();
- panel->appendChild(seekBackButton.release(), ec);
+ Ref<MediaControlSeekBackButtonElement> seekBackButton = MediaControlSeekBackButtonElement::create(document);
+ controls->m_seekBackButton = seekBackButton.ptr();
+ panel->appendChild(WTF::move(seekBackButton), ec);
if (ec)
- return 0;
+ return nullptr;
// FIXME: Only create when needed <http://webkit.org/b/57163>
- RefPtr<MediaControlSeekForwardButtonElement> seekForwardButton = MediaControlSeekForwardButtonElement::create(document);
- controls->m_seekForwardButton = seekForwardButton.get();
- panel->appendChild(seekForwardButton.release(), ec);
+ Ref<MediaControlSeekForwardButtonElement> seekForwardButton = MediaControlSeekForwardButtonElement::create(document);
+ controls->m_seekForwardButton = seekForwardButton.ptr();
+ panel->appendChild(WTF::move(seekForwardButton), ec);
if (ec)
- return 0;
+ return nullptr;
if (document.page()->theme().supportsClosedCaptioning()) {
- RefPtr<MediaControlClosedCaptionsContainerElement> closedCaptionsContainer = MediaControlClosedCaptionsContainerElement::create(document);
+ Ref<MediaControlClosedCaptionsContainerElement> closedCaptionsContainer = MediaControlClosedCaptionsContainerElement::create(document);
- RefPtr<MediaControlClosedCaptionsTrackListElement> closedCaptionsTrackList = MediaControlClosedCaptionsTrackListElement::create(document, controls.get());
- controls->m_closedCaptionsTrackList = closedCaptionsTrackList.get();
- closedCaptionsContainer->appendChild(closedCaptionsTrackList.release(), ec);
+ Ref<MediaControlClosedCaptionsTrackListElement> closedCaptionsTrackList = MediaControlClosedCaptionsTrackListElement::create(document, controls.get());
+ controls->m_closedCaptionsTrackList = closedCaptionsTrackList.ptr();
+ closedCaptionsContainer->appendChild(WTF::move(closedCaptionsTrackList), ec);
if (ec)
- return 0;
+ return nullptr;
- RefPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClosedCaptionsButton = MediaControlToggleClosedCaptionsButtonElement::create(document, controls.get());
- controls->m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get();
- panel->appendChild(toggleClosedCaptionsButton.release(), ec);
+ Ref<MediaControlToggleClosedCaptionsButtonElement> toggleClosedCaptionsButton = MediaControlToggleClosedCaptionsButtonElement::create(document, controls.get());
+ controls->m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.ptr();
+ panel->appendChild(WTF::move(toggleClosedCaptionsButton), ec);
if (ec)
- return 0;
+ return nullptr;
- controls->m_closedCaptionsContainer = closedCaptionsContainer.get();
- controls->appendChild(closedCaptionsContainer.release(), ec);
+ controls->m_closedCaptionsContainer = closedCaptionsContainer.ptr();
+ controls->appendChild(WTF::move(closedCaptionsContainer), ec);
if (ec)
- return 0;
+ return nullptr;
}
// FIXME: Only create when needed <http://webkit.org/b/57163>
- RefPtr<MediaControlFullscreenButtonElement> fullScreenButton = MediaControlFullscreenButtonElement::create(document);
- controls->m_fullScreenButton = fullScreenButton.get();
- panel->appendChild(fullScreenButton.release(), ec);
+ Ref<MediaControlFullscreenButtonElement> fullScreenButton = MediaControlFullscreenButtonElement::create(document);
+ controls->m_fullScreenButton = fullScreenButton.ptr();
+ panel->appendChild(WTF::move(fullScreenButton), ec);
// The mute button and the slider element should be in the same div.
- RefPtr<HTMLDivElement> panelVolumeControlContainer = HTMLDivElement::create(document);
+ Ref<HTMLDivElement> panelVolumeControlContainer = HTMLDivElement::create(document);
if (document.page()->theme().usesMediaControlVolumeSlider()) {
- RefPtr<MediaControlVolumeSliderContainerElement> volumeSliderContainer = MediaControlVolumeSliderContainerElement::create(document);
+ Ref<MediaControlVolumeSliderContainerElement> volumeSliderContainer = MediaControlVolumeSliderContainerElement::create(document);
- RefPtr<MediaControlPanelVolumeSliderElement> slider = MediaControlPanelVolumeSliderElement::create(document);
- controls->m_volumeSlider = slider.get();
- volumeSliderContainer->appendChild(slider.release(), ec);
+ Ref<MediaControlPanelVolumeSliderElement> slider = MediaControlPanelVolumeSliderElement::create(document);
+ controls->m_volumeSlider = slider.ptr();
+ volumeSliderContainer->appendChild(WTF::move(slider), ec);
if (ec)
- return 0;
+ return nullptr;
// This is a duplicate mute button, which is visible in some ports at the bottom of the volume bar.
// It's important only when the volume bar is displayed below the controls.
- RefPtr<MediaControlVolumeSliderMuteButtonElement> volumeSliderMuteButton = MediaControlVolumeSliderMuteButtonElement::create(document);
- controls->m_volumeSliderMuteButton = volumeSliderMuteButton.get();
- volumeSliderContainer->appendChild(volumeSliderMuteButton.release(), ec);
+ Ref<MediaControlVolumeSliderMuteButtonElement> volumeSliderMuteButton = MediaControlVolumeSliderMuteButtonElement::create(document);
+ controls->m_volumeSliderMuteButton = volumeSliderMuteButton.ptr();
+ volumeSliderContainer->appendChild(WTF::move(volumeSliderMuteButton), ec);
if (ec)
- return 0;
+ return nullptr;
- controls->m_volumeSliderContainer = volumeSliderContainer.get();
- panelVolumeControlContainer->appendChild(volumeSliderContainer.release(), ec);
+ controls->m_volumeSliderContainer = volumeSliderContainer.ptr();
+ panelVolumeControlContainer->appendChild(WTF::move(volumeSliderContainer), ec);
if (ec)
- return 0;
+ return nullptr;
}
- RefPtr<MediaControlPanelMuteButtonElement> panelMuteButton = MediaControlPanelMuteButtonElement::create(document, controls.get());
- controls->m_panelMuteButton = panelMuteButton.get();
- panelVolumeControlContainer->appendChild(panelMuteButton.release(), ec);
+ Ref<MediaControlPanelMuteButtonElement> panelMuteButton = MediaControlPanelMuteButtonElement::create(document, controls.get());
+ controls->m_panelMuteButton = panelMuteButton.ptr();
+ panelVolumeControlContainer->appendChild(WTF::move(panelMuteButton), ec);
if (ec)
- return 0;
+ return nullptr;
- panel->appendChild(panelVolumeControlContainer, ec);
+ panel->appendChild(WTF::move(panelVolumeControlContainer), ec);
if (ec)
- return 0;
+ return nullptr;
// FIXME: Only create when needed <http://webkit.org/b/57163>
- RefPtr<MediaControlFullscreenVolumeMinButtonElement> fullScreenMinVolumeButton = MediaControlFullscreenVolumeMinButtonElement::create(document);
- controls->m_fullScreenMinVolumeButton = fullScreenMinVolumeButton.get();
- panel->appendChild(fullScreenMinVolumeButton.release(), ec);
+ Ref<MediaControlFullscreenVolumeMinButtonElement> fullScreenMinVolumeButton = MediaControlFullscreenVolumeMinButtonElement::create(document);
+ controls->m_fullScreenMinVolumeButton = fullScreenMinVolumeButton.ptr();
+ panel->appendChild(WTF::move(fullScreenMinVolumeButton), ec);
if (ec)
- return 0;
+ return nullptr;
- RefPtr<MediaControlFullscreenVolumeSliderElement> fullScreenVolumeSlider = MediaControlFullscreenVolumeSliderElement::create(document);
- controls->m_fullScreenVolumeSlider = fullScreenVolumeSlider.get();
- panel->appendChild(fullScreenVolumeSlider.release(), ec);
+ Ref<MediaControlFullscreenVolumeSliderElement> fullScreenVolumeSlider = MediaControlFullscreenVolumeSliderElement::create(document);
+ controls->m_fullScreenVolumeSlider = fullScreenVolumeSlider.ptr();
+ panel->appendChild(WTF::move(fullScreenVolumeSlider), ec);
if (ec)
- return 0;
+ return nullptr;
- RefPtr<MediaControlFullscreenVolumeMaxButtonElement> fullScreenMaxVolumeButton = MediaControlFullscreenVolumeMaxButtonElement::create(document);
- controls->m_fullScreenMaxVolumeButton = fullScreenMaxVolumeButton.get();
- panel->appendChild(fullScreenMaxVolumeButton.release(), ec);
+ Ref<MediaControlFullscreenVolumeMaxButtonElement> fullScreenMaxVolumeButton = MediaControlFullscreenVolumeMaxButtonElement::create(document);
+ controls->m_fullScreenMaxVolumeButton = fullScreenMaxVolumeButton.ptr();
+ panel->appendChild(WTF::move(fullScreenMaxVolumeButton), ec);
if (ec)
- return 0;
+ return nullptr;
- controls->m_panel = panel.get();
- controls->appendChild(panel.release(), ec);
+ controls->m_panel = panel.ptr();
+ controls->appendChild(WTF::move(panel), ec);
if (ec)
- return 0;
+ return nullptr;
return controls.release();
}
}
}
-RefPtr<Element> SliderThumbElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
+Ref<Element> SliderThumbElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
{
return create(targetDocument);
}
SliderThumbElement(Document&);
virtual RenderPtr<RenderElement> createElementRenderer(Ref<RenderStyle>&&, const RenderTreePosition&) override;
- virtual RefPtr<Element> cloneElementWithoutAttributesAndChildren(Document&) override;
+ virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document&) override;
virtual bool isDisabledFormControl() const override;
virtual bool matchesReadWritePseudoClass() const override;
virtual Element* focusDelegate() override;
if (!document.page())
return nullptr;
- RefPtr<ImageControlsRootElementMac> controls = adoptRef(*new ImageControlsRootElementMac(document));
+ Ref<ImageControlsRootElementMac> controls = adoptRef(*new ImageControlsRootElementMac(document));
controls->setAttribute(HTMLNames::classAttr, "x-webkit-image-controls");
- controls->appendChild(ImageControlsButtonElementMac::maybeCreate(document));
+ if (RefPtr<ImageControlsButtonElementMac> button = ImageControlsButtonElementMac::maybeCreate(document))
+ controls->appendChild(button.releaseNonNull());
- return controls.release();
+ return WTF::move(controls);
}
ImageControlsRootElementMac::ImageControlsRootElementMac(Document& document)
clonedNode = downcast<WebVTTElement>(*node).createEquivalentHTMLElement(ownerDocument());
else
clonedNode = node->cloneNode(false);
- parent->appendChild(clonedNode, ASSERT_NO_EXCEPTION);
+ parent->appendChild(*clonedNode, ASSERT_NO_EXCEPTION);
if (is<ContainerNode>(*node))
copyWebVTTNodeToDOMTree(downcast<ContainerNode>(node), downcast<ContainerNode>(clonedNode.get()));
}
RefPtr<DocumentFragment> clonedFragment;
createWebVTTNodeTree();
if (!m_webVTTNodeTree)
- return 0;
+ return nullptr;
clonedFragment = DocumentFragment::create(ownerDocument());
- m_webVTTNodeTree->cloneChildNodes(clonedFragment.get());
+ m_webVTTNodeTree->cloneChildNodes(*clonedFragment);
return clonedFragment.release();
}
return;
markFutureAndPastNodes(referenceTree.get(), startMediaTime(), movieTime);
- m_cueHighlightBox->appendChild(referenceTree);
+ m_cueHighlightBox->appendChild(referenceTree.releaseNonNull());
}
VTTCueBox* VTTCue::getDisplayTree(const IntSize& videoSize, int fontSize)
m_cueHighlightBox->setPseudo(cueShadowPseudoId());
m_cueBackdropBox->setPseudo(cueBackdropShadowPseudoId());
- m_cueBackdropBox->appendChild(m_cueHighlightBox, ASSERT_NO_EXCEPTION);
- displayTree->appendChild(m_cueBackdropBox, ASSERT_NO_EXCEPTION);
+ m_cueBackdropBox->appendChild(*m_cueHighlightBox, ASSERT_NO_EXCEPTION);
+ displayTree->appendChild(*m_cueBackdropBox, ASSERT_NO_EXCEPTION);
// FIXME(BUG 79916): Runs of children of WebVTT Ruby Objects that are not
// WebVTT Ruby Text Objects must be wrapped in anonymous boxes whose
if (m_cueContainer->contains(displayBox.get()))
return;
- m_cueContainer->appendChild(displayBox, ASSERT_NO_EXCEPTION);
+ m_cueContainer->appendChild(*displayBox, ASSERT_NO_EXCEPTION);
displayLastTextTrackCueBox();
}
m_cueContainer->setInlineStyleProperty(CSSPropertyTop, m_currentTop, CSSPrimitiveValue::CSS_PX);
}
-PassRefPtr<HTMLDivElement> VTTRegion::getDisplayTree()
+HTMLDivElement& VTTRegion::getDisplayTree()
{
if (!m_regionDisplayTree) {
m_regionDisplayTree = HTMLDivElement::create(*ownerDocument());
prepareRegionDisplayTree();
}
- return m_regionDisplayTree;
+ return *m_regionDisplayTree;
}
void VTTRegion::prepareRegionDisplayTree()
m_cueContainer->setInlineStyleProperty(CSSPropertyTop, 0.0f, CSSPrimitiveValue::CSS_PX);
m_cueContainer->setPseudo(textTrackCueContainerShadowPseudoId());
- m_regionDisplayTree->appendChild(m_cueContainer);
+ m_regionDisplayTree->appendChild(*m_cueContainer);
// 7.5 Every WebVTT region object is initialised with the following CSS
m_regionDisplayTree->setPseudo(textTrackRegionShadowPseudoId());
bool isScrollingRegion() { return m_scroll; }
- PassRefPtr<HTMLDivElement> getDisplayTree();
+ HTMLDivElement& getDisplayTree();
void appendTextTrackCueBox(PassRefPtr<VTTCueBox>);
void displayLastTextTrackCueBox();
return adoptRef(*new WebVTTElement(nodeType, document));
}
-RefPtr<Element> WebVTTElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
+Ref<Element> WebVTTElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
{
- RefPtr<WebVTTElement> clone = create(static_cast<WebVTTNodeType>(m_webVTTNodeType), targetDocument);
+ Ref<WebVTTElement> clone = create(static_cast<WebVTTNodeType>(m_webVTTNodeType), targetDocument);
clone->setLanguage(m_language);
- return clone;
+ return WTF::move(clone);
}
PassRefPtr<HTMLElement> WebVTTElement::createEquivalentHTMLElement(Document& document)
static Ref<WebVTTElement> create(const WebVTTNodeType, Document&);
PassRefPtr<HTMLElement> createEquivalentHTMLElement(Document&);
- virtual RefPtr<Element> cloneElementWithoutAttributesAndChildren(Document&) override;
+ virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document&) override;
void setWebVTTNodeType(WebVTTNodeType type) { m_webVTTNodeType = static_cast<unsigned>(type); }
WebVTTNodeType webVTTNodeType() const { return static_cast<WebVTTNodeType>(m_webVTTNodeType); }
// Set this flag, so when we create it, we put it into the via inspector map.
m_creatingViaInspectorStyleSheet = true;
InlineStyleOverrideScope overrideScope(document);
- targetNode->appendChild(styleElement, ec);
+ targetNode->appendChild(styleElement.releaseNonNull(), ec);
m_creatingViaInspectorStyleSheet = false;
if (ec)
return nullptr;
String title;
String url = dragData.asURL(DragData::DoNotConvertFilenames, &title);
if (!url.isEmpty()) {
- RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(document);
+ Ref<HTMLAnchorElement> anchor = HTMLAnchorElement::create(document);
anchor->setHref(url);
if (title.isEmpty()) {
// Try the plain text first because the url might be normalized or escaped.
if (title.isEmpty())
title = url;
}
- RefPtr<Node> anchorText = document.createTextNode(title);
- anchor->appendChild(anchorText, IGNORE_EXCEPTION);
- RefPtr<DocumentFragment> fragment = document.createDocumentFragment();
- fragment->appendChild(anchor, IGNORE_EXCEPTION);
- return fragment.get();
+ anchor->appendChild(document.createTextNode(title), IGNORE_EXCEPTION);
+ Ref<DocumentFragment> fragment = document.createDocumentFragment();
+ fragment->appendChild(WTF::move(anchor), IGNORE_EXCEPTION);
+ return fragment.ptr();
}
}
}
if (allowPlainText && dragData.containsPlainText()) {
chosePlainText = true;
- return createFragmentFromText(context, dragData.asPlainText()).get();
+ return createFragmentFromText(context, dragData.asPlainText()).ptr();
}
- return 0;
+ return nullptr;
}
bool DragController::dragIsMove(FrameSelection& selection, DragData& dragData)
if (!style.isEmpty())
body->setAttribute(HTMLNames::styleAttr, style);
- rootElement->appendChild(body, ec);
- document->appendChild(rootElement, ec);
+ rootElement->appendChild(body.releaseNonNull(), ec);
+ document->appendChild(rootElement.releaseNonNull(), ec);
}
const ViewportArguments& Frame::viewportArguments() const
return hasAttribute(XLinkNames::hrefAttr);
}
-RefPtr<Element> SVGScriptElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
+Ref<Element> SVGScriptElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
{
- return adoptRef(new SVGScriptElement(tagQName(), targetDocument, false, alreadyStarted()));
+ return adoptRef(*new SVGScriptElement(tagQName(), targetDocument, false, alreadyStarted()));
}
#ifndef NDEBUG
virtual void dispatchLoadEvent() override { SVGExternalResourcesRequired::dispatchLoadEvent(this); }
- virtual RefPtr<Element> cloneElementWithoutAttributesAndChildren(Document&) override;
+ virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document&) override;
virtual bool rendererIsNeeded(const RenderStyle&) override { return false; }
// SVGExternalResourcesRequired
for (auto* element : disallowedElements) {
for (auto& descendant : descendantsOfType<SVGElement>(*element))
descendant.setCorrespondingElement(nullptr);
- element->parentNode()->removeChild(element);
+ element->parentNode()->removeChild(*element);
}
}
void SVGUseElement::cloneTarget(ContainerNode& container, SVGElement& target) const
{
- Ref<SVGElement> targetClone = static_pointer_cast<SVGElement>(target.cloneElementWithChildren(document())).releaseNonNull();
+ Ref<SVGElement> targetClone = static_cast<SVGElement&>(target.cloneElementWithChildren(document()).get());
associateClonesWithOriginals(targetClone.get(), target);
removeDisallowedElementsFromSubtree(targetClone.get());
transferSizeAttributesToTargetClone(targetClone.get());
ASSERT(!replacementClone.parentNode());
replacementClone.cloneDataFromElement(originalClone);
- originalClone.cloneChildNodes(&replacementClone);
+ originalClone.cloneChildNodes(replacementClone);
associateReplacementClonesWithOriginals(replacementClone, originalClone);
removeDisallowedElementsFromSubtree(replacementClone);
}
if (target)
originalClone.cloneTarget(replacementClone.get(), *target);
- originalClone.parentNode()->replaceChild(replacementClone.ptr(), &originalClone);
+ originalClone.parentNode()->replaceChild(replacementClone.copyRef(), originalClone);
// Resume iterating, starting just inside the replacement clone.
it = descendants.from(replacementClone.get());
auto replacementClone = SVGSVGElement::create(document());
cloneDataAndChildren(replacementClone.get(), originalClone);
- originalClone.parentNode()->replaceChild(replacementClone.ptr(), &originalClone);
+ originalClone.parentNode()->replaceChild(replacementClone.copyRef(), originalClone);
// Resume iterating, starting just inside the replacement clone.
it = descendants.from(replacementClone.get());
m_document.frame()->script().evaluate(ScriptSourceCode(AtomicString("prepareWebKitXMLViewer('This XML file does not appear to have any style information associated with it. The document tree is shown below.');")));
String cssString = StringImpl::createWithoutCopying(XMLViewer_css, sizeof(XMLViewer_css));
- RefPtr<Text> text = m_document.createTextNode(cssString);
- m_document.getElementById(String(ASCIILiteral("xml-viewer-style")))->appendChild(text, IGNORE_EXCEPTION);
+ Ref<Text> text = m_document.createTextNode(cssString);
+ m_document.getElementById(String(ASCIILiteral("xml-viewer-style")))->appendChild(WTF::move(text), IGNORE_EXCEPTION);
m_document.styleResolverChanged(RecalcStyleImmediately);
}
+2015-09-10 Chris Dumez <cdumez@apple.com>
+
+ Node.appendChild(null) / replaceChild(null, null) / removeChild(null) / insertBefore(null, ref) should throw a TypeError
+ https://bugs.webkit.org/show_bug.cgi?id=148971
+ <rdar://problem/22560883>
+ <rdar://problem/22559225>
+
+ Reviewed by Ryosuke Niwa.
+
+ ContainerNode::appendChild() now takes a Ref<Node>&& parameter so we
+ need to update the call site.
+
+ * WebView/WebFrame.mm:
+ (-[WebFrame _documentFragmentWithNodesAsParagraphs:]):
+
2015-09-07 Andy Estes <aestes@apple.com>
[Mac] DebugRelease builds should link against libWebKitSystemInterfaceElCapitan.a on 10.11
RefPtr<DocumentFragment> fragment = document->createDocumentFragment();
for (auto* node : nodesVector) {
- RefPtr<Element> element = createDefaultParagraphElement(*document);
- element->appendChild(node);
- fragment->appendChild(element.release());
+ Ref<Element> element = createDefaultParagraphElement(*document);
+ element->appendChild(*node);
+ fragment->appendChild(WTF::move(element));
}
return kit(fragment.release().get());
{
RefPtr<Range> range = _private->coreFrame->selection().toNormalizedRange();
- DOMDocumentFragment* fragment = range ? kit(createFragmentFromText(*range, text).get()) : nil;
+ DOMDocumentFragment* fragment = range ? kit(createFragmentFromText(*range, text).ptr()) : nil;
[self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:matchStyle];
}
{
RefPtr<Range> range = _private->coreFrame->selection().toNormalizedRange();
- DOMDocumentFragment* fragment = range ? kit(createFragmentFromText(*range, text).get()) : nil;
+ DOMDocumentFragment* fragment = range ? kit(createFragmentFromText(*range, text).ptr()) : nil;
[self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:YES];
}
#if PLATFORM(IOS)
- (DOMDocumentFragment *)_documentFragmentForText:(NSString *)text
{
- return kit(createFragmentFromText(*_private->coreFrame->selection().toNormalizedRange().get(), text).get());
+ return kit(createFragmentFromText(*_private->coreFrame->selection().toNormalizedRange().get(), text).ptr());
}
- (DOMDocumentFragment *)_documentFragmentForWebArchive:(WebArchive *)webArchive
if (pboardType == NSStringPboardType) {
if (!context)
return nil;
- return kit(createFragmentFromText(*core(context), [[pasteboard stringForType:NSStringPboardType] precomposedStringWithCanonicalMapping]).get());
+ return kit(createFragmentFromText(*core(context), [[pasteboard stringForType:NSStringPboardType] precomposedStringWithCanonicalMapping]).ptr());
}
return nil;
}
+2015-09-10 Chris Dumez <cdumez@apple.com>
+
+ Node.appendChild(null) / replaceChild(null, null) / removeChild(null) / insertBefore(null, ref) should throw a TypeError
+ https://bugs.webkit.org/show_bug.cgi?id=148971
+ <rdar://problem/22560883>
+ <rdar://problem/22559225>
+
+ Reviewed by Ryosuke Niwa.
+
+ ContainerNode::appendChild() now takes a Ref<Node>&& parameter so we
+ need to update the call sites.
+
+ * WebProcess/Plugins/PDF/PDFPlugin.mm:
+ (WebKit::PDFPlugin::PDFPlugin):
+ * WebProcess/Plugins/PDF/PDFPluginAnnotation.mm:
+ (WebKit::PDFPluginAnnotation::attach):
+ (WebKit::PDFPluginAnnotation::~PDFPluginAnnotation):
+ * WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm:
+ (WebKit::PDFPluginChoiceAnnotation::createAnnotationElement):
+
2015-09-10 Joseph Pecoraro <pecoraro@apple.com>
Web Inspector: Make WebInspectorProxy inspectorURL path methods static
m_annotationContainer = document->createElement(divTag, false);
m_annotationContainer->setAttribute(idAttr, "annotationContainer");
- RefPtr<Element> m_annotationStyle = document->createElement(styleTag, false);
- m_annotationStyle->setTextContent(annotationStyle, ASSERT_NO_EXCEPTION);
+ Ref<Element> annotationStyleElement = document->createElement(styleTag, false);
+ annotationStyleElement->setTextContent(annotationStyle, ASSERT_NO_EXCEPTION);
- m_annotationContainer->appendChild(m_annotationStyle.get());
- document->bodyOrFrameset()->appendChild(m_annotationContainer.get());
+ m_annotationContainer->appendChild(WTF::move(annotationStyleElement));
+ document->bodyOrFrameset()->appendChild(*m_annotationContainer);
}
m_accessibilityObject = adoptNS([[WKPDFPluginAccessibilityObject alloc] initWithPDFPlugin:this]);
updateGeometry();
- m_parent->appendChild(m_element);
+ m_parent->appendChild(*m_element);
// FIXME: The text cursor doesn't blink after this. Why?
m_element->focus();
m_eventListener->setAnnotation(0);
- m_parent->removeChild(element());
+ m_parent->removeChild(*element());
}
void PDFPluginAnnotation::updateGeometry()
NSString *selectedChoice = choiceAnnotation.stringValue;
for (NSString *choice in choices) {
- RefPtr<Element> choiceOption = document.createElement(optionTag, false);
+ Ref<Element> choiceOption = document.createElement(optionTag, false);
choiceOption->setAttribute(valueAttr, choice);
choiceOption->setTextContent(choice, ASSERT_NO_EXCEPTION);
if (choice == selectedChoice)
choiceOption->setAttribute(selectedAttr, "selected");
- styledElement->appendChild(choiceOption);
+ styledElement->appendChild(WTF::move(choiceOption));
}
return element;