Replace createTextNode with new Text().

Sky doesn't have this method (per spec).

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/879733002
This commit is contained in:
Elliott Sprehn 2015-01-26 15:12:19 -08:00
parent ff2cde060f
commit 765ef4ec8e
15 changed files with 17 additions and 24 deletions

View File

@ -44,7 +44,7 @@ function createElement(tagName) {
function createText(text) {
texts++;
return document.createTextNode(text);
return new Text(text);
}
function createElements(root, depth) {

View File

@ -15,9 +15,9 @@ var content = document.getElementById('content');
var out = [];
for (var i = 0; i < 1000; i++) {
var div = document.createElement('div');
div.appendChild(document.createElement('span')).appendChild(document.createTextNode('foo'));
div.appendChild(document.createTextNode(' '));
div.appendChild(document.createElement('span')).appendChild(document.createTextNode('bar'));
div.appendChild(document.createElement('span')).appendChild(new Text('foo'));
div.appendChild(new Text(' '));
div.appendChild(document.createElement('span')).appendChild(new Text('bar'));
content.appendChild(div);
}

View File

@ -517,11 +517,6 @@ PassRefPtr<DocumentFragment> Document::createDocumentFragment()
return DocumentFragment::create(*this);
}
PassRefPtr<Text> Document::createTextNode(const String& data)
{
return Text::create(*this, data);
}
PassRefPtr<Text> Document::createEditingTextNode(const String& text)
{
return Text::createEditingText(*this, text);
@ -545,7 +540,7 @@ PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionSt
{
switch (importedNode->nodeType()) {
case TEXT_NODE:
return createTextNode(toText(importedNode)->data());
return Text::create(*this, toText(importedNode)->data());
case ELEMENT_NODE: {
Element* oldElement = toElement(importedNode);
RefPtr<Element> newElement = createElement(oldElement->tagQName(), false);

View File

@ -174,7 +174,6 @@ public:
PassRefPtr<Element> createElement(const AtomicString& name, ExceptionState&);
PassRefPtr<DocumentFragment> createDocumentFragment();
PassRefPtr<Text> createTextNode(const String& data);
PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionState&);
PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser);

View File

@ -30,7 +30,6 @@ typedef (CanvasRenderingContext2D or WebGLRenderingContext) RenderingContext;
[CustomElementCallbacks, PerWorldBindings, RaisesException] Element createElement(DOMString tagName);
DocumentFragment createDocumentFragment();
Text createTextNode(DOMString data);
[CustomElementCallbacks, RaisesException, TypeChecking=Interface] Node importNode(Node node, optional boolean deep = false);

View File

@ -919,7 +919,7 @@ void Node::setTextContent(const String& text)
// Note: This API will not insert empty text nodes:
// http://dom.spec.whatwg.org/#dom-node-textcontent
if (!text.isEmpty())
container->appendChild(document().createTextNode(text), ASSERT_NO_EXCEPTION);
container->appendChild(Text::create(document(), text), ASSERT_NO_EXCEPTION);
return;
}
case DOCUMENT_NODE:

View File

@ -70,7 +70,7 @@ void InsertLineBreakCommand::doApply()
pos = positionOutsideTabSpan(pos);
RefPtr<Node> nodeToInsert = nullptr;
nodeToInsert = document().createTextNode("\n");
nodeToInsert = Text::create(document(), "\n");
// FIXME: Need to merge text nodes when inserting just after or before text.
@ -111,7 +111,7 @@ void InsertLineBreakCommand::doApply()
if (textNode->inDocument())
insertTextIntoNode(textNode, 0, nonBreakingSpaceString());
else {
RefPtr<Text> nbspNode = document().createTextNode(nonBreakingSpaceString());
RefPtr<Text> nbspNode = Text::create(document(), nonBreakingSpaceString());
insertNodeAt(nbspNode.get(), positionBeforeTextNode);
endingPosition = firstPositionInNode(nbspNode.get());
}

View File

@ -86,7 +86,7 @@ void HTMLTitleElement::setText(const String &value)
m_ignoreTitleUpdatesWhenChildrenChange = false;
if (!value.isEmpty())
appendChild(document().createTextNode(value.impl()), IGNORE_EXCEPTION);
appendChild(Text::create(document(), value.impl()), IGNORE_EXCEPTION);
}
}

View File

@ -9,9 +9,9 @@ describe("height of an editable block", function() {
var elem = document.getElementById("test");
var originalHeight = elem.offsetHeight;
var d = elem.appendChild(document.createElement('div'));
d.appendChild(document.createTextNode('aaa'));
d.appendChild(new Text('aaa'));
d = elem.appendChild(document.createElement('div'));
d.appendChild(document.createTextNode('bbb'));
d.appendChild(new Text('bbb'));
var newHeight = elem.offsetHeight;
while (elem.firstChild) {

View File

@ -28,7 +28,7 @@ describe('MutationObserver', function() {
observers[6].observe(div, {characterData: true, subtree: true});
observers[8].observe(div, {attributes: true});
div.setAttribute('foo', 'bar');
div.appendChild(document.createTextNode('hello'));
div.appendChild(new Text('hello'));
div.firstChild.textContent = 'goodbye';
setTimeout(function() {
assert.deepEqual(order, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);

View File

@ -9,7 +9,7 @@ function mutationCallback(mutations, observer) {
var mutationObserver = new MutationObserver(mutationCallback);
var body = document.getElementById("body");
mutationObserver.observe(body, {childList: true});
body.appendChild(document.createTextNode("PASS. We didn't crash"));
body.appendChild(new Text("PASS. We didn't crash"));
</script>
</body>
</html>

View File

@ -7,7 +7,7 @@ describe('Non-relevant properties on mutation records should be null, except for
var observer = new MutationObserver(function() {});
it('on characterData records', function() {
var text = document.createTextNode('something');
var text = new Text('something');
observer.observe(text, {characterData: true});
text.data = 'something else';
var record = observer.takeRecords()[0];

View File

@ -41,7 +41,7 @@ describe('MutationObserver on character data', function() {
// ...observer.disconnect() should prevent further delivery of mutations.
assert.equal(mutations, null);
charDataNode = document.createTextNode('');
charDataNode = new Text('');
observer.observe(charDataNode, { characterData: true });
charDataNode.textContent = 'foo';
charDataNode.textContent = 'bar';

View File

@ -5,7 +5,7 @@
describe('Test MutationObserver.observe', function() {
it('should respect character data options', function() {
var observer = new MutationObserver(function() {});
var text = document.createTextNode('0');
var text = new Text('0');
observer.observe(text, {characterDataOldValue: true});
text.data = '1';

View File

@ -7,7 +7,7 @@ describe('MutationObservers', function() {
it('should handle shadow dom', function() {
function mutate(element) {
element.setAttribute('data-foo', 'bar');
element.insertBefore(document.createTextNode('hello'), element.firstChild);
element.insertBefore(new Text('hello'), element.firstChild);
element.firstChild.textContent = 'goodbye';
element.removeChild(element.firstChild);
}