Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: third_party/WebKit/Source/core/dom/Node.cpp

Issue 2305903003: DOM append(), prepend(), after(), before(), and replaceWith() should throw an exception if a Docume… (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/dom/ParentNode/prepend.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 return nullptr; 459 return nullptr;
460 } 460 }
461 461
462 static Node* nodeOrStringToNode(const NodeOrString& nodeOrString, Document& docu ment) 462 static Node* nodeOrStringToNode(const NodeOrString& nodeOrString, Document& docu ment)
463 { 463 {
464 if (nodeOrString.isNode()) 464 if (nodeOrString.isNode())
465 return nodeOrString.getAsNode(); 465 return nodeOrString.getAsNode();
466 return Text::create(document, nodeOrString.getAsString()); 466 return Text::create(document, nodeOrString.getAsString());
467 } 467 }
468 468
469 static Node* convertNodesIntoNode(const HeapVector<NodeOrString>& nodes, Documen t& document) 469 // Returns nullptr if an exception was thrown.
470 static Node* convertNodesIntoNode(const HeapVector<NodeOrString>& nodes, Documen t& document, ExceptionState& exceptionState)
470 { 471 {
471 if (nodes.size() == 1) 472 if (nodes.size() == 1)
472 return nodeOrStringToNode(nodes[0], document); 473 return nodeOrStringToNode(nodes[0], document);
473 474
474 Node* fragment = DocumentFragment::create(document); 475 Node* fragment = DocumentFragment::create(document);
475 for (const NodeOrString& nodeOrString : nodes) 476 for (const NodeOrString& nodeOrString : nodes) {
476 fragment->appendChild(nodeOrStringToNode(nodeOrString, document), ASSERT _NO_EXCEPTION); 477 fragment->appendChild(nodeOrStringToNode(nodeOrString, document), except ionState);
478 if (exceptionState.hadException())
479 return nullptr;
480 }
477 return fragment; 481 return fragment;
478 } 482 }
479 483
480 void Node::prepend(const HeapVector<NodeOrString>& nodes, ExceptionState& except ionState) 484 void Node::prepend(const HeapVector<NodeOrString>& nodes, ExceptionState& except ionState)
481 { 485 {
482 Node* node = convertNodesIntoNode(nodes, document()); 486 if (Node* node = convertNodesIntoNode(nodes, document(), exceptionState))
483 insertBefore(node, firstChild(), exceptionState); 487 insertBefore(node, firstChild(), exceptionState);
484 } 488 }
485 489
486 void Node::append(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti onState) 490 void Node::append(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti onState)
487 { 491 {
488 Node* node = convertNodesIntoNode(nodes, document()); 492 if (Node* node = convertNodesIntoNode(nodes, document(), exceptionState))
489 appendChild(node, exceptionState); 493 appendChild(node, exceptionState);
490 } 494 }
491 495
492 void Node::before(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti onState) 496 void Node::before(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti onState)
493 { 497 {
494 Node* parent = parentNode(); 498 Node* parent = parentNode();
495 if (!parent) 499 if (!parent)
496 return; 500 return;
497 Node* viablePreviousSibling = findViablePreviousSibling(*this, nodes); 501 Node* viablePreviousSibling = findViablePreviousSibling(*this, nodes);
498 Node* node = convertNodesIntoNode(nodes, document()); 502 if (Node* node = convertNodesIntoNode(nodes, document(), exceptionState))
499 parent->insertBefore(node, viablePreviousSibling ? viablePreviousSibling->ne xtSibling() : parent->firstChild(), exceptionState); 503 parent->insertBefore(node, viablePreviousSibling ? viablePreviousSibling ->nextSibling() : parent->firstChild(), exceptionState);
500 } 504 }
501 505
502 void Node::after(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptio nState) 506 void Node::after(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptio nState)
503 { 507 {
504 Node* parent = parentNode(); 508 Node* parent = parentNode();
505 if (!parent) 509 if (!parent)
506 return; 510 return;
507 Node* viableNextSibling = findViableNextSibling(*this, nodes); 511 Node* viableNextSibling = findViableNextSibling(*this, nodes);
508 Node* node = convertNodesIntoNode(nodes, document()); 512 if (Node* node = convertNodesIntoNode(nodes, document(), exceptionState))
509 parent->insertBefore(node, viableNextSibling, exceptionState); 513 parent->insertBefore(node, viableNextSibling, exceptionState);
510 } 514 }
511 515
512 void Node::replaceWith(const HeapVector<NodeOrString>& nodes, ExceptionState& ex ceptionState) 516 void Node::replaceWith(const HeapVector<NodeOrString>& nodes, ExceptionState& ex ceptionState)
513 { 517 {
514 Node* parent = parentNode(); 518 Node* parent = parentNode();
515 if (!parent) 519 if (!parent)
516 return; 520 return;
517 Node* viableNextSibling = findViableNextSibling(*this, nodes); 521 Node* viableNextSibling = findViableNextSibling(*this, nodes);
518 Node* node = convertNodesIntoNode(nodes, document()); 522 Node* node = convertNodesIntoNode(nodes, document(), exceptionState);
523 if (exceptionState.hadException())
524 return;
519 if (parent == parentNode()) 525 if (parent == parentNode())
520 parent->replaceChild(node, this, exceptionState); 526 parent->replaceChild(node, this, exceptionState);
521 else 527 else
522 parent->insertBefore(node, viableNextSibling, exceptionState); 528 parent->insertBefore(node, viableNextSibling, exceptionState);
523 } 529 }
524 530
525 void Node::remove(ExceptionState& exceptionState) 531 void Node::remove(ExceptionState& exceptionState)
526 { 532 {
527 if (ContainerNode* parent = parentNode()) 533 if (ContainerNode* parent = parentNode())
528 parent->removeChild(this, exceptionState); 534 parent->removeChild(this, exceptionState);
(...skipping 1876 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 if (node) { 2411 if (node) {
2406 std::stringstream stream; 2412 std::stringstream stream;
2407 node->printNodePathTo(stream); 2413 node->printNodePathTo(stream);
2408 LOG(INFO) << stream.str(); 2414 LOG(INFO) << stream.str();
2409 } else { 2415 } else {
2410 LOG(INFO) << "Cannot showNodePath for <null>"; 2416 LOG(INFO) << "Cannot showNodePath for <null>";
2411 } 2417 }
2412 } 2418 }
2413 2419
2414 #endif 2420 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/dom/ParentNode/prepend.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698