Merge from Chromium at DEPS revision r215849

This commit was generated by merge_to_master.py.

Change-Id: I9e6d77256a64b87c056aa64e44c8f8cdc852f5d2
diff --git a/Source/core/dom/Attr.cpp b/Source/core/dom/Attr.cpp
index 70afc51..510a383 100644
--- a/Source/core/dom/Attr.cpp
+++ b/Source/core/dom/Attr.cpp
@@ -24,6 +24,8 @@
 #include "core/dom/Attr.h"
 
 #include "XMLNSNames.h"
+#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "core/dom/Element.h"
 #include "core/dom/ExceptionCode.h"
 #include "core/dom/ScopedEventQueue.h"
@@ -89,16 +91,16 @@
     }
 }
 
-void Attr::setPrefix(const AtomicString& prefix, ExceptionCode& ec)
+void Attr::setPrefix(const AtomicString& prefix, ExceptionState& es)
 {
-    ec = 0;
-    checkSetPrefix(prefix, ec);
-    if (ec)
+    es.clearException();
+    checkSetPrefix(prefix, es);
+    if (es.hadException())
         return;
 
     if ((prefix == xmlnsAtom && namespaceURI() != XMLNSNames::xmlnsNamespaceURI)
         || static_cast<Attr*>(this)->qualifiedName() == xmlnsAtom) {
-        ec = NamespaceError;
+        es.throwDOMException(NamespaceError);
         return;
     }
 
@@ -124,7 +126,7 @@
     invalidateNodeListCachesInAncestors(&m_name, m_element);
 }
 
-void Attr::setValue(const AtomicString& value, ExceptionCode&)
+void Attr::setValue(const AtomicString& value, ExceptionState&)
 {
     if (m_element)
         m_element->willModifyAttribute(qualifiedName(), this->value(), value);
@@ -137,7 +139,7 @@
 
 void Attr::setNodeValue(const String& v)
 {
-    setValue(v, IGNORE_EXCEPTION);
+    setValue(v, IGNORE_EXCEPTION_STATE);
 }
 
 PassRefPtr<Node> Attr::cloneNode(bool /*deep*/)
diff --git a/Source/core/dom/Attr.h b/Source/core/dom/Attr.h
index 82a7e13..3673be2 100644
--- a/Source/core/dom/Attr.h
+++ b/Source/core/dom/Attr.h
@@ -31,6 +31,7 @@
 namespace WebCore {
 
 class CSSStyleDeclaration;
+class ExceptionState;
 class MutableStylePropertySet;
 
 // Attr can have Text children
@@ -50,7 +51,7 @@
     Element* ownerElement() const { return m_element; }
 
     const AtomicString& value() const;
-    void setValue(const AtomicString&, ExceptionCode&);
+    void setValue(const AtomicString&, ExceptionState&);
     void setValue(const AtomicString&);
 
     const QualifiedName& qualifiedName() const { return m_name; }
@@ -75,7 +76,7 @@
     virtual const AtomicString& namespaceURI() const OVERRIDE { return m_name.namespaceURI(); }
     virtual const AtomicString& prefix() const OVERRIDE { return m_name.prefix(); }
 
-    virtual void setPrefix(const AtomicString&, ExceptionCode&);
+    virtual void setPrefix(const AtomicString&, ExceptionState&);
 
     virtual String nodeValue() const OVERRIDE { return value(); }
     virtual void setNodeValue(const String&);
diff --git a/Source/core/dom/CharacterData.cpp b/Source/core/dom/CharacterData.cpp
index eb8a383..cc386f5 100644
--- a/Source/core/dom/CharacterData.cpp
+++ b/Source/core/dom/CharacterData.cpp
@@ -22,6 +22,7 @@
 #include "config.h"
 #include "core/dom/CharacterData.h"
 
+#include "bindings/v8/ExceptionState.h"
 #include "core/dom/Document.h"
 #include "core/dom/EventNames.h"
 #include "core/dom/ExceptionCode.h"
@@ -56,10 +57,10 @@
     document()->textRemoved(this, 0, oldLength);
 }
 
-String CharacterData::substringData(unsigned offset, unsigned count, ExceptionCode& ec)
+String CharacterData::substringData(unsigned offset, unsigned count, ExceptionState& es)
 {
     if (offset > length()) {
-        ec = IndexSizeError;
+        es.throwDOMException(IndexSizeError);
         return String();
     }
 
@@ -116,10 +117,10 @@
     // FIXME: Should we call textInserted here?
 }
 
-void CharacterData::insertData(unsigned offset, const String& data, ExceptionCode& ec)
+void CharacterData::insertData(unsigned offset, const String& data, ExceptionState& es)
 {
     if (offset > length()) {
-        ec = IndexSizeError;
+        es.throwDOMException(IndexSizeError);
         return;
     }
 
@@ -131,10 +132,10 @@
     document()->textInserted(this, offset, data.length());
 }
 
-void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionCode& ec)
+void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionState& es)
 {
     if (offset > length()) {
-        ec = IndexSizeError;
+        es.throwDOMException(IndexSizeError);
         return;
     }
 
@@ -152,10 +153,10 @@
     document()->textRemoved(this, offset, realCount);
 }
 
-void CharacterData::replaceData(unsigned offset, unsigned count, const String& data, ExceptionCode& ec)
+void CharacterData::replaceData(unsigned offset, unsigned count, const String& data, ExceptionState& es)
 {
     if (offset > length()) {
-        ec = IndexSizeError;
+        es.throwDOMException(IndexSizeError);
         return;
     }
 
diff --git a/Source/core/dom/CharacterData.h b/Source/core/dom/CharacterData.h
index 6dc7e68..8077364 100644
--- a/Source/core/dom/CharacterData.h
+++ b/Source/core/dom/CharacterData.h
@@ -28,17 +28,19 @@
 
 namespace WebCore {
 
+class ExceptionState;
+
 class CharacterData : public Node {
 public:
     void atomize();
     String data() const { return m_data; }
     void setData(const String&);
     unsigned length() const { return m_data.length(); }
-    String substringData(unsigned offset, unsigned count, ExceptionCode&);
+    String substringData(unsigned offset, unsigned count, ExceptionState&);
     void appendData(const String&);
-    void insertData(unsigned offset, const String&, ExceptionCode&);
-    void deleteData(unsigned offset, unsigned count, ExceptionCode&);
-    void replaceData(unsigned offset, unsigned count, const String&, ExceptionCode&);
+    void insertData(unsigned offset, const String&, ExceptionState&);
+    void deleteData(unsigned offset, unsigned count, ExceptionState&);
+    void replaceData(unsigned offset, unsigned count, const String&, ExceptionState&);
 
     bool containsOnlyWhitespace() const;
 
diff --git a/Source/core/dom/CharacterData.idl b/Source/core/dom/CharacterData.idl
index 0999ab7..10972ba 100644
--- a/Source/core/dom/CharacterData.idl
+++ b/Source/core/dom/CharacterData.idl
@@ -23,7 +23,7 @@
 
     readonly attribute unsigned long length;
 
-    [TreatReturnedNullStringAs=Null, RaisesException] DOMString substringData([Default=Undefined] optional unsigned long offset, [IsIndex,Default=Undefined] optional unsigned long length);
+    [TreatReturnedNullStringAs=Null, RaisesException] DOMString substringData(unsigned long offset, unsigned long length);
 
     void appendData(DOMString data);
     [RaisesException] void insertData(unsigned long offset, DOMString data);
diff --git a/Source/core/dom/ContainerNode.cpp b/Source/core/dom/ContainerNode.cpp
index e8aceb8..3924585 100644
--- a/Source/core/dom/ContainerNode.cpp
+++ b/Source/core/dom/ContainerNode.cpp
@@ -23,6 +23,8 @@
 #include "config.h"
 #include "core/dom/ContainerNode.h"
 
+#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "core/dom/ChildListMutationScope.h"
 #include "core/dom/ContainerNodeAlgorithms.h"
 #include "core/dom/EventNames.h"
@@ -60,12 +62,12 @@
 unsigned NoEventDispatchAssertion::s_count = 0;
 #endif
 
-static void collectChildrenAndRemoveFromOldParent(Node* node, NodeVector& nodes, ExceptionCode& ec)
+static void collectChildrenAndRemoveFromOldParent(Node* node, NodeVector& nodes, ExceptionState& es)
 {
     if (node->nodeType() != Node::DOCUMENT_FRAGMENT_NODE) {
         nodes.append(node);
         if (ContainerNode* oldParent = node->parentNode())
-            oldParent->removeChild(node, ec);
+            oldParent->removeChild(node, es);
         return;
     }
     getChildNodes(node, nodes);
@@ -102,7 +104,7 @@
         if (children[i]->attached())
             children[i]->detach();
         // FIXME: We need a no mutation event version of adoptNode.
-        RefPtr<Node> child = document()->adoptNode(children[i].release(), ASSERT_NO_EXCEPTION);
+        RefPtr<Node> child = document()->adoptNode(children[i].release(), ASSERT_NO_EXCEPTION_STATE);
         parserAppendChild(child.get());
         // FIXME: Together with adoptNode above, the tree scope might get updated recursively twice
         // (if the document changed or oldParent was in a shadow tree, AND *this is in a shadow tree).
@@ -145,72 +147,77 @@
         : newChild->contains(newParent);
 }
 
-static inline ExceptionCode checkAcceptChild(ContainerNode* newParent, Node* newChild, Node* oldChild)
+static inline bool checkAcceptChild(ContainerNode* newParent, Node* newChild, Node* oldChild, ExceptionState& es)
 {
     // Not mentioned in spec: throw NotFoundError if newChild is null
-    if (!newChild)
-        return NotFoundError;
+    if (!newChild) {
+        es.throwDOMException(NotFoundError);
+        return false;
+    }
 
     // Use common case fast path if possible.
     if ((newChild->isElementNode() || newChild->isTextNode()) && newParent->isElementNode()) {
         ASSERT(!newParent->isDocumentTypeNode());
         ASSERT(isChildTypeAllowed(newParent, newChild));
-        if (containsConsideringHostElements(newChild, newParent))
-            return HierarchyRequestError;
-        return 0;
+        if (containsConsideringHostElements(newChild, newParent)) {
+            es.throwDOMException(HierarchyRequestError);
+            return false;
+        }
+        return true;
     }
 
     // This should never happen, but also protect release builds from tree corruption.
     ASSERT(!newChild->isPseudoElement());
-    if (newChild->isPseudoElement())
-        return HierarchyRequestError;
-
-    if (newChild->inDocument() && newChild->isDocumentTypeNode())
-        return HierarchyRequestError;
-    if (containsConsideringHostElements(newChild, newParent))
-        return HierarchyRequestError;
-
-    if (oldChild && newParent->isDocumentNode()) {
-        if (!toDocument(newParent)->canReplaceChild(newChild, oldChild))
-            return HierarchyRequestError;
-    } else if (!isChildTypeAllowed(newParent, newChild)) {
-        return HierarchyRequestError;
+    if (newChild->isPseudoElement()) {
+        es.throwDOMException(HierarchyRequestError);
+        return false;
     }
 
-    return 0;
+    if (newChild->inDocument() && newChild->isDocumentTypeNode()) {
+        es.throwDOMException(HierarchyRequestError);
+        return false;
+    }
+    if (containsConsideringHostElements(newChild, newParent)) {
+        es.throwDOMException(HierarchyRequestError);
+        return false;
+    }
+
+    if (oldChild && newParent->isDocumentNode()) {
+        if (!toDocument(newParent)->canReplaceChild(newChild, oldChild)) {
+            es.throwDOMException(HierarchyRequestError);
+            return false;
+        }
+    } else if (!isChildTypeAllowed(newParent, newChild)) {
+        es.throwDOMException(HierarchyRequestError);
+        return false;
+    }
+
+    return true;
 }
 
-static inline bool checkAcceptChildGuaranteedNodeTypes(ContainerNode* newParent, Node* newChild, ExceptionCode& ec)
+static inline bool checkAcceptChildGuaranteedNodeTypes(ContainerNode* newParent, Node* newChild, ExceptionState& es)
 {
     ASSERT(!newParent->isDocumentTypeNode());
     ASSERT(isChildTypeAllowed(newParent, newChild));
     if (newChild->contains(newParent)) {
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
         return false;
     }
 
     return true;
 }
 
-static inline bool checkAddChild(ContainerNode* newParent, Node* newChild, ExceptionCode& ec)
+static inline bool checkAddChild(ContainerNode* newParent, Node* newChild, ExceptionState& es)
 {
-    ec = checkAcceptChild(newParent, newChild, 0);
-    if (ec)
-        return false;
-
-    return true;
+    return checkAcceptChild(newParent, newChild, 0, es);
 }
 
-static inline bool checkReplaceChild(ContainerNode* newParent, Node* newChild, Node* oldChild, ExceptionCode& ec)
+static inline bool checkReplaceChild(ContainerNode* newParent, Node* newChild, Node* oldChild, ExceptionState& es)
 {
-    ec = checkAcceptChild(newParent, newChild, oldChild);
-    if (ec)
-        return false;
-
-    return true;
+    return checkAcceptChild(newParent, newChild, oldChild, es);
 }
 
-void ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& ec, AttachBehavior attachBehavior)
+void ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionState& es, AttachBehavior attachBehavior)
 {
     // Check that this node is not "floating".
     // If it is, it can be deleted as a side effect of sending mutation events.
@@ -218,21 +225,21 @@
 
     RefPtr<Node> protect(this);
 
-    ec = 0;
+    es.clearException();
 
     // insertBefore(node, 0) is equivalent to appendChild(node)
     if (!refChild) {
-        appendChild(newChild, ec, attachBehavior);
+        appendChild(newChild, es, attachBehavior);
         return;
     }
 
     // Make sure adding the new child is OK.
-    if (!checkAddChild(this, newChild.get(), ec))
+    if (!checkAddChild(this, newChild.get(), es))
         return;
 
     // NotFoundError: Raised if refChild is not a child of this node
     if (refChild->parentNode() != this) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -242,14 +249,14 @@
     RefPtr<Node> next = refChild;
 
     NodeVector targets;
-    collectChildrenAndRemoveFromOldParent(newChild.get(), targets, ec);
-    if (ec)
+    collectChildrenAndRemoveFromOldParent(newChild.get(), targets, es);
+    if (es.hadException())
         return;
     if (targets.isEmpty())
         return;
 
     // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
-    if (!checkAcceptChildGuaranteedNodeTypes(this, newChild.get(), ec))
+    if (!checkAcceptChildGuaranteedNodeTypes(this, newChild.get(), es))
         return;
 
     InspectorInstrumentation::willInsertDOMNode(document(), this);
@@ -315,7 +322,7 @@
         return;
 
     if (document() != newChild->document())
-        document()->adoptNode(newChild.get(), ASSERT_NO_EXCEPTION);
+        document()->adoptNode(newChild.get(), ASSERT_NO_EXCEPTION_STATE);
 
     insertBeforeCommon(nextChild, newChild.get());
 
@@ -327,7 +334,7 @@
     ChildNodeInsertionNotifier(this).notify(newChild.get());
 }
 
-void ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode& ec, AttachBehavior attachBehavior)
+void ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionState& es, AttachBehavior attachBehavior)
 {
     // Check that this node is not "floating".
     // If it is, it can be deleted as a side effect of sending mutation events.
@@ -335,23 +342,23 @@
 
     RefPtr<Node> protect(this);
 
-    ec = 0;
+    es.clearException();
 
     if (oldChild == newChild) // nothing to do
         return;
 
     if (!oldChild) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
     // Make sure replacing the old child with the new is ok
-    if (!checkReplaceChild(this, newChild.get(), oldChild, ec))
+    if (!checkReplaceChild(this, newChild.get(), oldChild, es))
         return;
 
     // NotFoundError: Raised if oldChild is not a child of this node.
     if (oldChild->parentNode() != this) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -361,24 +368,24 @@
 
     // Remove the node we're replacing
     RefPtr<Node> removedChild = oldChild;
-    removeChild(oldChild, ec);
-    if (ec)
+    removeChild(oldChild, es);
+    if (es.hadException())
         return;
 
     if (next && (next->previousSibling() == newChild || next == newChild)) // nothing to do
         return;
 
     // Does this one more time because removeChild() fires a MutationEvent.
-    if (!checkReplaceChild(this, newChild.get(), oldChild, ec))
+    if (!checkReplaceChild(this, newChild.get(), oldChild, es))
         return;
 
     NodeVector targets;
-    collectChildrenAndRemoveFromOldParent(newChild.get(), targets, ec);
-    if (ec)
+    collectChildrenAndRemoveFromOldParent(newChild.get(), targets, es);
+    if (es.hadException())
         return;
 
     // Does this yet another check because collectChildrenAndRemoveFromOldParent() fires a MutationEvent.
-    if (!checkReplaceChild(this, newChild.get(), oldChild, ec))
+    if (!checkReplaceChild(this, newChild.get(), oldChild, es))
         return;
 
     InspectorInstrumentation::willInsertDOMNode(document(), this);
@@ -448,7 +455,7 @@
     ChildFrameDisconnector(this).disconnect();
 }
 
-void ContainerNode::removeChild(Node* oldChild, ExceptionCode& ec)
+void ContainerNode::removeChild(Node* oldChild, ExceptionState& es)
 {
     // Check that this node is not "floating".
     // If it is, it can be deleted as a side effect of sending mutation events.
@@ -456,11 +463,11 @@
 
     RefPtr<Node> protect(this);
 
-    ec = 0;
+    es.clearException();
 
     // NotFoundError: Raised if oldChild is not a child of this node.
     if (!oldChild || oldChild->parentNode() != this) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -474,7 +481,7 @@
     // Events fired when blurring currently focused node might have moved this
     // child into a different parent.
     if (child->parentNode() != this) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -482,7 +489,7 @@
 
     // Mutation events might have moved this child into a different parent.
     if (child->parentNode() != this) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -589,7 +596,7 @@
     dispatchSubtreeModifiedEvent();
 }
 
-void ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, AttachBehavior attachBehavior)
+void ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionState& es, AttachBehavior attachBehavior)
 {
     RefPtr<ContainerNode> protect(this);
 
@@ -597,25 +604,25 @@
     // If it is, it can be deleted as a side effect of sending mutation events.
     ASSERT(refCount() || parentOrShadowHostNode());
 
-    ec = 0;
+    es.clearException();
 
     // Make sure adding the new child is ok
-    if (!checkAddChild(this, newChild.get(), ec))
+    if (!checkAddChild(this, newChild.get(), es))
         return;
 
     if (newChild == m_lastChild) // nothing to do
         return;
 
     NodeVector targets;
-    collectChildrenAndRemoveFromOldParent(newChild.get(), targets, ec);
-    if (ec)
+    collectChildrenAndRemoveFromOldParent(newChild.get(), targets, es);
+    if (es.hadException())
         return;
 
     if (targets.isEmpty())
         return;
 
     // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
-    if (!checkAcceptChildGuaranteedNodeTypes(this, newChild.get(), ec))
+    if (!checkAcceptChildGuaranteedNodeTypes(this, newChild.get(), es))
         return;
 
     InspectorInstrumentation::willInsertDOMNode(document(), this);
@@ -653,7 +660,7 @@
     ASSERT(!hasTagName(HTMLNames::templateTag));
 
     if (document() != newChild->document())
-        document()->adoptNode(newChild.get(), ASSERT_NO_EXCEPTION);
+        document()->adoptNode(newChild.get(), ASSERT_NO_EXCEPTION_STATE);
 
     Node* last = m_lastChild;
     {
@@ -733,9 +740,9 @@
 
 void ContainerNode::cloneChildNodes(ContainerNode *clone)
 {
-    ExceptionCode ec = 0;
-    for (Node* n = firstChild(); n && !ec; n = n->nextSibling())
-        clone->appendChild(n->cloneNode(true), ec);
+    TrackExceptionState es;
+    for (Node* n = firstChild(); n && !es.hadException(); n = n->nextSibling())
+        clone->appendChild(n->cloneNode(true), es);
 }
 
 
diff --git a/Source/core/dom/ContainerNode.h b/Source/core/dom/ContainerNode.h
index f7ea2e8..ef3862b 100644
--- a/Source/core/dom/ContainerNode.h
+++ b/Source/core/dom/ContainerNode.h
@@ -24,13 +24,14 @@
 #ifndef ContainerNode_h
 #define ContainerNode_h
 
-#include "core/dom/ExceptionCodePlaceholder.h"
+#include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "core/dom/Node.h"
 #include "wtf/OwnPtr.h"
 #include "wtf/Vector.h"
 
 namespace WebCore {
 
+class ExceptionState;
 class FloatPoint;
 class HTMLCollection;
 
@@ -95,10 +96,10 @@
     unsigned childNodeCount() const;
     Node* childNode(unsigned index) const;
 
-    void insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& = ASSERT_NO_EXCEPTION, AttachBehavior = AttachNow);
-    void replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode& = ASSERT_NO_EXCEPTION, AttachBehavior = AttachNow);
-    void removeChild(Node* child, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    void appendChild(PassRefPtr<Node> newChild, ExceptionCode& = ASSERT_NO_EXCEPTION, AttachBehavior = AttachNow);
+    void insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionState& = ASSERT_NO_EXCEPTION_STATE, AttachBehavior = AttachNow);
+    void replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionState& = ASSERT_NO_EXCEPTION_STATE, AttachBehavior = AttachNow);
+    void removeChild(Node* child, ExceptionState& = ASSERT_NO_EXCEPTION_STATE);
+    void appendChild(PassRefPtr<Node> newChild, ExceptionState& = ASSERT_NO_EXCEPTION_STATE, AttachBehavior = AttachNow);
 
     // These methods are only used during parsing.
     // They don't send DOM mutation events or handle reparenting.
diff --git a/Source/core/dom/CustomElementRegistrationContext.cpp b/Source/core/dom/CustomElementRegistrationContext.cpp
index d37ba1e..1a7ea72 100644
--- a/Source/core/dom/CustomElementRegistrationContext.cpp
+++ b/Source/core/dom/CustomElementRegistrationContext.cpp
@@ -34,6 +34,7 @@
 #include "HTMLNames.h"
 #include "MathMLNames.h"
 #include "SVGNames.h"
+#include "bindings/v8/ExceptionState.h"
 #include "core/dom/CustomElement.h"
 #include "core/dom/CustomElementDefinition.h"
 #include "core/dom/Element.h"
@@ -44,9 +45,9 @@
 
 namespace WebCore {
 
-void CustomElementRegistrationContext::registerElement(Document* document, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& type, ExceptionCode& ec)
+void CustomElementRegistrationContext::registerElement(Document* document, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& type, ExceptionState& es)
 {
-    CustomElementDefinition* definition = m_registry.registerElement(document, constructorBuilder, type, ec);
+    CustomElementDefinition* definition = m_registry.registerElement(document, constructorBuilder, type, es);
 
     if (!definition)
         return;
diff --git a/Source/core/dom/CustomElementRegistrationContext.h b/Source/core/dom/CustomElementRegistrationContext.h
index c8c2e15..f45f053 100644
--- a/Source/core/dom/CustomElementRegistrationContext.h
+++ b/Source/core/dom/CustomElementRegistrationContext.h
@@ -34,7 +34,6 @@
 #include "core/dom/CustomElementDescriptor.h"
 #include "core/dom/CustomElementRegistry.h"
 #include "core/dom/CustomElementUpgradeCandidateMap.h"
-#include "core/dom/ExceptionCode.h"
 #include "core/dom/QualifiedName.h"
 #include "wtf/HashMap.h"
 #include "wtf/PassRefPtr.h"
@@ -47,6 +46,7 @@
 class CustomElementDefinition;
 class Document;
 class Element;
+class ExceptionState;
 
 class CustomElementRegistrationContext : public RefCounted<CustomElementRegistrationContext> {
 public:
@@ -61,7 +61,7 @@
     static bool isCustomTagName(const AtomicString& localName);
 
     // Definitions
-    void registerElement(Document*, CustomElementConstructorBuilder*, const AtomicString& type, ExceptionCode&);
+    void registerElement(Document*, CustomElementConstructorBuilder*, const AtomicString& type, ExceptionState&);
 
     // Instance creation
     PassRefPtr<Element> createCustomTagElement(Document*, const QualifiedName&);
diff --git a/Source/core/dom/CustomElementRegistry.cpp b/Source/core/dom/CustomElementRegistry.cpp
index 5755cc3..ac55220 100644
--- a/Source/core/dom/CustomElementRegistry.cpp
+++ b/Source/core/dom/CustomElementRegistry.cpp
@@ -34,9 +34,11 @@
 #include "HTMLNames.h"
 #include "SVGNames.h"
 #include "bindings/v8/CustomElementConstructorBuilder.h"
+#include "bindings/v8/ExceptionState.h"
 #include "core/dom/CustomElementDefinition.h"
 #include "core/dom/CustomElementRegistrationContext.h"
 #include "core/dom/DocumentLifecycleObserver.h"
+#include "core/dom/ExceptionCode.h"
 
 namespace WebCore {
 
@@ -56,7 +58,7 @@
     bool m_wentAway;
 };
 
-CustomElementDefinition* CustomElementRegistry::registerElement(Document* document, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& userSuppliedName, ExceptionCode& ec)
+CustomElementDefinition* CustomElementRegistry::registerElement(Document* document, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& userSuppliedName, ExceptionState& es)
 {
     // FIXME: In every instance except one it is the
     // CustomElementConstructorBuilder that observes document
@@ -65,30 +67,30 @@
     RegistrationContextObserver observer(document);
 
     if (!constructorBuilder->isFeatureAllowed()) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
 
     AtomicString type = userSuppliedName.lower();
     if (!CustomElementRegistrationContext::isValidTypeName(type)) {
-        ec = InvalidCharacterError;
+        es.throwDOMException(InvalidCharacterError);
         return 0;
     }
 
     if (!constructorBuilder->validateOptions()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
     QualifiedName tagName = nullQName();
     if (!constructorBuilder->findTagName(type, tagName)) {
-        ec = NamespaceError;
+        es.throwDOMException(NamespaceError);
         return 0;
     }
     ASSERT(tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI || tagName.namespaceURI() == SVGNames::svgNamespaceURI);
 
     if (m_registeredTypeNames.contains(type)) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
@@ -99,7 +101,7 @@
     // Consulting the constructor builder could execute script and
     // kill the document.
     if (observer.registrationContextWentAway()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
@@ -107,7 +109,7 @@
     RefPtr<CustomElementDefinition> definition = CustomElementDefinition::create(descriptor, lifecycleCallbacks);
 
     if (!constructorBuilder->createConstructor(document, definition.get())) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
 
@@ -115,7 +117,7 @@
     m_registeredTypeNames.add(descriptor.type());
 
     if (!constructorBuilder->didRegisterDefinition(definition.get())) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
 
diff --git a/Source/core/dom/CustomElementRegistry.h b/Source/core/dom/CustomElementRegistry.h
index 36477fe..c9ff8db 100644
--- a/Source/core/dom/CustomElementRegistry.h
+++ b/Source/core/dom/CustomElementRegistry.h
@@ -34,7 +34,6 @@
 #include "core/dom/CustomElementDefinition.h"
 #include "core/dom/CustomElementDescriptor.h"
 #include "core/dom/CustomElementDescriptorHash.h"
-#include "core/dom/ExceptionCode.h"
 #include "wtf/HashMap.h"
 #include "wtf/HashSet.h"
 #include "wtf/RefPtr.h"
@@ -45,6 +44,7 @@
 
 class CustomElementConstructorBuilder;
 class Document;
+class ExceptionState;
 
 class CustomElementRegistry {
     WTF_MAKE_NONCOPYABLE(CustomElementRegistry);
@@ -54,7 +54,7 @@
     CustomElementRegistry() { }
     virtual ~CustomElementRegistry() { }
 
-    CustomElementDefinition* registerElement(Document*, CustomElementConstructorBuilder*, const AtomicString& name, ExceptionCode&);
+    CustomElementDefinition* registerElement(Document*, CustomElementConstructorBuilder*, const AtomicString& name, ExceptionState&);
     CustomElementDefinition* find(const CustomElementDescriptor&) const;
 
 private:
diff --git a/Source/core/dom/DOMImplementation.cpp b/Source/core/dom/DOMImplementation.cpp
index d4b633c..14c51fe 100644
--- a/Source/core/dom/DOMImplementation.cpp
+++ b/Source/core/dom/DOMImplementation.cpp
@@ -27,6 +27,7 @@
 
 #include "HTMLNames.h"
 #include "SVGNames.h"
+#include "bindings/v8/ExceptionState.h"
 #include "core/css/CSSStyleSheet.h"
 #include "core/css/MediaList.h"
 #include "core/css/StyleSheetContents.h"
@@ -177,10 +178,10 @@
 }
 
 PassRefPtr<DocumentType> DOMImplementation::createDocumentType(const String& qualifiedName,
-    const String& publicId, const String& systemId, ExceptionCode& ec)
+    const String& publicId, const String& systemId, ExceptionState& es)
 {
     String prefix, localName;
-    if (!Document::parseQualifiedName(qualifiedName, prefix, localName, ec))
+    if (!Document::parseQualifiedName(qualifiedName, prefix, localName, es))
         return 0;
 
     return DocumentType::create(0, qualifiedName, publicId, systemId);
@@ -192,7 +193,7 @@
 }
 
 PassRefPtr<Document> DOMImplementation::createDocument(const String& namespaceURI,
-    const String& qualifiedName, DocumentType* doctype, ExceptionCode& ec)
+    const String& qualifiedName, DocumentType* doctype, ExceptionState& es)
 {
     RefPtr<Document> doc;
     if (namespaceURI == SVGNames::svgNamespaceURI)
@@ -207,8 +208,8 @@
 
     RefPtr<Node> documentElement;
     if (!qualifiedName.isEmpty()) {
-        documentElement = doc->createElementNS(namespaceURI, qualifiedName, ec);
-        if (ec)
+        documentElement = doc->createElementNS(namespaceURI, qualifiedName, es);
+        if (es.hadException())
             return 0;
     }
 
@@ -218,7 +219,7 @@
     // other exceptions to WrongDocumentError (based on order mentioned in spec),
     // but this matches the new DOM Core spec (http://www.w3.org/TR/domcore/).
     if (doctype && doctype->document()) {
-        ec = WrongDocumentError;
+        es.throwDOMException(WrongDocumentError);
         return 0;
     }
 
diff --git a/Source/core/dom/DOMImplementation.h b/Source/core/dom/DOMImplementation.h
index e09ff6e..153f4c4 100644
--- a/Source/core/dom/DOMImplementation.h
+++ b/Source/core/dom/DOMImplementation.h
@@ -33,12 +33,11 @@
 class CSSStyleSheet;
 class Document;
 class DocumentType;
+class ExceptionState;
 class Frame;
 class HTMLDocument;
 class KURL;
 
-typedef int ExceptionCode;
-
 class DOMImplementation : public ScriptWrappable {
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -50,8 +49,8 @@
 
     // DOM methods & attributes for DOMImplementation
     static bool hasFeature(const String& feature, const String& version);
-    PassRefPtr<DocumentType> createDocumentType(const String& qualifiedName, const String& publicId, const String& systemId, ExceptionCode&);
-    PassRefPtr<Document> createDocument(const String& namespaceURI, const String& qualifiedName, DocumentType*, ExceptionCode&);
+    PassRefPtr<DocumentType> createDocumentType(const String& qualifiedName, const String& publicId, const String& systemId, ExceptionState&);
+    PassRefPtr<Document> createDocument(const String& namespaceURI, const String& qualifiedName, DocumentType*, ExceptionState&);
 
     DOMImplementation* getInterface(const String& feature);
 
diff --git a/Source/core/dom/DOMStringMap.cpp b/Source/core/dom/DOMStringMap.cpp
index 21415cd..f5f1f9d 100644
--- a/Source/core/dom/DOMStringMap.cpp
+++ b/Source/core/dom/DOMStringMap.cpp
@@ -32,7 +32,7 @@
 {
 }
 
-bool DOMStringMap::namedPropertyQuery(const AtomicString& name, ExceptionCode& ec)
+bool DOMStringMap::namedPropertyQuery(const AtomicString& name, ExceptionState&)
 {
     return contains(name);
 }
diff --git a/Source/core/dom/DOMStringMap.h b/Source/core/dom/DOMStringMap.h
index 3408945..1ded783 100644
--- a/Source/core/dom/DOMStringMap.h
+++ b/Source/core/dom/DOMStringMap.h
@@ -26,6 +26,7 @@
 #ifndef DOMStringMap_h
 #define DOMStringMap_h
 
+#include "bindings/v8/ExceptionState.h"
 #include "bindings/v8/ScriptWrappable.h"
 #include "wtf/Noncopyable.h"
 #include "wtf/Vector.h"
@@ -34,7 +35,6 @@
 namespace WebCore {
 
 class Element;
-typedef int ExceptionCode;
 
 class DOMStringMap : public ScriptWrappable {
     WTF_MAKE_NONCOPYABLE(DOMStringMap); WTF_MAKE_FAST_ALLOCATED;
@@ -47,29 +47,29 @@
     virtual void getNames(Vector<String>&) = 0;
     virtual String item(const String& name) = 0;
     virtual bool contains(const String& name) = 0;
-    virtual void setItem(const String& name, const String& value, ExceptionCode&) = 0;
-    virtual void deleteItem(const String& name, ExceptionCode&) = 0;
-    bool anonymousNamedSetter(const String& name, const String& value, ExceptionCode& ec)
+    virtual void setItem(const String& name, const String& value, ExceptionState&) = 0;
+    virtual void deleteItem(const String& name, ExceptionState&) = 0;
+    bool anonymousNamedSetter(const String& name, const String& value, ExceptionState& es)
     {
-        setItem(name, value, ec);
+        setItem(name, value, es);
         return true;
     }
-    bool anonymousNamedDeleter(const AtomicString& name, ExceptionCode& ec)
+    bool anonymousNamedDeleter(const AtomicString& name, ExceptionState& es)
     {
-        deleteItem(name, ec);
-        bool result = !ec;
+        deleteItem(name, es);
+        bool result = !es.hadException();
         // DOMStringMap deleter should ignore exception.
         // Behavior of Firefox and Opera are same.
         // delete document.body.dataset["-foo"] // false instead of DOM Exception 12
         // LayoutTests/fast/dom/HTMLSelectElement/select-selectedIndex-multiple.html
-        ec = 0;
+        es.clearException();
         return result;
     }
-    void namedPropertyEnumerator(Vector<String>& names, ExceptionCode&)
+    void namedPropertyEnumerator(Vector<String>& names, ExceptionState&)
     {
         getNames(names);
     }
-    bool namedPropertyQuery(const AtomicString&, ExceptionCode&);
+    bool namedPropertyQuery(const AtomicString&, ExceptionState&);
 
     virtual Element* element() = 0;
 
diff --git a/Source/core/dom/DataTransferItemList.h b/Source/core/dom/DataTransferItemList.h
index 4e9c6d6..91fd967 100644
--- a/Source/core/dom/DataTransferItemList.h
+++ b/Source/core/dom/DataTransferItemList.h
@@ -41,7 +41,7 @@
 class Clipboard;
 class File;
 
-typedef int ExceptionCode;
+class ExceptionState;
 
 class DataTransferItemList : public RefCounted<DataTransferItemList>, public ScriptWrappable {
 public:
@@ -54,9 +54,9 @@
 
     virtual size_t length() const = 0;
     virtual PassRefPtr<DataTransferItem> item(unsigned long index) = 0;
-    virtual void deleteItem(unsigned long index, ExceptionCode&) = 0;
+    virtual void deleteItem(unsigned long index, ExceptionState&) = 0;
     virtual void clear() = 0;
-    virtual void add(const String& data, const String& type, ExceptionCode&) = 0;
+    virtual void add(const String& data, const String& type, ExceptionState&) = 0;
     virtual void add(PassRefPtr<File>) = 0;
 };
 
diff --git a/Source/core/dom/DatasetDOMStringMap.cpp b/Source/core/dom/DatasetDOMStringMap.cpp
index 10e9b40..fbeaa54 100644
--- a/Source/core/dom/DatasetDOMStringMap.cpp
+++ b/Source/core/dom/DatasetDOMStringMap.cpp
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "core/dom/DatasetDOMStringMap.h"
 
+#include "bindings/v8/ExceptionState.h"
 #include "core/dom/Attribute.h"
 #include "core/dom/Element.h"
 #include "core/dom/ExceptionCode.h"
@@ -176,20 +177,20 @@
     return false;
 }
 
-void DatasetDOMStringMap::setItem(const String& name, const String& value, ExceptionCode& ec)
+void DatasetDOMStringMap::setItem(const String& name, const String& value, ExceptionState& es)
 {
     if (!isValidPropertyName(name)) {
-        ec = SyntaxError;
+        es.throwDOMException(SyntaxError);
         return;
     }
 
-    m_element->setAttribute(convertPropertyNameToAttributeName(name), value, ec);
+    m_element->setAttribute(convertPropertyNameToAttributeName(name), value, es);
 }
 
-void DatasetDOMStringMap::deleteItem(const String& name, ExceptionCode& ec)
+void DatasetDOMStringMap::deleteItem(const String& name, ExceptionState& es)
 {
     if (!isValidPropertyName(name)) {
-        ec = SyntaxError;
+        es.throwDOMException(SyntaxError);
         return;
     }
 
diff --git a/Source/core/dom/DatasetDOMStringMap.h b/Source/core/dom/DatasetDOMStringMap.h
index c716181..9bbd1d0 100644
--- a/Source/core/dom/DatasetDOMStringMap.h
+++ b/Source/core/dom/DatasetDOMStringMap.h
@@ -32,6 +32,7 @@
 namespace WebCore {
 
 class Element;
+class ExceptionState;
 
 class DatasetDOMStringMap : public DOMStringMap {
 public:
@@ -46,8 +47,8 @@
     virtual void getNames(Vector<String>&);
     virtual String item(const String& name);
     virtual bool contains(const String& name);
-    virtual void setItem(const String& name, const String& value, ExceptionCode&);
-    virtual void deleteItem(const String& name, ExceptionCode&);
+    virtual void setItem(const String& name, const String& value, ExceptionState&);
+    virtual void deleteItem(const String& name, ExceptionState&);
 
     virtual Element* element() { return m_element; }
 
diff --git a/Source/core/dom/DecodedDataDocumentParser.cpp b/Source/core/dom/DecodedDataDocumentParser.cpp
index 610d44e..462051c 100644
--- a/Source/core/dom/DecodedDataDocumentParser.cpp
+++ b/Source/core/dom/DecodedDataDocumentParser.cpp
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "core/dom/DecodedDataDocumentParser.h"
 
+#include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "core/dom/Document.h"
 #include "core/dom/Element.h"
 #include "core/loader/TextResourceDecoder.h"
@@ -74,7 +75,7 @@
     CString originalBytes = titleElement->textContent().latin1();
     OwnPtr<TextCodec> codec = newTextCodec(m_document->decoder()->encoding());
     String correctlyDecodedTitle = codec->decode(originalBytes.data(), originalBytes.length(), true);
-    titleElement->setTextContent(correctlyDecodedTitle, IGNORE_EXCEPTION);
+    titleElement->setTextContent(correctlyDecodedTitle, IGNORE_EXCEPTION_STATE);
 }
 
 }
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index ad152ed..a912fc8 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -37,6 +37,8 @@
 #include "XMLNames.h"
 #include "bindings/v8/CustomElementConstructorBuilder.h"
 #include "bindings/v8/Dictionary.h"
+#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "bindings/v8/ScriptController.h"
 #include "core/accessibility/AXObjectCache.h"
 #include "core/animation/DocumentTimeline.h"
@@ -68,7 +70,6 @@
 #include "core/dom/EventListener.h"
 #include "core/dom/EventNames.h"
 #include "core/dom/ExceptionCode.h"
-#include "core/dom/ExceptionCodePlaceholder.h"
 #include "core/dom/HashChangeEvent.h"
 #include "core/dom/NamedFlowCollection.h"
 #include "core/dom/NodeFilter.h"
@@ -690,10 +691,10 @@
     clearStyleResolver();
 }
 
-PassRefPtr<Element> Document::createElement(const AtomicString& name, ExceptionCode& ec)
+PassRefPtr<Element> Document::createElement(const AtomicString& name, ExceptionState& es)
 {
     if (!isValidName(name)) {
-        ec = InvalidCharacterError;
+        es.throwDOMException(InvalidCharacterError);
         return 0;
     }
 
@@ -703,10 +704,10 @@
     return createElement(QualifiedName(nullAtom, name, nullAtom), false);
 }
 
-PassRefPtr<Element> Document::createElement(const AtomicString& localName, const AtomicString& typeExtension, ExceptionCode& ec)
+PassRefPtr<Element> Document::createElement(const AtomicString& localName, const AtomicString& typeExtension, ExceptionState& es)
 {
     if (!isValidName(localName)) {
-        ec = InvalidCharacterError;
+        es.throwDOMException(InvalidCharacterError);
         return 0;
     }
 
@@ -715,7 +716,7 @@
     if (CustomElementRegistrationContext::isCustomTagName(localName) && registrationContext())
         element = registrationContext()->createCustomTagElement(this, QualifiedName(nullAtom, localName, xhtmlNamespaceURI));
     else
-        element = createElement(localName, ec);
+        element = createElement(localName, es);
 
     if (!typeExtension.isNull() && !typeExtension.isEmpty())
         CustomElementRegistrationContext::setIsAttributeAndTypeExtension(element.get(), typeExtension);
@@ -723,15 +724,15 @@
     return element;
 }
 
-PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const String& qualifiedName, const AtomicString& typeExtension, ExceptionCode& ec)
+PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const String& qualifiedName, const AtomicString& typeExtension, ExceptionState& es)
 {
     String prefix, localName;
-    if (!parseQualifiedName(qualifiedName, prefix, localName, ec))
+    if (!parseQualifiedName(qualifiedName, prefix, localName, es))
         return 0;
 
     QualifiedName qName(prefix, localName, namespaceURI);
     if (!hasValidNamespaceForElements(qName)) {
-        ec = NamespaceError;
+        es.throwDOMException(NamespaceError);
         return 0;
     }
 
@@ -739,7 +740,7 @@
     if (CustomElementRegistrationContext::isCustomTagName(qName.localName()) && registrationContext())
         element = registrationContext()->createCustomTagElement(this, qName);
     else
-        element = createElementNS(namespaceURI, qualifiedName, ec);
+        element = createElementNS(namespaceURI, qualifiedName, es);
 
     if (!typeExtension.isNull() && !typeExtension.isEmpty())
         CustomElementRegistrationContext::setIsAttributeAndTypeExtension(element.get(), typeExtension);
@@ -747,20 +748,20 @@
     return element;
 }
 
-ScriptValue Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, ExceptionCode& ec)
+ScriptValue Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, ExceptionState& es)
 {
-    return registerElement(state, name, Dictionary(), ec);
+    return registerElement(state, name, Dictionary(), es);
 }
 
-ScriptValue Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, const Dictionary& options, ExceptionCode& ec)
+ScriptValue Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, const Dictionary& options, ExceptionState& es)
 {
     if (!registrationContext()) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return ScriptValue();
     }
 
     CustomElementConstructorBuilder constructorBuilder(state, &options);
-    registrationContext()->registerElement(this, &constructorBuilder, name, ec);
+    registrationContext()->registerElement(this, &constructorBuilder, name, es);
     return constructorBuilder.bindingsReturnValue();
 }
 
@@ -795,23 +796,23 @@
     return Comment::create(this, data);
 }
 
-PassRefPtr<CDATASection> Document::createCDATASection(const String& data, ExceptionCode& ec)
+PassRefPtr<CDATASection> Document::createCDATASection(const String& data, ExceptionState& es)
 {
     if (isHTMLDocument()) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
     return CDATASection::create(this, data);
 }
 
-PassRefPtr<ProcessingInstruction> Document::createProcessingInstruction(const String& target, const String& data, ExceptionCode& ec)
+PassRefPtr<ProcessingInstruction> Document::createProcessingInstruction(const String& target, const String& data, ExceptionState& es)
 {
     if (!isValidName(target)) {
-        ec = InvalidCharacterError;
+        es.throwDOMException(InvalidCharacterError);
         return 0;
     }
     if (isHTMLDocument()) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
     return ProcessingInstruction::create(this, target, data);
@@ -827,12 +828,12 @@
     return MutableStylePropertySet::create()->ensureCSSStyleDeclaration();
 }
 
-PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionCode& ec)
+PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionState& es)
 {
-    ec = 0;
+    es.clearException();
 
     if (!importedNode) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
 
@@ -840,9 +841,9 @@
     case TEXT_NODE:
         return createTextNode(importedNode->nodeValue());
     case CDATA_SECTION_NODE:
-        return createCDATASection(importedNode->nodeValue(), ec);
+        return createCDATASection(importedNode->nodeValue(), es);
     case PROCESSING_INSTRUCTION_NODE:
-        return createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue(), ec);
+        return createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue(), es);
     case COMMENT_NODE:
         return createComment(importedNode->nodeValue());
     case ELEMENT_NODE: {
@@ -850,7 +851,7 @@
         // FIXME: The following check might be unnecessary. Is it possible that
         // oldElement has mismatched prefix/namespace?
         if (!hasValidNamespaceForElements(oldElement->tagQName())) {
-            ec = NamespaceError;
+            es.throwDOMException(NamespaceError);
             return 0;
         }
         RefPtr<Element> newElement = createElement(oldElement->tagQName(), false);
@@ -859,11 +860,11 @@
 
         if (deep) {
             for (Node* oldChild = oldElement->firstChild(); oldChild; oldChild = oldChild->nextSibling()) {
-                RefPtr<Node> newChild = importNode(oldChild, true, ec);
-                if (ec)
+                RefPtr<Node> newChild = importNode(oldChild, true, es);
+                if (es.hadException())
                     return 0;
-                newElement->appendChild(newChild.release(), ec);
-                if (ec)
+                newElement->appendChild(newChild.release(), es);
+                if (es.hadException())
                     return 0;
             }
         }
@@ -882,11 +883,11 @@
         RefPtr<DocumentFragment> newFragment = createDocumentFragment();
         if (deep) {
             for (Node* oldChild = oldFragment->firstChild(); oldChild; oldChild = oldChild->nextSibling()) {
-                RefPtr<Node> newChild = importNode(oldChild, true, ec);
-                if (ec)
+                RefPtr<Node> newChild = importNode(oldChild, true, es);
+                if (es.hadException())
                     return 0;
-                newFragment->appendChild(newChild.release(), ec);
-                if (ec)
+                newFragment->appendChild(newChild.release(), es);
+                if (es.hadException())
                     return 0;
             }
         }
@@ -902,14 +903,14 @@
     case XPATH_NAMESPACE_NODE:
         break;
     }
-    ec = NotSupportedError;
+    es.throwDOMException(NotSupportedError);
     return 0;
 }
 
-PassRefPtr<Node> Document::adoptNode(PassRefPtr<Node> source, ExceptionCode& ec)
+PassRefPtr<Node> Document::adoptNode(PassRefPtr<Node> source, ExceptionState& es)
 {
     if (!source) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
 
@@ -921,32 +922,32 @@
     case DOCUMENT_NODE:
     case DOCUMENT_TYPE_NODE:
     case XPATH_NAMESPACE_NODE:
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     case ATTRIBUTE_NODE: {
         Attr* attr = toAttr(source.get());
         if (attr->ownerElement())
-            attr->ownerElement()->removeAttributeNode(attr, ec);
+            attr->ownerElement()->removeAttributeNode(attr, es);
         attr->setSpecified(true);
         break;
     }
     default:
         if (source->isShadowRoot()) {
             // ShadowRoot cannot disconnect itself from the host node.
-            ec = HierarchyRequestError;
+            es.throwDOMException(HierarchyRequestError);
             return 0;
         }
 
         if (source->isFrameOwnerElement()) {
             HTMLFrameOwnerElement* frameOwnerElement = toFrameOwnerElement(source.get());
             if (frame() && frame()->tree()->isDescendantOf(frameOwnerElement->contentFrame())) {
-                ec = HierarchyRequestError;
+                es.throwDOMException(HierarchyRequestError);
                 return 0;
             }
         }
         if (source->parentNode()) {
-            source->parentNode()->removeChild(source.get(), ec);
-            if (ec)
+            source->parentNode()->removeChild(source.get(), es);
+            if (es.hadException())
                 return 0;
         }
     }
@@ -1040,15 +1041,15 @@
     return m_namedFlows.get();
 }
 
-PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec)
+PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionState& es)
 {
     String prefix, localName;
-    if (!parseQualifiedName(qualifiedName, prefix, localName, ec))
+    if (!parseQualifiedName(qualifiedName, prefix, localName, es))
         return 0;
 
     QualifiedName qName(prefix, localName, namespaceURI);
     if (!hasValidNamespaceForElements(qName)) {
-        ec = NamespaceError;
+        es.throwDOMException(NamespaceError);
         return 0;
     }
 
@@ -1132,25 +1133,25 @@
     setNeedsStyleRecalc();
 }
 
-void Document::setXMLVersion(const String& version, ExceptionCode& ec)
+void Document::setXMLVersion(const String& version, ExceptionState& es)
 {
     if (!implementation()->hasFeature("XML", String())) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return;
     }
 
     if (!XMLDocumentParser::supportsXMLVersion(version)) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return;
     }
 
     m_xmlVersion = version;
 }
 
-void Document::setXMLStandalone(bool standalone, ExceptionCode& ec)
+void Document::setXMLStandalone(bool standalone, ExceptionState& es)
 {
     if (!implementation()->hasFeature("XML", String())) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return;
     }
 
@@ -1313,7 +1314,7 @@
     else if (!m_titleElement) {
         if (HTMLElement* headElement = head()) {
             m_titleElement = createElement(titleTag, false);
-            headElement->appendChild(m_titleElement, ASSERT_NO_EXCEPTION, AttachLazily);
+            headElement->appendChild(m_titleElement, ASSERT_NO_EXCEPTION_STATE, AttachLazily);
         }
     }
 
@@ -1446,20 +1447,20 @@
     return Range::create(this);
 }
 
-PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, ExceptionCode& ec)
+PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, ExceptionState& es)
 {
     // FIXME: Probably this should be handled within the bindings layer and TypeError should be thrown.
     if (!root) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
     return NodeIterator::create(root, NodeFilter::SHOW_ALL, PassRefPtr<NodeFilter>());
 }
 
-PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatToShow, ExceptionCode& ec)
+PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatToShow, ExceptionState& es)
 {
     if (!root) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
     // FIXME: It might be a good idea to emit a warning if |whatToShow| contains a bit that is not defined in
@@ -1467,20 +1468,20 @@
     return NodeIterator::create(root, whatToShow, PassRefPtr<NodeFilter>());
 }
 
-PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter> filter, ExceptionCode& ec)
+PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter> filter, ExceptionState& es)
 {
     if (!root) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
     // FIXME: Ditto.
     return NodeIterator::create(root, whatToShow, filter);
 }
 
-PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences, ExceptionCode& ec)
+PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences, ExceptionState& es)
 {
     if (!root) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
     // FIXME: Warn if |expandEntityReferences| is specified. This optional argument is deprecated in DOM4.
@@ -1488,38 +1489,38 @@
     return NodeIterator::create(root, whatToShow, filter);
 }
 
-PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, ExceptionCode& ec)
+PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, ExceptionState& es)
 {
     if (!root) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
     return TreeWalker::create(root, NodeFilter::SHOW_ALL, PassRefPtr<NodeFilter>());
 }
 
-PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToShow, ExceptionCode& ec)
+PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToShow, ExceptionState& es)
 {
     if (!root) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
     return TreeWalker::create(root, whatToShow, PassRefPtr<NodeFilter>());
 }
 
-PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter> filter, ExceptionCode& ec)
+PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter> filter, ExceptionState& es)
 {
     if (!root) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
     return TreeWalker::create(root, whatToShow, filter);
 }
 
-PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences, ExceptionCode& ec)
+PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences, ExceptionState& es)
 {
     UNUSED_PARAM(expandEntityReferences);
     if (!root) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
     return TreeWalker::create(root, whatToShow, filter);
@@ -1557,7 +1558,7 @@
 
 bool Document::hasPendingForcedStyleRecalc() const
 {
-    return hasPendingStyleRecalc() && styleChangeType() == SubtreeStyleChange;
+    return hasPendingStyleRecalc() && styleChangeType() >= SubtreeStyleChange;
 }
 
 void Document::styleRecalcTimerFired(Timer<Document>*)
@@ -1632,7 +1633,7 @@
         if (!renderer())
             goto bailOut;
 
-        if (styleChangeType() == SubtreeStyleChange)
+        if (styleChangeType() >= SubtreeStyleChange)
             change = Force;
 
         // Recalculating the root style (on the document) is not needed in the common case.
@@ -2141,17 +2142,17 @@
     return 0;
 }
 
-void Document::setBody(PassRefPtr<HTMLElement> prpNewBody, ExceptionCode& ec)
+void Document::setBody(PassRefPtr<HTMLElement> prpNewBody, ExceptionState& es)
 {
     RefPtr<HTMLElement> newBody = prpNewBody;
 
     if (!newBody || !documentElement()) {
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
         return;
     }
 
     if (!newBody->hasTagName(bodyTag) && !newBody->hasTagName(framesetTag)) {
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
         return;
     }
 
@@ -2160,9 +2161,9 @@
         return;
 
     if (oldBody)
-        documentElement()->replaceChild(newBody.release(), oldBody, ec, AttachLazily);
+        documentElement()->replaceChild(newBody.release(), oldBody, es, AttachLazily);
     else
-        documentElement()->appendChild(newBody.release(), ec, AttachLazily);
+        documentElement()->appendChild(newBody.release(), es, AttachLazily);
 }
 
 HTMLHeadElement* Document::head()
@@ -2722,7 +2723,7 @@
         return;
 
     // Exception (for sandboxed documents) ignored.
-    toHTMLDocument(this)->setCookie(content, IGNORE_EXCEPTION);
+    toHTMLDocument(this)->setCookie(content, IGNORE_EXCEPTION_STATE);
 }
 
 void Document::processHttpEquivXFrameOptions(const String& content)
@@ -3471,13 +3472,13 @@
     m_eventQueue->enqueueEvent(event);
 }
 
-PassRefPtr<Event> Document::createEvent(const String& eventType, ExceptionCode& ec)
+PassRefPtr<Event> Document::createEvent(const String& eventType, ExceptionState& es)
 {
     RefPtr<Event> event = EventFactory::create(eventType);
     if (event)
         return event.release();
 
-    ec = NotSupportedError;
+    es.throwDOMException(NotSupportedError);
     return 0;
 }
 
@@ -3539,7 +3540,7 @@
     return frame()->ownerElement();
 }
 
-String Document::cookie(ExceptionCode& ec) const
+String Document::cookie(ExceptionState& es) const
 {
     if (page() && !page()->settings()->cookieEnabled())
         return String();
@@ -3549,7 +3550,7 @@
     // browsing context.
 
     if (!securityOrigin()->canAccessCookies()) {
-        ec = SecurityError;
+        es.throwDOMException(SecurityError);
         return String();
     }
 
@@ -3560,7 +3561,7 @@
     return cookies(this, cookieURL);
 }
 
-void Document::setCookie(const String& value, ExceptionCode& ec)
+void Document::setCookie(const String& value, ExceptionState& es)
 {
     if (page() && !page()->settings()->cookieEnabled())
         return;
@@ -3570,7 +3571,7 @@
     // browsing context.
 
     if (!securityOrigin()->canAccessCookies()) {
-        ec = SecurityError;
+        es.throwDOMException(SecurityError);
         return;
     }
 
@@ -3593,10 +3594,10 @@
     return securityOrigin()->domain();
 }
 
-void Document::setDomain(const String& newDomain, ExceptionCode& ec)
+void Document::setDomain(const String& newDomain, ExceptionState& es)
 {
     if (SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(securityOrigin()->protocol())) {
-        ec = SecurityError;
+        es.throwDOMException(SecurityError);
         return;
     }
 
@@ -3622,14 +3623,14 @@
     int newLength = newDomain.length();
     // e.g. newDomain = webkit.org (10) and domain() = www.webkit.org (14)
     if (newLength >= oldLength) {
-        ec = SecurityError;
+        es.throwDOMException(SecurityError);
         return;
     }
 
     String test = domain();
     // Check that it's a subdomain, not e.g. "ebkit.org"
     if (test[oldLength - newLength - 1] != '.') {
-        ec = SecurityError;
+        es.throwDOMException(SecurityError);
         return;
     }
 
@@ -3637,7 +3638,7 @@
     // and we check that it's the same thing as newDomain
     test.remove(0, oldLength - newLength);
     if (test != newDomain) {
-        ec = SecurityError;
+        es.throwDOMException(SecurityError);
         return;
     }
 
@@ -3744,7 +3745,7 @@
 }
 
 template<typename CharType>
-static bool parseQualifiedNameInternal(const String& qualifiedName, const CharType* characters, unsigned length, String& prefix, String& localName, ExceptionCode& ec)
+static bool parseQualifiedNameInternal(const String& qualifiedName, const CharType* characters, unsigned length, String& prefix, String& localName, ExceptionState& es)
 {
     bool nameStart = true;
     bool sawColon = false;
@@ -3755,7 +3756,7 @@
         U16_NEXT(characters, i, length, c)
         if (c == ':') {
             if (sawColon) {
-                ec = NamespaceError;
+                es.throwDOMException(NamespaceError);
                 return false; // multiple colons: not allowed
             }
             nameStart = true;
@@ -3763,13 +3764,13 @@
             colonPos = i - 1;
         } else if (nameStart) {
             if (!isValidNameStart(c)) {
-                ec = InvalidCharacterError;
+                es.throwDOMException(InvalidCharacterError);
                 return false;
             }
             nameStart = false;
         } else {
             if (!isValidNamePart(c)) {
-                ec = InvalidCharacterError;
+                es.throwDOMException(InvalidCharacterError);
                 return false;
             }
         }
@@ -3781,32 +3782,32 @@
     } else {
         prefix = qualifiedName.substring(0, colonPos);
         if (prefix.isEmpty()) {
-            ec = NamespaceError;
+            es.throwDOMException(NamespaceError);
             return false;
         }
         localName = qualifiedName.substring(colonPos + 1);
     }
 
     if (localName.isEmpty()) {
-        ec = NamespaceError;
+        es.throwDOMException(NamespaceError);
         return false;
     }
 
     return true;
 }
 
-bool Document::parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode& ec)
+bool Document::parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionState& es)
 {
     unsigned length = qualifiedName.length();
 
     if (!length) {
-        ec = InvalidCharacterError;
+        es.throwDOMException(InvalidCharacterError);
         return false;
     }
 
     if (qualifiedName.is8Bit())
-        return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters8(), length, prefix, localName, ec);
-    return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16(), length, prefix, localName, ec);
+        return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters8(), length, prefix, localName, es);
+    return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16(), length, prefix, localName, es);
 }
 
 void Document::setDecoder(PassRefPtr<TextResourceDecoder> decoder)
@@ -3988,21 +3989,21 @@
     return doc;
 }
 
-PassRefPtr<Attr> Document::createAttribute(const String& name, ExceptionCode& ec)
+PassRefPtr<Attr> Document::createAttribute(const String& name, ExceptionState& es)
 {
-    return createAttributeNS(String(), name, ec, true);
+    return createAttributeNS(String(), name, es, true);
 }
 
-PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec, bool shouldIgnoreNamespaceChecks)
+PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionState& es, bool shouldIgnoreNamespaceChecks)
 {
     String prefix, localName;
-    if (!parseQualifiedName(qualifiedName, prefix, localName, ec))
+    if (!parseQualifiedName(qualifiedName, prefix, localName, es))
         return 0;
 
     QualifiedName qName(prefix, localName, namespaceURI);
 
     if (!shouldIgnoreNamespaceChecks && !hasValidNamespaceForAttributes(qName)) {
-        ec = NamespaceError;
+        es.throwDOMException(NamespaceError);
         return 0;
     }
 
@@ -4085,12 +4086,12 @@
 
 PassRefPtr<HTMLCollection> Document::windowNamedItems(const AtomicString& name)
 {
-    return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<WindowNameCollection>(this, WindowNamedItems, name);
+    return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<HTMLNameCollection>(this, WindowNamedItems, name);
 }
 
 PassRefPtr<HTMLCollection> Document::documentNamedItems(const AtomicString& name)
 {
-    return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<DocumentNameCollection>(this, DocumentNamedItems, name);
+    return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<HTMLNameCollection>(this, DocumentNamedItems, name);
 }
 
 void Document::finishedParsing()
diff --git a/Source/core/dom/Document.h b/Source/core/dom/Document.h
index f9eb213..4d3ba07 100644
--- a/Source/core/dom/Document.h
+++ b/Source/core/dom/Document.h
@@ -64,7 +64,6 @@
 class CSSStyleDeclaration;
 class CSSStyleSheet;
 class CachedCSSStyleSheet;
-class ResourceFetcher;
 class CachedScript;
 class CanvasRenderingContext;
 class CharacterData;
@@ -77,6 +76,7 @@
 class DOMSecurityPolicy;
 class DOMSelection;
 class DOMWindow;
+class DOMWrapperWorld;
 class Database;
 class DatabaseThread;
 class DocumentFragment;
@@ -92,31 +92,31 @@
 class Element;
 class Event;
 class EventListener;
-class FloatRect;
+class ExceptionState;
 class FloatQuad;
+class FloatRect;
 class FormController;
 class Frame;
 class FrameView;
+class HTMLAllCollection;
 class HTMLCanvasElement;
 class HTMLCollection;
-class HTMLAllCollection;
 class HTMLDocument;
 class HTMLElement;
 class HTMLFrameOwnerElement;
 class HTMLHeadElement;
-class HTMLImport;
 class HTMLIFrameElement;
+class HTMLImport;
 class HTMLMapElement;
 class HTMLNameCollection;
 class HTMLScriptElement;
 class HitTestRequest;
 class HitTestResult;
 class IntPoint;
+class JSNode;
 class LayoutPoint;
 class LayoutRect;
 class LiveNodeListBase;
-class DOMWrapperWorld;
-class JSNode;
 class Locale;
 class MediaQueryList;
 class MediaQueryMatcher;
@@ -132,6 +132,7 @@
 class RegisteredEventListener;
 class RenderView;
 class RequestAnimationFrameCallback;
+class ResourceFetcher;
 class SVGDocumentExtensions;
 class ScriptElementData;
 class ScriptRunner;
@@ -307,17 +308,17 @@
 
     bool hasManifest() const;
 
-    PassRefPtr<Element> createElement(const AtomicString& name, ExceptionCode&);
+    PassRefPtr<Element> createElement(const AtomicString& name, ExceptionState&);
     PassRefPtr<DocumentFragment> createDocumentFragment();
     PassRefPtr<Text> createTextNode(const String& data);
     PassRefPtr<Comment> createComment(const String& data);
-    PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCode&);
-    PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&);
-    PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode&);
-    PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false);
-    PassRefPtr<Node> importNode(Node* importedNode, ExceptionCode& ec) { return importNode(importedNode, true, ec); }
-    PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&);
-    PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
+    PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionState&);
+    PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionState&);
+    PassRefPtr<Attr> createAttribute(const String& name, ExceptionState&);
+    PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionState&, bool shouldIgnoreNamespaceChecks = false);
+    PassRefPtr<Node> importNode(Node* importedNode, ExceptionState& ec) { return importNode(importedNode, true, ec); }
+    PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionState&);
+    PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionState&);
     PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser);
 
     bool cssStickyPositionEnabled() const;
@@ -372,8 +373,8 @@
     bool hasXMLDeclaration() const { return m_hasXMLDeclaration; }
 
     void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser
-    void setXMLVersion(const String&, ExceptionCode&);
-    void setXMLStandalone(bool, ExceptionCode&);
+    void setXMLVersion(const String&, ExceptionState&);
+    void setXMLStandalone(bool, ExceptionState&);
     void setHasXMLDeclaration(bool hasXMLDeclaration) { m_hasXMLDeclaration = hasXMLDeclaration ? 1 : 0; }
 
     String documentURI() const { return m_documentURI; }
@@ -386,7 +387,7 @@
 
     DOMSecurityPolicy* securityPolicy();
 
-    PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
+    PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionState&);
 
     PassRefPtr<HTMLCollection> images();
     PassRefPtr<HTMLCollection> embeds();
@@ -467,15 +468,15 @@
 
     PassRefPtr<Range> createRange();
 
-    PassRefPtr<NodeIterator> createNodeIterator(Node* root, ExceptionCode&);
-    PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow, ExceptionCode&);
-    PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, ExceptionCode&);
-    PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
+    PassRefPtr<NodeIterator> createNodeIterator(Node* root, ExceptionState&);
+    PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow, ExceptionState&);
+    PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, ExceptionState&);
+    PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionState&);
 
-    PassRefPtr<TreeWalker> createTreeWalker(Node* root, ExceptionCode&);
-    PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, ExceptionCode&);
-    PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, ExceptionCode&);
-    PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
+    PassRefPtr<TreeWalker> createTreeWalker(Node* root, ExceptionState&);
+    PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, ExceptionState&);
+    PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, ExceptionState&);
+    PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionState&);
 
     // Special support for editing
     PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration();
@@ -695,7 +696,7 @@
     EventListener* getWindowAttributeEventListener(const AtomicString& eventType, DOMWrapperWorld* isolatedWorld);
     void dispatchWindowEvent(PassRefPtr<Event>, PassRefPtr<EventTarget> = 0);
 
-    PassRefPtr<Event> createEvent(const String& eventType, ExceptionCode&);
+    PassRefPtr<Event> createEvent(const String& eventType, ExceptionState&);
 
     // keep track of what types of event listeners are registered, so we don't
     // dispatch events unnecessarily
@@ -757,13 +758,13 @@
     void setTitleElement(const StringWithDirection&, Element* titleElement);
     void removeTitle(Element* titleElement);
 
-    String cookie(ExceptionCode&) const;
-    void setCookie(const String&, ExceptionCode&);
+    String cookie(ExceptionState&) const;
+    void setCookie(const String&, ExceptionState&);
 
     String referrer() const;
 
     String domain() const;
-    void setDomain(const String& newDomain, ExceptionCode&);
+    void setDomain(const String& newDomain, ExceptionState&);
 
     String lastModified() const;
 
@@ -790,14 +791,14 @@
     // The following breaks a qualified name into a prefix and a local name.
     // It also does a validity check, and returns false if the qualified name
     // is invalid.  It also sets ExceptionCode when name is invalid.
-    static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode&);
+    static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionState&);
 
     // Checks to make sure prefix and namespace do not conflict (per DOM Core 3)
     static bool hasValidNamespaceForElements(const QualifiedName&);
     static bool hasValidNamespaceForAttributes(const QualifiedName&);
 
     HTMLElement* body() const;
-    void setBody(PassRefPtr<HTMLElement>, ExceptionCode&);
+    void setBody(PassRefPtr<HTMLElement>, ExceptionState&);
 
     HTMLHeadElement* head();
 
@@ -979,10 +980,10 @@
 
     TextAutosizer* textAutosizer() { return m_textAutosizer.get(); }
 
-    PassRefPtr<Element> createElement(const AtomicString& localName, const AtomicString& typeExtension, ExceptionCode&);
-    PassRefPtr<Element> createElementNS(const AtomicString& namespaceURI, const String& qualifiedName, const AtomicString& typeExtension, ExceptionCode&);
-    ScriptValue registerElement(WebCore::ScriptState*, const AtomicString& name, ExceptionCode&);
-    ScriptValue registerElement(WebCore::ScriptState*, const AtomicString& name, const Dictionary& options, ExceptionCode&);
+    PassRefPtr<Element> createElement(const AtomicString& localName, const AtomicString& typeExtension, ExceptionState&);
+    PassRefPtr<Element> createElementNS(const AtomicString& namespaceURI, const String& qualifiedName, const AtomicString& typeExtension, ExceptionState&);
+    ScriptValue registerElement(WebCore::ScriptState*, const AtomicString& name, ExceptionState&);
+    ScriptValue registerElement(WebCore::ScriptState*, const AtomicString& name, const Dictionary& options, ExceptionState&);
     CustomElementRegistrationContext* registrationContext() { return m_registrationContext.get(); }
 
     void setImport(HTMLImport*);
diff --git a/Source/core/dom/DocumentOrderedMap.cpp b/Source/core/dom/DocumentOrderedMap.cpp
index c5df110..76f236a 100644
--- a/Source/core/dom/DocumentOrderedMap.cpp
+++ b/Source/core/dom/DocumentOrderedMap.cpp
@@ -37,7 +37,6 @@
 #include "core/dom/TreeScope.h"
 #include "core/html/HTMLLabelElement.h"
 #include "core/html/HTMLMapElement.h"
-#include "core/html/HTMLNameCollection.h"
 
 namespace WebCore {
 
@@ -48,11 +47,6 @@
     return element->getIdAttribute().impl() == key;
 }
 
-inline bool keyMatchesName(StringImpl* key, Element* element)
-{
-    return element->getNameAttribute().impl() == key;
-}
-
 inline bool keyMatchesMapName(StringImpl* key, Element* element)
 {
     return element->hasTagName(mapTag) && toHTMLMapElement(element)->getName().impl() == key;
@@ -68,16 +62,6 @@
     return isHTMLLabelElement(element) && element->getAttribute(forAttr).impl() == key;
 }
 
-inline bool keyMatchesWindowNamedItem(StringImpl* key, Element* element)
-{
-    return WindowNameCollection::nodeMatches(element, key);
-}
-
-inline bool keyMatchesDocumentNamedItem(StringImpl* key, Element* element)
-{
-    return DocumentNameCollection::nodeMatches(element, key);
-}
-
 void DocumentOrderedMap::clear()
 {
     m_map.clear();
@@ -159,11 +143,6 @@
     return get<keyMatchesId>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByName(StringImpl* key, const TreeScope* scope) const
-{
-    return get<keyMatchesName>(key, scope);
-}
-
 Element* DocumentOrderedMap::getElementByMapName(StringImpl* key, const TreeScope* scope) const
 {
     return get<keyMatchesMapName>(key, scope);
@@ -179,14 +158,4 @@
     return get<keyMatchesLabelForAttribute>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByWindowNamedItem(StringImpl* key, const TreeScope* scope) const
-{
-    return get<keyMatchesWindowNamedItem>(key, scope);
-}
-
-Element* DocumentOrderedMap::getElementByDocumentNamedItem(StringImpl* key, const TreeScope* scope) const
-{
-    return get<keyMatchesDocumentNamedItem>(key, scope);
-}
-
 } // namespace WebCore
diff --git a/Source/core/dom/DocumentOrderedMap.h b/Source/core/dom/DocumentOrderedMap.h
index 762da72..b6fc8e0 100644
--- a/Source/core/dom/DocumentOrderedMap.h
+++ b/Source/core/dom/DocumentOrderedMap.h
@@ -47,15 +47,12 @@
     void clear();
 
     bool contains(StringImpl*) const;
-    bool mightContainMultiple(StringImpl*) const;
+    bool containsMultiple(StringImpl*) const;
     // concrete instantiations of the get<>() method template
     Element* getElementById(StringImpl*, const TreeScope*) const;
-    Element* getElementByName(StringImpl*, const TreeScope*) const;
     Element* getElementByMapName(StringImpl*, const TreeScope*) const;
     Element* getElementByLowercasedMapName(StringImpl*, const TreeScope*) const;
     Element* getElementByLabelForAttribute(StringImpl*, const TreeScope*) const;
-    Element* getElementByWindowNamedItem(StringImpl*, const TreeScope*) const;
-    Element* getElementByDocumentNamedItem(StringImpl*, const TreeScope*) const;
 
     void checkConsistency() const;
 
@@ -76,9 +73,9 @@
     return m_map.contains(id) || m_duplicateCounts.contains(id);
 }
 
-inline bool DocumentOrderedMap::mightContainMultiple(StringImpl* id) const
+inline bool DocumentOrderedMap::containsMultiple(StringImpl* id) const
 {
-    return (m_map.contains(id) ? 1 : 0) + m_duplicateCounts.count(id) > 1;
+    return m_duplicateCounts.contains(id);
 }
 
 } // namespace WebCore
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index c18dec2..8ba2fda 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -32,6 +32,7 @@
 #include "RuntimeEnabledFeatures.h"
 #include "SVGNames.h"
 #include "XMLNames.h"
+#include "bindings/v8/ExceptionState.h"
 #include "core/accessibility/AXObjectCache.h"
 #include "core/animation/DocumentTimeline.h"
 #include "core/css/CSSParser.h"
@@ -75,7 +76,6 @@
 #include "core/html/HTMLFormControlsCollection.h"
 #include "core/html/HTMLFrameOwnerElement.h"
 #include "core/html/HTMLLabelElement.h"
-#include "core/html/HTMLNameCollection.h"
 #include "core/html/HTMLOptionsCollection.h"
 #include "core/html/HTMLTableRowsCollection.h"
 #include "core/html/parser/HTMLParserIdioms.h"
@@ -826,10 +826,10 @@
     return getAttribute(QualifiedName(nullAtom, localName, namespaceURI));
 }
 
-void Element::setAttribute(const AtomicString& localName, const AtomicString& value, ExceptionCode& ec)
+void Element::setAttribute(const AtomicString& localName, const AtomicString& value, ExceptionState& es)
 {
     if (!Document::isValidName(localName)) {
-        ec = InvalidCharacterError;
+        es.throwDOMException(InvalidCharacterError);
         return;
     }
 
@@ -1164,11 +1164,11 @@
     return m_tagName.toString();
 }
 
-void Element::setPrefix(const AtomicString& prefix, ExceptionCode& ec)
+void Element::setPrefix(const AtomicString& prefix, ExceptionState& es)
 {
-    ec = 0;
-    checkSetPrefix(prefix, ec);
-    if (ec)
+    es.clearException();
+    checkSetPrefix(prefix, es);
+    if (es.hadException())
         return;
 
     m_tagName.setPrefix(prefix.isEmpty() ? AtomicString() : prefix);
@@ -1249,7 +1249,7 @@
 
     const AtomicString& nameValue = getNameAttribute();
     if (!nameValue.isNull())
-        updateName(scope, nullAtom, nameValue);
+        updateName(nullAtom, nameValue);
 
     if (hasTagName(labelTag)) {
         if (scope->shouldCacheLabelsByForAttribute())
@@ -1288,7 +1288,7 @@
 
         const AtomicString& nameValue = getNameAttribute();
         if (!nameValue.isNull())
-            updateName(insertionPoint->treeScope(), nameValue, nullAtom);
+            updateName(nameValue, nullAtom);
 
         if (hasTagName(labelTag)) {
             TreeScope* treeScope = insertionPoint->treeScope();
@@ -1502,7 +1502,7 @@
             change = Force;
         }
 
-        if (styleChangeType() == SubtreeStyleChange)
+        if (styleChangeType() >= SubtreeStyleChange)
             change = Force;
         else if (change != Force)
             change = localChange;
@@ -1542,7 +1542,7 @@
             if (forceCheckOfNextElementSibling || forceCheckOfAnyElementSibling)
                 element->setNeedsStyleRecalc();
 
-            bool childRulesChanged = element->needsStyleRecalc() && element->styleChangeType() == SubtreeStyleChange;
+            bool childRulesChanged = element->needsStyleRecalc() && element->styleChangeType() >= SubtreeStyleChange;
             forceCheckOfNextElementSibling = childRulesChanged && hasDirectAdjacentRules;
             forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (childRulesChanged && hasIndirectAdjacentRules);
 
@@ -1583,7 +1583,7 @@
         elementShadow->didAffectSelector(mask);
 }
 
-PassRefPtr<ShadowRoot> Element::createShadowRoot(ExceptionCode& ec)
+PassRefPtr<ShadowRoot> Element::createShadowRoot(ExceptionState& es)
 {
     if (alwaysCreateUserAgentShadowRoot())
         ensureUserAgentShadowRoot();
@@ -1595,7 +1595,7 @@
     // subtrees won't work well in that element. Until they are fixed, we disable
     // adding author shadow root for them.
     if (!areAuthorShadowsAllowed()) {
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
         return 0;
     }
     return ensureShadow()->addShadowRoot(this, ShadowRoot::AuthorShadowRoot);
@@ -1671,7 +1671,7 @@
 static void checkForSiblingStyleChanges(Element* e, RenderStyle* style, bool finishedParsingCallback,
                                         Node* beforeChange, Node* afterChange, int childCountDelta)
 {
-    if (!e->attached() || e->document()->hasPendingForcedStyleRecalc() || e->styleChangeType() == SubtreeStyleChange)
+    if (!e->attached() || e->document()->hasPendingForcedStyleRecalc() || e->styleChangeType() >= SubtreeStyleChange)
         return;
 
     // :empty selector.
@@ -1811,10 +1811,10 @@
     return *attrNodeListForElement(this);
 }
 
-PassRefPtr<Attr> Element::setAttributeNode(Attr* attrNode, ExceptionCode& ec)
+PassRefPtr<Attr> Element::setAttributeNode(Attr* attrNode, ExceptionState& es)
 {
     if (!attrNode) {
-        ec = TypeMismatchError;
+        es.throwDOMException(TypeMismatchError);
         return 0;
     }
 
@@ -1825,7 +1825,7 @@
     // InUseAttributeError: Raised if node is an Attr that is already an attribute of another Element object.
     // The DOM user must explicitly clone Attr nodes to re-use them in other elements.
     if (attrNode->ownerElement()) {
-        ec = InUseAttributeError;
+        es.throwDOMException(InUseAttributeError);
         return 0;
     }
 
@@ -1849,19 +1849,19 @@
     return oldAttrNode.release();
 }
 
-PassRefPtr<Attr> Element::setAttributeNodeNS(Attr* attr, ExceptionCode& ec)
+PassRefPtr<Attr> Element::setAttributeNodeNS(Attr* attr, ExceptionState& es)
 {
-    return setAttributeNode(attr, ec);
+    return setAttributeNode(attr, es);
 }
 
-PassRefPtr<Attr> Element::removeAttributeNode(Attr* attr, ExceptionCode& ec)
+PassRefPtr<Attr> Element::removeAttributeNode(Attr* attr, ExceptionState& es)
 {
     if (!attr) {
-        ec = TypeMismatchError;
+        es.throwDOMException(TypeMismatchError);
         return 0;
     }
     if (attr->ownerElement() != this) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return 0;
     }
 
@@ -1871,7 +1871,7 @@
 
     size_t index = elementData()->getAttrIndex(attr);
     if (index == notFound) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return 0;
     }
 
@@ -1880,17 +1880,17 @@
     return guard.release();
 }
 
-bool Element::parseAttributeName(QualifiedName& out, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionCode& ec)
+bool Element::parseAttributeName(QualifiedName& out, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionState& es)
 {
     String prefix, localName;
-    if (!Document::parseQualifiedName(qualifiedName, prefix, localName, ec))
+    if (!Document::parseQualifiedName(qualifiedName, prefix, localName, es))
         return false;
-    ASSERT(!ec);
+    ASSERT(!es.hadException());
 
     QualifiedName qName(prefix, localName, namespaceURI);
 
     if (!Document::hasValidNamespaceForAttributes(qName)) {
-        ec = NamespaceError;
+        es.throwDOMException(NamespaceError);
         return false;
     }
 
@@ -1898,10 +1898,10 @@
     return true;
 }
 
-void Element::setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode& ec)
+void Element::setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionState& es)
 {
     QualifiedName parsedName = anyName;
-    if (!parseAttributeName(parsedName, namespaceURI, qualifiedName, ec))
+    if (!parseAttributeName(parsedName, namespaceURI, qualifiedName, es))
         return;
     setAttribute(parsedName, value);
 }
@@ -2076,6 +2076,11 @@
     }
 }
 
+bool Element::isFocusable() const
+{
+    return inDocument() && supportsFocus() && !isInert() && rendererIsFocusable();
+}
+
 bool Element::isKeyboardFocusable() const
 {
     return isFocusable() && tabIndex() >= 0;
@@ -2497,14 +2502,14 @@
     return 0;
 }
 
-bool Element::webkitMatchesSelector(const String& selector, ExceptionCode& ec)
+bool Element::webkitMatchesSelector(const String& selector, ExceptionState& es)
 {
     if (selector.isEmpty()) {
-        ec = SyntaxError;
+        es.throwDOMException(SyntaxError);
         return false;
     }
 
-    SelectorQuery* selectorQuery = document()->selectorQueryCache()->add(selector, document(), ec);
+    SelectorQuery* selectorQuery = document()->selectorQueryCache()->add(selector, document(), es);
     if (!selectorQuery)
         return false;
     return selectorQuery->matches(this);
@@ -2756,48 +2761,17 @@
 
 inline void Element::updateName(const AtomicString& oldName, const AtomicString& newName)
 {
-    if (!isInTreeScope())
+    if (!inDocument() || isInShadowTree())
         return;
 
     if (oldName == newName)
         return;
 
-    updateName(treeScope(), oldName, newName);
+    if (shouldRegisterAsNamedItem())
+        updateNamedItemRegistration(oldName, newName);
 }
 
-void Element::updateName(TreeScope* scope, const AtomicString& oldName, const AtomicString& newName)
-{
-    ASSERT(isInTreeScope());
-    ASSERT(oldName != newName);
-
-    if (!oldName.isEmpty())
-        scope->removeElementByName(oldName, this);
-    if (!newName.isEmpty())
-        scope->addElementByName(newName, this);
-
-    if (!inDocument() || isInShadowTree())
-        return;
-
-    Document* ownerDocument = document();
-    if (!ownerDocument->isHTMLDocument())
-        return;
-
-    if (WindowNameCollection::nodeMatchesIfNameAttributeMatch(this)) {
-        if (!oldName.isEmpty())
-            toHTMLDocument(ownerDocument)->windowNamedItemMap().remove(oldName.impl(), this);
-        if (!newName.isEmpty())
-            toHTMLDocument(ownerDocument)->windowNamedItemMap().add(newName.impl(), this);
-    }
-
-    if (DocumentNameCollection::nodeMatchesIfNameAttributeMatch(this)) {
-        if (!oldName.isEmpty())
-            toHTMLDocument(ownerDocument)->removeNamedDocumentItem(oldName, this);
-        if (!newName.isEmpty())
-            toHTMLDocument(ownerDocument)->addNamedDocumentItem(newName, this);
-    }
-}
-
-void Element::updateId(const AtomicString& oldId, const AtomicString& newId)
+inline void Element::updateId(const AtomicString& oldId, const AtomicString& newId)
 {
     if (!isInTreeScope())
         return;
@@ -2818,26 +2792,8 @@
     if (!newId.isEmpty())
         scope->addElementById(newId, this);
 
-    if (!inDocument() || isInShadowTree())
-        return;
-
-    Document* ownerDocument = document();
-    if (!ownerDocument->isHTMLDocument())
-        return;
-
-    if (WindowNameCollection::nodeMatchesIfIdAttributeMatch(this)) {
-        if (!oldId.isEmpty())
-            toHTMLDocument(ownerDocument)->windowNamedItemMap().remove(oldId.impl(), this);
-        if (!newId.isEmpty())
-            toHTMLDocument(ownerDocument)->windowNamedItemMap().add(newId.impl(), this);
-    }
-
-    if (DocumentNameCollection::nodeMatchesIfIdAttributeMatch(this)) {
-        if (!oldId.isEmpty())
-            toHTMLDocument(ownerDocument)->removeNamedDocumentItem(oldId, this);
-        if (!newId.isEmpty())
-            toHTMLDocument(ownerDocument)->addNamedDocumentItem(newId, this);
-    }
+    if (shouldRegisterAsExtraNamedItem())
+        updateExtraNamedItemRegistration(oldId, newId);
 }
 
 void Element::updateLabel(TreeScope* scope, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue)
@@ -2923,6 +2879,30 @@
     }
 }
 
+void Element::updateNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName)
+{
+    if (!document()->isHTMLDocument())
+        return;
+
+    if (!oldName.isEmpty())
+        toHTMLDocument(document())->removeNamedItem(oldName);
+
+    if (!newName.isEmpty())
+        toHTMLDocument(document())->addNamedItem(newName);
+}
+
+void Element::updateExtraNamedItemRegistration(const AtomicString& oldId, const AtomicString& newId)
+{
+    if (!document()->isHTMLDocument())
+        return;
+
+    if (!oldId.isEmpty())
+        toHTMLDocument(document())->removeExtraNamedItem(oldId);
+
+    if (!newId.isEmpty())
+        toHTMLDocument(document())->addExtraNamedItem(newId);
+}
+
 PassRefPtr<HTMLCollection> Element::ensureCachedHTMLCollection(CollectionType type)
 {
     if (HTMLCollection* collection = cachedHTMLCollection(type))
diff --git a/Source/core/dom/Element.h b/Source/core/dom/Element.h
index 31ced21..dd7d113 100644
--- a/Source/core/dom/Element.h
+++ b/Source/core/dom/Element.h
@@ -48,6 +48,7 @@
 class Element;
 class ElementRareData;
 class ElementShadow;
+class ExceptionState;
 class Image;
 class InputMethodContext;
 class IntSize;
@@ -274,9 +275,9 @@
     const AtomicString& getAttribute(const AtomicString& name) const;
     const AtomicString& getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
 
-    void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionCode&);
-    static bool parseAttributeName(QualifiedName&, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionCode&);
-    void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode&);
+    void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionState&);
+    static bool parseAttributeName(QualifiedName&, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionState&);
+    void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionState&);
 
     bool isIdAttributeName(const QualifiedName&) const;
     const AtomicString& getIdAttribute() const;
@@ -342,9 +343,9 @@
 
     PassRefPtr<Attr> getAttributeNode(const AtomicString& name);
     PassRefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
-    PassRefPtr<Attr> setAttributeNode(Attr*, ExceptionCode&);
-    PassRefPtr<Attr> setAttributeNodeNS(Attr*, ExceptionCode&);
-    PassRefPtr<Attr> removeAttributeNode(Attr*, ExceptionCode&);
+    PassRefPtr<Attr> setAttributeNode(Attr*, ExceptionState&);
+    PassRefPtr<Attr> setAttributeNodeNS(Attr*, ExceptionState&);
+    PassRefPtr<Attr> removeAttributeNode(Attr*, ExceptionState&);
 
     PassRefPtr<Attr> attrIfExists(const QualifiedName&);
     PassRefPtr<Attr> ensureAttr(const QualifiedName&);
@@ -438,7 +439,7 @@
 
     ElementShadow* shadow() const;
     ElementShadow* ensureShadow();
-    PassRefPtr<ShadowRoot> createShadowRoot(ExceptionCode&);
+    PassRefPtr<ShadowRoot> createShadowRoot(ExceptionState&);
     ShadowRoot* shadowRoot() const;
 
     bool hasAuthorShadowRoot() const { return shadowRoot(); }
@@ -507,6 +508,8 @@
     virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
     virtual void updateFocusAppearance(bool restorePreviousSelection);
     virtual void blur();
+    // Whether the node can actually be focused.
+    bool isFocusable() const;
     virtual bool isKeyboardFocusable() const;
     virtual bool isMouseFocusable() const;
     virtual void dispatchFocusEvent(Element* oldFocusedElement, FocusDirection);
@@ -542,7 +545,7 @@
 
     virtual bool matchesReadOnlyPseudoClass() const { return false; }
     virtual bool matchesReadWritePseudoClass() const { return false; }
-    bool webkitMatchesSelector(const String& selectors, ExceptionCode&);
+    bool webkitMatchesSelector(const String& selectors, ExceptionState&);
     virtual bool shouldAppearIndeterminate() const { return false; }
 
     DOMTokenList* classList();
@@ -663,6 +666,9 @@
     virtual void didRecalcStyle(StyleChange);
     virtual PassRefPtr<RenderStyle> customStyleForRenderer();
 
+    virtual bool shouldRegisterAsNamedItem() const { return false; }
+    virtual bool shouldRegisterAsExtraNamedItem() const { return false; }
+
     void clearTabIndexExplicitlyIfNeeded();
     void setTabIndexExplicitly(short);
     virtual bool supportsFocus() const OVERRIDE;
@@ -711,12 +717,11 @@
     void updateId(const AtomicString& oldId, const AtomicString& newId);
     void updateId(TreeScope*, const AtomicString& oldId, const AtomicString& newId);
     void updateName(const AtomicString& oldName, const AtomicString& newName);
-    void updateName(TreeScope*, const AtomicString& oldName, const AtomicString& newName);
     void updateLabel(TreeScope*, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
 
     void scrollByUnits(int units, ScrollGranularity);
 
-    virtual void setPrefix(const AtomicString&, ExceptionCode&) OVERRIDE FINAL;
+    virtual void setPrefix(const AtomicString&, ExceptionState&) OVERRIDE FINAL;
     virtual NodeType nodeType() const OVERRIDE FINAL;
     virtual bool childTypeAllowed(NodeType) const OVERRIDE FINAL;
 
@@ -754,6 +759,9 @@
 
     SpellcheckAttributeState spellcheckAttributeState() const;
 
+    void updateNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
+    void updateExtraNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
+
     void unregisterNamedFlowContentNode();
 
     void createUniqueElementData();
diff --git a/Source/core/dom/EventTarget.cpp b/Source/core/dom/EventTarget.cpp
index 522f44c..8facd5a 100644
--- a/Source/core/dom/EventTarget.cpp
+++ b/Source/core/dom/EventTarget.cpp
@@ -33,6 +33,7 @@
 #include "core/dom/EventTarget.h"
 
 #include "bindings/v8/DOMWrapperWorld.h"
+#include "bindings/v8/ExceptionState.h"
 #include "bindings/v8/ScriptController.h"
 #include "core/dom/Event.h"
 #include "core/dom/ExceptionCode.h"
@@ -140,10 +141,10 @@
     return removeEventListener(eventType, listener, false);
 }
 
-bool EventTarget::dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec)
+bool EventTarget::dispatchEvent(PassRefPtr<Event> event, ExceptionState& es)
 {
     if (!event || event->type().isEmpty() || event->isBeingDispatched()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return false;
     }
 
diff --git a/Source/core/dom/EventTarget.h b/Source/core/dom/EventTarget.h
index a0c3a0e..5e95e0f 100644
--- a/Source/core/dom/EventTarget.h
+++ b/Source/core/dom/EventTarget.h
@@ -39,12 +39,13 @@
 namespace WebCore {
 
     class AudioContext;
-    class DedicatedWorkerGlobalScope;
     class DOMApplicationCache;
     class DOMWindow;
+    class DedicatedWorkerGlobalScope;
     class Event;
     class EventListener;
     class EventSource;
+    class ExceptionState;
     class FileReader;
     class FileWriter;
     class IDBDatabase;
@@ -71,8 +72,6 @@
     class XMLHttpRequest;
     class XMLHttpRequestUpload;
 
-    typedef int ExceptionCode;
-
     struct FiringEventIterator {
         FiringEventIterator(const AtomicString& eventType, size_t& iterator, size_t& end)
             : eventType(eventType)
@@ -112,7 +111,7 @@
         virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
         virtual void removeAllEventListeners();
         virtual bool dispatchEvent(PassRefPtr<Event>);
-        bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); // DOM API
+        bool dispatchEvent(PassRefPtr<Event>, ExceptionState&); // DOM API
         virtual void uncaughtExceptionInEventHandler();
 
         // Used for legacy "onEvent" attribute APIs.
diff --git a/Source/core/dom/MessagePort.cpp b/Source/core/dom/MessagePort.cpp
index be7ab66..efdb7ce 100644
--- a/Source/core/dom/MessagePort.cpp
+++ b/Source/core/dom/MessagePort.cpp
@@ -28,6 +28,7 @@
 #include "core/dom/MessagePort.h"
 
 #include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "core/dom/Document.h"
 #include "core/dom/EventNames.h"
 #include "core/dom/ExceptionCode.h"
@@ -169,7 +170,7 @@
         OwnPtr<MessagePortArray> ports = MessagePort::entanglePorts(*m_scriptExecutionContext, channels.release());
         RefPtr<Event> evt = MessageEvent::create(ports.release(), message.release());
 
-        dispatchEvent(evt.release(), ASSERT_NO_EXCEPTION);
+        dispatchEvent(evt.release(), ASSERT_NO_EXCEPTION_STATE);
     }
 }
 
diff --git a/Source/core/dom/MutationObserver.cpp b/Source/core/dom/MutationObserver.cpp
index a2e4084..e2d5fec 100644
--- a/Source/core/dom/MutationObserver.cpp
+++ b/Source/core/dom/MutationObserver.cpp
@@ -29,11 +29,11 @@
  */
 
 #include "config.h"
-
 #include "core/dom/MutationObserver.h"
 
 #include <algorithm>
 #include "bindings/v8/Dictionary.h"
+#include "bindings/v8/ExceptionState.h"
 #include "core/dom/Document.h"
 #include "core/dom/ExceptionCode.h"
 #include "core/dom/MutationCallback.h"
@@ -81,10 +81,10 @@
         && ((options & CharacterData) || !(options & CharacterDataOldValue));
 }
 
-void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary, ExceptionCode& ec)
+void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary, ExceptionState& es)
 {
     if (!node) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -111,7 +111,7 @@
         options |= AttributeFilter;
 
     if (!validateOptions(options)) {
-        ec = SyntaxError;
+        es.throwDOMException(SyntaxError);
         return;
     }
 
diff --git a/Source/core/dom/MutationObserver.h b/Source/core/dom/MutationObserver.h
index 2a78bbf..3f2941d 100644
--- a/Source/core/dom/MutationObserver.h
+++ b/Source/core/dom/MutationObserver.h
@@ -41,13 +41,12 @@
 namespace WebCore {
 
 class Dictionary;
+class ExceptionState;
 class MutationCallback;
 class MutationObserverRegistration;
 class MutationRecord;
 class Node;
 
-typedef int ExceptionCode;
-
 typedef unsigned char MutationObserverOptions;
 typedef unsigned char MutationRecordDeliveryOptions;
 
@@ -76,7 +75,7 @@
 
     ~MutationObserver();
 
-    void observe(Node*, const Dictionary&, ExceptionCode&);
+    void observe(Node*, const Dictionary&, ExceptionState&);
     Vector<RefPtr<MutationRecord> > takeRecords();
     void disconnect();
     void observationStarted(MutationObserverRegistration*);
diff --git a/Source/core/dom/NamedNodeMap.cpp b/Source/core/dom/NamedNodeMap.cpp
index 0f93b6d..b24e12d 100644
--- a/Source/core/dom/NamedNodeMap.cpp
+++ b/Source/core/dom/NamedNodeMap.cpp
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "core/dom/NamedNodeMap.h"
 
+#include "bindings/v8/ExceptionState.h"
 #include "core/dom/Attr.h"
 #include "core/dom/Document.h"
 #include "core/dom/Element.h"
@@ -59,45 +60,45 @@
     return m_element->getAttributeNodeNS(namespaceURI, localName);
 }
 
-PassRefPtr<Node> NamedNodeMap::removeNamedItem(const AtomicString& name, ExceptionCode& ec)
+PassRefPtr<Node> NamedNodeMap::removeNamedItem(const AtomicString& name, ExceptionState& es)
 {
     size_t index = m_element->hasAttributes() ? m_element->getAttributeItemIndex(name, shouldIgnoreAttributeCase(m_element)) : notFound;
     if (index == notFound) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return 0;
     }
     return m_element->detachAttribute(index);
 }
 
-PassRefPtr<Node> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionCode& ec)
+PassRefPtr<Node> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionState& es)
 {
     size_t index = m_element->hasAttributes() ? m_element->getAttributeItemIndex(QualifiedName(nullAtom, localName, namespaceURI)) : notFound;
     if (index == notFound) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return 0;
     }
     return m_element->detachAttribute(index);
 }
 
-PassRefPtr<Node> NamedNodeMap::setNamedItem(Node* node, ExceptionCode& ec)
+PassRefPtr<Node> NamedNodeMap::setNamedItem(Node* node, ExceptionState& es)
 {
     if (!node) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return 0;
     }
 
     // Not mentioned in spec: throw a HIERARCHY_REQUEST_ERROR if the user passes in a non-attribute node
     if (!node->isAttributeNode()) {
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
         return 0;
     }
 
-    return m_element->setAttributeNode(toAttr(node), ec);
+    return m_element->setAttributeNode(toAttr(node), es);
 }
 
-PassRefPtr<Node> NamedNodeMap::setNamedItemNS(Node* node, ExceptionCode& ec)
+PassRefPtr<Node> NamedNodeMap::setNamedItemNS(Node* node, ExceptionState& es)
 {
-    return setNamedItem(node, ec);
+    return setNamedItem(node, es);
 }
 
 PassRefPtr<Node> NamedNodeMap::item(unsigned index) const
diff --git a/Source/core/dom/NamedNodeMap.h b/Source/core/dom/NamedNodeMap.h
index cbb12b4..f01102c 100644
--- a/Source/core/dom/NamedNodeMap.h
+++ b/Source/core/dom/NamedNodeMap.h
@@ -34,8 +34,7 @@
 
 class Node;
 class Element;
-
-typedef int ExceptionCode;
+class ExceptionState;
 
 class NamedNodeMap : public ScriptWrappable {
     WTF_MAKE_FAST_ALLOCATED;
@@ -52,13 +51,13 @@
     // Public DOM interface.
 
     PassRefPtr<Node> getNamedItem(const AtomicString&) const;
-    PassRefPtr<Node> removeNamedItem(const AtomicString& name, ExceptionCode&);
+    PassRefPtr<Node> removeNamedItem(const AtomicString& name, ExceptionState&);
 
     PassRefPtr<Node> getNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
-    PassRefPtr<Node> removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionCode&);
+    PassRefPtr<Node> removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionState&);
 
-    PassRefPtr<Node> setNamedItem(Node*, ExceptionCode&);
-    PassRefPtr<Node> setNamedItemNS(Node*, ExceptionCode&);
+    PassRefPtr<Node> setNamedItem(Node*, ExceptionState&);
+    PassRefPtr<Node> setNamedItemNS(Node*, ExceptionState&);
 
     PassRefPtr<Node> item(unsigned index) const;
     size_t length() const;
diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp
index edd958d..6b64f8a 100644
--- a/Source/core/dom/Node.cpp
+++ b/Source/core/dom/Node.cpp
@@ -27,6 +27,8 @@
 
 #include "HTMLNames.h"
 #include "XMLNames.h"
+#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "core/accessibility/AXObjectCache.h"
 #include "core/dom/Attr.h"
 #include "core/dom/Attribute.h"
@@ -46,7 +48,6 @@
 #include "core/dom/EventListener.h"
 #include "core/dom/EventNames.h"
 #include "core/dom/ExceptionCode.h"
-#include "core/dom/ExceptionCodePlaceholder.h"
 #include "core/dom/GestureEvent.h"
 #include "core/dom/KeyboardEvent.h"
 #include "core/dom/LiveNodeList.h"
@@ -510,42 +511,42 @@
     return lastChild();
 }
 
-void Node::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& ec, AttachBehavior attachBehavior)
+void Node::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionState& es, AttachBehavior attachBehavior)
 {
     if (isContainerNode())
-        toContainerNode(this)->insertBefore(newChild, refChild, ec, attachBehavior);
+        toContainerNode(this)->insertBefore(newChild, refChild, es, attachBehavior);
     else
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
 }
 
-void Node::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode& ec, AttachBehavior attachBehavior)
+void Node::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionState& es, AttachBehavior attachBehavior)
 {
     if (isContainerNode())
-        toContainerNode(this)->replaceChild(newChild, oldChild, ec, attachBehavior);
+        toContainerNode(this)->replaceChild(newChild, oldChild, es, attachBehavior);
     else
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
 }
 
-void Node::removeChild(Node* oldChild, ExceptionCode& ec)
+void Node::removeChild(Node* oldChild, ExceptionState& es)
 {
     if (isContainerNode())
-        toContainerNode(this)->removeChild(oldChild, ec);
+        toContainerNode(this)->removeChild(oldChild, es);
     else
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
 }
 
-void Node::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, AttachBehavior attachBehavior)
+void Node::appendChild(PassRefPtr<Node> newChild, ExceptionState& es, AttachBehavior attachBehavior)
 {
     if (isContainerNode())
-        toContainerNode(this)->appendChild(newChild, ec, attachBehavior);
+        toContainerNode(this)->appendChild(newChild, es, attachBehavior);
     else
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
 }
 
-void Node::remove(ExceptionCode& ec)
+void Node::remove(ExceptionState& es)
 {
     if (ContainerNode* parent = parentNode())
-        parent->removeChild(this, ec);
+        parent->removeChild(this, es);
 }
 
 void Node::normalize()
@@ -575,7 +576,7 @@
         if (!text->length()) {
             // Care must be taken to get the next node before removing the current node.
             node = NodeTraversal::nextPostOrder(node.get());
-            text->remove(IGNORE_EXCEPTION);
+            text->remove(IGNORE_EXCEPTION_STATE);
             continue;
         }
 
@@ -587,7 +588,7 @@
 
             // Remove empty text nodes.
             if (!nextText->length()) {
-                nextText->remove(IGNORE_EXCEPTION);
+                nextText->remove(IGNORE_EXCEPTION_STATE);
                 continue;
             }
 
@@ -595,7 +596,7 @@
             unsigned offset = text->length();
             text->appendData(nextText->data());
             document()->textNodesMerged(nextText.get(), offset);
-            nextText->remove(IGNORE_EXCEPTION);
+            nextText->remove(IGNORE_EXCEPTION_STATE);
         }
 
         node = NodeTraversal::nextPostOrder(node.get());
@@ -608,12 +609,12 @@
     return nullAtom;
 }
 
-void Node::setPrefix(const AtomicString& /*prefix*/, ExceptionCode& ec)
+void Node::setPrefix(const AtomicString& /*prefix*/, ExceptionState& es)
 {
     // The spec says that for nodes other than elements and attributes, prefix is always null.
     // It does not say what to do when the user tries to set the prefix on another type of
     // node, however Mozilla throws a NamespaceError exception.
-    ec = NamespaceError;
+    es.throwDOMException(NamespaceError);
 }
 
 const AtomicString& Node::localName() const
@@ -846,7 +847,7 @@
     }
     markAncestorsWithChildNeedsStyleRecalc();
     for (Node* node = this; node; node = NodeTraversal::next(node, this)) {
-        node->setStyleChange(SubtreeStyleChange);
+        node->setStyleChange(LazyAttachStyleChange);
         node->setChildNeedsStyleRecalc();
         // FIXME: This flag is only used by HTMLFrameElementBase and doesn't look needed.
         if (shouldSetAttached == SetAttached)
@@ -863,15 +864,6 @@
     return false;
 }
 
-bool Node::isFocusable() const
-{
-    if (!inDocument() || !supportsFocus())
-        return false;
-    if (isElementNode() && toElement(this)->isInert())
-        return false;
-    return rendererIsFocusable();
-}
-
 Node* Node::focusDelegate()
 {
     return this;
@@ -961,13 +953,13 @@
     rareData()->clearNodeLists();
 }
 
-void Node::checkSetPrefix(const AtomicString& prefix, ExceptionCode& ec)
+void Node::checkSetPrefix(const AtomicString& prefix, ExceptionState& es)
 {
     // Perform error checking as required by spec for setting Node.prefix. Used by
     // Element::setPrefix() and Attr::setPrefix()
 
     if (!prefix.isEmpty() && !Document::isValidName(prefix)) {
-        ec = InvalidCharacterError;
+        es.throwDOMException(InvalidCharacterError);
         return;
     }
 
@@ -976,7 +968,7 @@
     const AtomicString& nodeNamespaceURI = namespaceURI();
     if ((nodeNamespaceURI.isEmpty() && !prefix.isEmpty())
         || (prefix == xmlAtom && nodeNamespaceURI != XMLNames::xmlNamespaceURI)) {
-        ec = NamespaceError;
+        es.throwDOMException(NamespaceError);
         return;
     }
     // Attribute-specific checks are in Attr::setPrefix().
@@ -1368,27 +1360,27 @@
     return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<RadioNodeList>(this, RadioNodeListType, name);
 }
 
-PassRefPtr<Element> Node::querySelector(const AtomicString& selectors, ExceptionCode& ec)
+PassRefPtr<Element> Node::querySelector(const AtomicString& selectors, ExceptionState& es)
 {
     if (selectors.isEmpty()) {
-        ec = SyntaxError;
+        es.throwDOMException(SyntaxError);
         return 0;
     }
 
-    SelectorQuery* selectorQuery = document()->selectorQueryCache()->add(selectors, document(), ec);
+    SelectorQuery* selectorQuery = document()->selectorQueryCache()->add(selectors, document(), es);
     if (!selectorQuery)
         return 0;
     return selectorQuery->queryFirst(this);
 }
 
-PassRefPtr<NodeList> Node::querySelectorAll(const AtomicString& selectors, ExceptionCode& ec)
+PassRefPtr<NodeList> Node::querySelectorAll(const AtomicString& selectors, ExceptionState& es)
 {
     if (selectors.isEmpty()) {
-        ec = SyntaxError;
+        es.throwDOMException(SyntaxError);
         return 0;
     }
 
-    SelectorQuery* selectorQuery = document()->selectorQueryCache()->add(selectors, document(), ec);
+    SelectorQuery* selectorQuery = document()->selectorQueryCache()->add(selectors, document(), es);
     if (!selectorQuery)
         return 0;
     return selectorQuery->queryAll(this);
@@ -1679,7 +1671,7 @@
     return isNullString ? String() : content.toString();
 }
 
-void Node::setTextContent(const String& text, ExceptionCode& ec)
+void Node::setTextContent(const String& text, ExceptionState& es)
 {
     switch (nodeType()) {
         case TEXT_NODE:
@@ -1696,7 +1688,7 @@
             ChildListMutationScope mutation(this);
             container->removeChildren();
             if (!text.isEmpty())
-                container->appendChild(document()->createTextNode(text), ec, AttachLazily);
+                container->appendChild(document()->createTextNode(text), es, AttachLazily);
             return;
         }
         case DOCUMENT_NODE:
@@ -2591,7 +2583,7 @@
 void Node::textRects(Vector<IntRect>& rects) const
 {
     RefPtr<Range> range = Range::create(document());
-    range->selectNodeContents(const_cast<Node*>(this), IGNORE_EXCEPTION);
+    range->selectNodeContents(const_cast<Node*>(this), IGNORE_EXCEPTION_STATE);
     range->textRects(rects);
 }
 
diff --git a/Source/core/dom/Node.h b/Source/core/dom/Node.h
index 2a11ef9..1a6287f 100644
--- a/Source/core/dom/Node.h
+++ b/Source/core/dom/Node.h
@@ -55,6 +55,7 @@
 class EventContext;
 class EventDispatchMediator;
 class EventListener;
+class ExceptionState;
 class FloatPoint;
 class Frame;
 class HTMLInputElement;
@@ -82,14 +83,13 @@
 class TagNodeList;
 class TouchEvent;
 
-typedef int ExceptionCode;
-
 const int nodeStyleChangeShift = 14;
 
 enum StyleChangeType {
     NoStyleChange = 0,
     LocalStyleChange = 1 << nodeStyleChangeShift,
     SubtreeStyleChange = 2 << nodeStyleChangeShift,
+    LazyAttachStyleChange = 3 << nodeStyleChangeShift,
 };
 
 // If the style change is from the renderer then we'll call setStyle on the
@@ -192,7 +192,7 @@
     // ChildNode interface API
     Element* previousElementSibling() const;
     Element* nextElementSibling() const;
-    void remove(ExceptionCode&);
+    void remove(ExceptionState&);
 
     Node* pseudoAwareNextSibling() const;
     Node* pseudoAwarePreviousSibling() const;
@@ -204,17 +204,17 @@
     // These should all actually return a node, but this is only important for language bindings,
     // which will already know and hold a ref on the right node to return. Returning bool allows
     // these methods to be more efficient since they don't need to return a ref
-    void insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, AttachBehavior = AttachNow);
-    void replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, AttachBehavior = AttachNow);
-    void removeChild(Node* child, ExceptionCode&);
-    void appendChild(PassRefPtr<Node> newChild, ExceptionCode&, AttachBehavior = AttachNow);
+    void insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionState&, AttachBehavior = AttachNow);
+    void replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionState&, AttachBehavior = AttachNow);
+    void removeChild(Node* child, ExceptionState&);
+    void appendChild(PassRefPtr<Node> newChild, ExceptionState&, AttachBehavior = AttachNow);
 
     bool hasChildNodes() const { return firstChild(); }
     virtual PassRefPtr<Node> cloneNode(bool deep = true) = 0;
     virtual const AtomicString& localName() const;
     virtual const AtomicString& namespaceURI() const;
     virtual const AtomicString& prefix() const;
-    virtual void setPrefix(const AtomicString&, ExceptionCode&);
+    virtual void setPrefix(const AtomicString&, ExceptionState&);
     void normalize();
 
     bool isSameNode(Node* other) const { return this == other; }
@@ -225,7 +225,7 @@
     String lookupNamespacePrefix(const AtomicString& namespaceURI, const Element* originalElement) const;
 
     String textContent(bool convertBRsToNewlines = false) const;
-    void setTextContent(const String&, ExceptionCode&);
+    void setTextContent(const String&, ExceptionState&);
 
     Node* lastDescendant() const;
     Node* firstDescendant() const;
@@ -434,8 +434,6 @@
     // rendererIsFocusable(), this method may be called when layout is not up to
     // date, so it must not use the renderer to determine focusability.
     virtual bool supportsFocus() const;
-    // Whether the node can actually be focused.
-    bool isFocusable() const;
     virtual Node* focusDelegate();
     // This is called only when the node is focused.
     virtual bool shouldHaveFocusAppearance() const;
@@ -516,7 +514,7 @@
     unsigned childNodeCount() const;
     Node* childNode(unsigned index) const;
 
-    void checkSetPrefix(const AtomicString& prefix, ExceptionCode&);
+    void checkSetPrefix(const AtomicString& prefix, ExceptionState&);
     bool isDescendantOf(const Node*) const;
     bool contains(const Node*) const;
     bool containsIncludingShadowDOM(const Node*) const;
@@ -641,8 +639,8 @@
     virtual bool willRespondToMouseClickEvents();
     virtual bool willRespondToTouchEvents();
 
-    PassRefPtr<Element> querySelector(const AtomicString& selectors, ExceptionCode&);
-    PassRefPtr<NodeList> querySelectorAll(const AtomicString& selectors, ExceptionCode&);
+    PassRefPtr<Element> querySelector(const AtomicString& selectors, ExceptionState&);
+    PassRefPtr<NodeList> querySelectorAll(const AtomicString& selectors, ExceptionState&);
 
     unsigned short compareDocumentPosition(const Node*) const;
 
@@ -928,6 +926,9 @@
 
 inline void Node::lazyReattach(ShouldSetAttached shouldSetAttached)
 {
+    if (styleChangeType() == LazyAttachStyleChange)
+        return;
+
     AttachContext context;
     context.performingReattach = true;
 
diff --git a/Source/core/dom/NodeIterator.cpp b/Source/core/dom/NodeIterator.cpp
index bcd2bfe..6bb4d9f 100644
--- a/Source/core/dom/NodeIterator.cpp
+++ b/Source/core/dom/NodeIterator.cpp
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "core/dom/NodeIterator.h"
 
+#include "bindings/v8/ExceptionState.h"
 #include "bindings/v8/ScriptState.h"
 #include "core/dom/Document.h"
 #include "core/dom/ExceptionCode.h"
@@ -90,10 +91,10 @@
         ownerDocument->detachNodeIterator(this);
 }
 
-PassRefPtr<Node> NodeIterator::nextNode(ScriptState* state, ExceptionCode& ec)
+PassRefPtr<Node> NodeIterator::nextNode(ScriptState* state, ExceptionState& es)
 {
     if (m_detached) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
@@ -119,10 +120,10 @@
     return result.release();
 }
 
-PassRefPtr<Node> NodeIterator::previousNode(ScriptState* state, ExceptionCode& ec)
+PassRefPtr<Node> NodeIterator::previousNode(ScriptState* state, ExceptionState& es)
 {
     if (m_detached) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
diff --git a/Source/core/dom/NodeIterator.h b/Source/core/dom/NodeIterator.h
index 5aafc13..4c504bf 100644
--- a/Source/core/dom/NodeIterator.h
+++ b/Source/core/dom/NodeIterator.h
@@ -33,46 +33,46 @@
 
 namespace WebCore {
 
-    typedef int ExceptionCode;
+class ExceptionState;
 
-    class NodeIterator : public ScriptWrappable, public RefCounted<NodeIterator>, public Traversal {
-    public:
-        static PassRefPtr<NodeIterator> create(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPtr<NodeFilter> filter)
-        {
-            return adoptRef(new NodeIterator(rootNode, whatToShow, filter));
-        }
-        ~NodeIterator();
+class NodeIterator : public ScriptWrappable, public RefCounted<NodeIterator>, public Traversal {
+public:
+    static PassRefPtr<NodeIterator> create(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPtr<NodeFilter> filter)
+    {
+        return adoptRef(new NodeIterator(rootNode, whatToShow, filter));
+    }
+    ~NodeIterator();
 
-        PassRefPtr<Node> nextNode(ScriptState*, ExceptionCode&);
-        PassRefPtr<Node> previousNode(ScriptState*, ExceptionCode&);
-        void detach();
+    PassRefPtr<Node> nextNode(ScriptState*, ExceptionState&);
+    PassRefPtr<Node> previousNode(ScriptState*, ExceptionState&);
+    void detach();
 
-        Node* referenceNode() const { return m_referenceNode.node.get(); }
-        bool pointerBeforeReferenceNode() const { return m_referenceNode.isPointerBeforeNode; }
+    Node* referenceNode() const { return m_referenceNode.node.get(); }
+    bool pointerBeforeReferenceNode() const { return m_referenceNode.isPointerBeforeNode; }
 
-        // This function is called before any node is removed from the document tree.
-        void nodeWillBeRemoved(Node*);
+    // This function is called before any node is removed from the document tree.
+    void nodeWillBeRemoved(Node*);
 
-    private:
-        NodeIterator(PassRefPtr<Node>, unsigned whatToShow, PassRefPtr<NodeFilter>);
+private:
+    NodeIterator(PassRefPtr<Node>, unsigned whatToShow, PassRefPtr<NodeFilter>);
 
-        struct NodePointer {
-            RefPtr<Node> node;
-            bool isPointerBeforeNode;
-            NodePointer();
-            NodePointer(PassRefPtr<Node>, bool);
-            void clear();
-            bool moveToNext(Node* root);
-            bool moveToPrevious(Node* root);
-        };
-
-        void updateForNodeRemoval(Node* nodeToBeRemoved, NodePointer&) const;
-
-        NodePointer m_referenceNode;
-        NodePointer m_candidateNode;
-        bool m_detached;
+    struct NodePointer {
+        RefPtr<Node> node;
+        bool isPointerBeforeNode;
+        NodePointer();
+        NodePointer(PassRefPtr<Node>, bool);
+        void clear();
+        bool moveToNext(Node* root);
+        bool moveToPrevious(Node* root);
     };
 
+    void updateForNodeRemoval(Node* nodeToBeRemoved, NodePointer&) const;
+
+    NodePointer m_referenceNode;
+    NodePointer m_candidateNode;
+    bool m_detached;
+};
+
 } // namespace WebCore
 
 #endif // NodeIterator_h
diff --git a/Source/core/dom/NodeList.idl b/Source/core/dom/NodeList.idl
index 37634f7..794ba11 100644
--- a/Source/core/dom/NodeList.idl
+++ b/Source/core/dom/NodeList.idl
@@ -23,7 +23,7 @@
     DependentLifetime
 ] interface NodeList {
 
-    getter Node item([IsIndex,Default=Undefined] optional unsigned long index);
+    getter Node item(unsigned long index);
     [ImplementedAs=anonymousNamedGetter, OverrideBuiltins, NotEnumerable] getter (Node or unsigned long) (DOMString name);
 
     readonly attribute unsigned long length;
diff --git a/Source/core/dom/Range.cpp b/Source/core/dom/Range.cpp
index 2f4de90..d6cd653 100644
--- a/Source/core/dom/Range.cpp
+++ b/Source/core/dom/Range.cpp
@@ -25,7 +25,8 @@
 #include "config.h"
 #include "core/dom/Range.h"
 
-#include <stdio.h>
+#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "core/dom/ClientRect.h"
 #include "core/dom/ClientRectList.h"
 #include "core/dom/DocumentFragment.h"
@@ -48,6 +49,7 @@
 #include "wtf/Vector.h"
 #include "wtf/text/CString.h"
 #include "wtf/text/StringBuilder.h"
+#include <stdio.h>
 
 namespace WebCore {
 
@@ -123,50 +125,50 @@
     m_ownerDocument->attachRange(this);
 }
 
-Node* Range::startContainer(ExceptionCode& ec) const
+Node* Range::startContainer(ExceptionState& es) const
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
     return m_start.container();
 }
 
-int Range::startOffset(ExceptionCode& ec) const
+int Range::startOffset(ExceptionState& es) const
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
     return m_start.offset();
 }
 
-Node* Range::endContainer(ExceptionCode& ec) const
+Node* Range::endContainer(ExceptionState& es) const
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
     return m_end.container();
 }
 
-int Range::endOffset(ExceptionCode& ec) const
+int Range::endOffset(ExceptionState& es) const
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
     return m_end.offset();
 }
 
-Node* Range::commonAncestorContainer(ExceptionCode& ec) const
+Node* Range::commonAncestorContainer(ExceptionState& es) const
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
@@ -184,10 +186,10 @@
     return 0;
 }
 
-bool Range::collapsed(ExceptionCode& ec) const
+bool Range::collapsed(ExceptionState& es) const
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
@@ -203,18 +205,18 @@
     while (startRootContainer->parentNode())
         startRootContainer = startRootContainer->parentNode();
 
-    return startRootContainer != endRootContainer || (Range::compareBoundaryPoints(start, end, ASSERT_NO_EXCEPTION) > 0);
+    return startRootContainer != endRootContainer || (Range::compareBoundaryPoints(start, end, ASSERT_NO_EXCEPTION_STATE) > 0);
 }
 
-void Range::setStart(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec)
+void Range::setStart(PassRefPtr<Node> refNode, int offset, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
     if (!refNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -224,26 +226,26 @@
         didMoveDocument = true;
     }
 
-    ec = 0;
-    Node* childNode = checkNodeWOffset(refNode.get(), offset, ec);
-    if (ec)
+    es.clearException();
+    Node* childNode = checkNodeWOffset(refNode.get(), offset, es);
+    if (es.hadException())
         return;
 
     m_start.set(refNode, offset, childNode);
 
     if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end))
-        collapse(true, ec);
+        collapse(true, es);
 }
 
-void Range::setEnd(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec)
+void Range::setEnd(PassRefPtr<Node> refNode, int offset, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
     if (!refNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -253,33 +255,33 @@
         didMoveDocument = true;
     }
 
-    ec = 0;
-    Node* childNode = checkNodeWOffset(refNode.get(), offset, ec);
-    if (ec)
+    es.clearException();
+    Node* childNode = checkNodeWOffset(refNode.get(), offset, es);
+    if (es.hadException())
         return;
 
     m_end.set(refNode, offset, childNode);
 
     if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end))
-        collapse(false, ec);
+        collapse(false, es);
 }
 
-void Range::setStart(const Position& start, ExceptionCode& ec)
+void Range::setStart(const Position& start, ExceptionState& es)
 {
     Position parentAnchored = start.parentAnchoredEquivalent();
-    setStart(parentAnchored.containerNode(), parentAnchored.offsetInContainerNode(), ec);
+    setStart(parentAnchored.containerNode(), parentAnchored.offsetInContainerNode(), es);
 }
 
-void Range::setEnd(const Position& end, ExceptionCode& ec)
+void Range::setEnd(const Position& end, ExceptionState& es)
 {
     Position parentAnchored = end.parentAnchoredEquivalent();
-    setEnd(parentAnchored.containerNode(), parentAnchored.offsetInContainerNode(), ec);
+    setEnd(parentAnchored.containerNode(), parentAnchored.offsetInContainerNode(), es);
 }
 
-void Range::collapse(bool toStart, ExceptionCode& ec)
+void Range::collapse(bool toStart, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
@@ -289,15 +291,15 @@
         m_start = m_end;
 }
 
-bool Range::isPointInRange(Node* refNode, int offset, ExceptionCode& ec)
+bool Range::isPointInRange(Node* refNode, int offset, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return false;
     }
 
     if (!refNode) {
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
         return false;
     }
 
@@ -305,69 +307,69 @@
         return false;
     }
 
-    ec = 0;
-    checkNodeWOffset(refNode, offset, ec);
-    if (ec)
+    es.clearException();
+    checkNodeWOffset(refNode, offset, es);
+    if (es.hadException())
         return false;
 
-    return compareBoundaryPoints(refNode, offset, m_start.container(), m_start.offset(), ec) >= 0 && !ec
-        && compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset(), ec) <= 0 && !ec;
+    return compareBoundaryPoints(refNode, offset, m_start.container(), m_start.offset(), es) >= 0 && !es.hadException()
+        && compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset(), es) <= 0 && !es.hadException();
 }
 
-short Range::comparePoint(Node* refNode, int offset, ExceptionCode& ec) const
+short Range::comparePoint(Node* refNode, int offset, ExceptionState& es) const
 {
     // http://developer.mozilla.org/en/docs/DOM:range.comparePoint
     // This method returns -1, 0 or 1 depending on if the point described by the
     // refNode node and an offset within the node is before, same as, or after the range respectively.
 
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
     if (!refNode) {
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
         return 0;
     }
 
     if (!refNode->attached() || refNode->document() != m_ownerDocument) {
-        ec = WrongDocumentError;
+        es.throwDOMException(WrongDocumentError);
         return 0;
     }
 
-    ec = 0;
-    checkNodeWOffset(refNode, offset, ec);
-    if (ec)
+    es.clearException();
+    checkNodeWOffset(refNode, offset, es);
+    if (es.hadException())
         return 0;
 
     // compare to start, and point comes before
-    if (compareBoundaryPoints(refNode, offset, m_start.container(), m_start.offset(), ec) < 0)
+    if (compareBoundaryPoints(refNode, offset, m_start.container(), m_start.offset(), es) < 0)
         return -1;
 
-    if (ec)
+    if (es.hadException())
         return 0;
 
     // compare to end, and point comes after
-    if (compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset(), ec) > 0 && !ec)
+    if (compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset(), es) > 0 && !es.hadException())
         return 1;
 
     // point is in the middle of this range, or on the boundary points
     return 0;
 }
 
-Range::CompareResults Range::compareNode(Node* refNode, ExceptionCode& ec) const
+Range::CompareResults Range::compareNode(Node* refNode, ExceptionState& es) const
 {
     // http://developer.mozilla.org/en/docs/DOM:range.compareNode
     // This method returns 0, 1, 2, or 3 based on if the node is before, after,
     // before and after(surrounds), or inside the range, respectively
 
     if (!refNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return NODE_BEFORE;
     }
 
     if (!m_start.container() && refNode->attached()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return NODE_BEFORE;
     }
 
@@ -387,43 +389,43 @@
     if (!parentNode) {
         // if the node is the top document we should return NODE_BEFORE_AND_AFTER
         // but we throw to match firefox behavior
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return NODE_BEFORE;
     }
 
-    if (comparePoint(parentNode, nodeIndex, ec) < 0) { // starts before
-        if (comparePoint(parentNode, nodeIndex + 1, ec) > 0) // ends after the range
+    if (comparePoint(parentNode, nodeIndex, es) < 0) { // starts before
+        if (comparePoint(parentNode, nodeIndex + 1, es) > 0) // ends after the range
             return NODE_BEFORE_AND_AFTER;
         return NODE_BEFORE; // ends before or in the range
-    } else { // starts at or after the range start
-        if (comparePoint(parentNode, nodeIndex + 1, ec) > 0) // ends after the range
-            return NODE_AFTER;
-        return NODE_INSIDE; // ends inside the range
     }
+    // starts at or after the range start
+    if (comparePoint(parentNode, nodeIndex + 1, es) > 0) // ends after the range
+        return NODE_AFTER;
+    return NODE_INSIDE; // ends inside the range
 }
 
-short Range::compareBoundaryPoints(CompareHow how, const Range* sourceRange, ExceptionCode& ec) const
+short Range::compareBoundaryPoints(CompareHow how, const Range* sourceRange, ExceptionState& es) const
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
     if (!sourceRange) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return 0;
     }
 
-    ec = 0;
-    Node* thisCont = commonAncestorContainer(ec);
-    if (ec)
+    es.clearException();
+    Node* thisCont = commonAncestorContainer(es);
+    if (es.hadException())
         return 0;
-    Node* sourceCont = sourceRange->commonAncestorContainer(ec);
-    if (ec)
+    Node* sourceCont = sourceRange->commonAncestorContainer(es);
+    if (es.hadException())
         return 0;
 
     if (thisCont->document() != sourceCont->document()) {
-        ec = WrongDocumentError;
+        es.throwDOMException(WrongDocumentError);
         return 0;
     }
 
@@ -434,26 +436,26 @@
     while (sourceTop->parentNode())
         sourceTop = sourceTop->parentNode();
     if (thisTop != sourceTop) { // in different DocumentFragments
-        ec = WrongDocumentError;
+        es.throwDOMException(WrongDocumentError);
         return 0;
     }
 
     switch (how) {
         case START_TO_START:
-            return compareBoundaryPoints(m_start, sourceRange->m_start, ec);
+            return compareBoundaryPoints(m_start, sourceRange->m_start, es);
         case START_TO_END:
-            return compareBoundaryPoints(m_end, sourceRange->m_start, ec);
+            return compareBoundaryPoints(m_end, sourceRange->m_start, es);
         case END_TO_END:
-            return compareBoundaryPoints(m_end, sourceRange->m_end, ec);
+            return compareBoundaryPoints(m_end, sourceRange->m_end, es);
         case END_TO_START:
-            return compareBoundaryPoints(m_start, sourceRange->m_end, ec);
+            return compareBoundaryPoints(m_start, sourceRange->m_end, es);
     }
 
-    ec = SyntaxError;
+    es.throwDOMException(SyntaxError);
     return 0;
 }
 
-short Range::compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionCode& ec)
+short Range::compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionState& es)
 {
     ASSERT(containerA);
     ASSERT(containerB);
@@ -515,7 +517,7 @@
     // ### we need to do a traversal here instead
     Node* commonAncestor = commonAncestorContainer(containerA, containerB);
     if (!commonAncestor) {
-        ec = WrongDocumentError;
+        es.throwDOMException(WrongDocumentError);
         return 0;
     }
     Node* childA = containerA;
@@ -546,38 +548,38 @@
     return 0;
 }
 
-short Range::compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB, ExceptionCode& ec)
+short Range::compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB, ExceptionState& es)
 {
-    return compareBoundaryPoints(boundaryA.container(), boundaryA.offset(), boundaryB.container(), boundaryB.offset(), ec);
+    return compareBoundaryPoints(boundaryA.container(), boundaryA.offset(), boundaryB.container(), boundaryB.offset(), es);
 }
 
 bool Range::boundaryPointsValid() const
 {
-    ExceptionCode ec = 0;
-    return m_start.container() && compareBoundaryPoints(m_start, m_end, ec) <= 0 && !ec;
+    TrackExceptionState es;
+    return m_start.container() && compareBoundaryPoints(m_start, m_end, es) <= 0 && !es.hadException();
 }
 
-void Range::deleteContents(ExceptionCode& ec)
+void Range::deleteContents(ExceptionState& es)
 {
-    checkDeleteExtract(ec);
-    if (ec)
+    checkDeleteExtract(es);
+    if (es.hadException())
         return;
 
-    processContents(DELETE_CONTENTS, ec);
+    processContents(DELETE_CONTENTS, es);
 }
 
-bool Range::intersectsNode(Node* refNode, ExceptionCode& ec)
+bool Range::intersectsNode(Node* refNode, ExceptionState& es)
 {
     // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode
     // Returns a bool if the node intersects the range.
 
     // Throw exception if the range is already detached.
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return false;
     }
     if (!refNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return false;
     }
 
@@ -592,15 +594,17 @@
     if (!parentNode) {
         // if the node is the top document we should return NODE_BEFORE_AND_AFTER
         // but we throw to match firefox behavior
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return false;
     }
 
-    if (comparePoint(parentNode, nodeIndex, ec) < 0 && // starts before start
-        comparePoint(parentNode, nodeIndex + 1, ec) < 0) { // ends before start
+    if (comparePoint(parentNode, nodeIndex, es) < 0 // starts before start
+        && comparePoint(parentNode, nodeIndex + 1, es) < 0) { // ends before start
         return false;
-    } else if (comparePoint(parentNode, nodeIndex, ec) > 0 && // starts after end
-               comparePoint(parentNode, nodeIndex + 1, ec) > 0) { // ends after end
+    }
+
+    if (comparePoint(parentNode, nodeIndex, es) > 0 // starts after end
+        && comparePoint(parentNode, nodeIndex + 1, es) > 0) { // ends after end
         return false;
     }
 
@@ -664,7 +668,7 @@
     return 0;
 }
 
-PassRefPtr<DocumentFragment> Range::processContents(ActionType action, ExceptionCode& ec)
+PassRefPtr<DocumentFragment> Range::processContents(ActionType action, ExceptionState& es)
 {
     typedef Vector<RefPtr<Node> > NodeVector;
 
@@ -672,19 +676,19 @@
     if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS)
         fragment = DocumentFragment::create(m_ownerDocument.get());
 
-    ec = 0;
-    if (collapsed(ec))
+    es.clearException();
+    if (collapsed(es))
         return fragment.release();
-    if (ec)
+    if (es.hadException())
         return 0;
 
-    RefPtr<Node> commonRoot = commonAncestorContainer(ec);
-    if (ec)
+    RefPtr<Node> commonRoot = commonAncestorContainer(es);
+    if (es.hadException())
         return 0;
     ASSERT(commonRoot);
 
     if (m_start.container() == m_end.container()) {
-        processContentsBetweenOffsets(action, fragment, m_start.container(), m_start.offset(), m_end.offset(), ec);
+        processContentsBetweenOffsets(action, fragment, m_start.container(), m_start.offset(), m_end.offset(), es);
         return fragment;
     }
 
@@ -718,14 +722,14 @@
 
     RefPtr<Node> leftContents;
     if (originalStart.container() != commonRoot && commonRoot->contains(originalStart.container())) {
-        leftContents = processContentsBetweenOffsets(action, 0, originalStart.container(), originalStart.offset(), lengthOfContentsInNode(originalStart.container()), ec);
-        leftContents = processAncestorsAndTheirSiblings(action, originalStart.container(), ProcessContentsForward, leftContents, commonRoot.get(), ec);
+        leftContents = processContentsBetweenOffsets(action, 0, originalStart.container(), originalStart.offset(), lengthOfContentsInNode(originalStart.container()), es);
+        leftContents = processAncestorsAndTheirSiblings(action, originalStart.container(), ProcessContentsForward, leftContents, commonRoot.get(), es);
     }
 
     RefPtr<Node> rightContents;
     if (m_end.container() != commonRoot && commonRoot->contains(originalEnd.container())) {
-        rightContents = processContentsBetweenOffsets(action, 0, originalEnd.container(), 0, originalEnd.offset(), ec);
-        rightContents = processAncestorsAndTheirSiblings(action, originalEnd.container(), ProcessContentsBackward, rightContents, commonRoot.get(), ec);
+        rightContents = processContentsBetweenOffsets(action, 0, originalEnd.container(), 0, originalEnd.offset(), es);
+        rightContents = processAncestorsAndTheirSiblings(action, originalEnd.container(), ProcessContentsBackward, rightContents, commonRoot.get(), es);
     }
 
     // delete all children of commonRoot between the start and end container
@@ -737,10 +741,10 @@
     // Collapse the range, making sure that the result is not within a node that was partially selected.
     if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) {
         if (partialStart && commonRoot->contains(partialStart.get()))
-            setStart(partialStart->parentNode(), partialStart->nodeIndex() + 1, ec);
+            setStart(partialStart->parentNode(), partialStart->nodeIndex() + 1, es);
         else if (partialEnd && commonRoot->contains(partialEnd.get()))
-            setStart(partialEnd->parentNode(), partialEnd->nodeIndex(), ec);
-        if (ec)
+            setStart(partialEnd->parentNode(), partialEnd->nodeIndex(), es);
+        if (es.hadException())
             return 0;
         m_end = m_start;
     }
@@ -752,31 +756,31 @@
     // (or just delete the stuff in between)
 
     if ((action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) && leftContents)
-        fragment->appendChild(leftContents, ec);
+        fragment->appendChild(leftContents, es);
 
     if (processStart) {
         NodeVector nodes;
         for (Node* n = processStart.get(); n && n != processEnd; n = n->nextSibling())
             nodes.append(n);
-        processNodes(action, nodes, commonRoot, fragment, ec);
+        processNodes(action, nodes, commonRoot, fragment, es);
     }
 
     if ((action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) && rightContents)
-        fragment->appendChild(rightContents, ec);
+        fragment->appendChild(rightContents, es);
 
     return fragment.release();
 }
 
-static inline void deleteCharacterData(PassRefPtr<CharacterData> data, unsigned startOffset, unsigned endOffset, ExceptionCode& ec)
+static inline void deleteCharacterData(PassRefPtr<CharacterData> data, unsigned startOffset, unsigned endOffset, ExceptionState& es)
 {
     if (data->length() - endOffset)
-        data->deleteData(endOffset, data->length() - endOffset, ec);
+        data->deleteData(endOffset, data->length() - endOffset, es);
     if (startOffset)
-        data->deleteData(0, startOffset, ec);
+        data->deleteData(0, startOffset, es);
 }
 
 PassRefPtr<Node> Range::processContentsBetweenOffsets(ActionType action, PassRefPtr<DocumentFragment> fragment,
-    Node* container, unsigned startOffset, unsigned endOffset, ExceptionCode& ec)
+    Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& es)
 {
     ASSERT(container);
     ASSERT(startOffset <= endOffset);
@@ -790,15 +794,15 @@
         ASSERT(endOffset <= static_cast<CharacterData*>(container)->length());
         if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) {
             RefPtr<CharacterData> c = static_pointer_cast<CharacterData>(container->cloneNode(true));
-            deleteCharacterData(c, startOffset, endOffset, ec);
+            deleteCharacterData(c, startOffset, endOffset, es);
             if (fragment) {
                 result = fragment;
-                result->appendChild(c.release(), ec);
+                result->appendChild(c.release(), es);
             } else
                 result = c.release();
         }
         if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS)
-            static_cast<CharacterData*>(container)->deleteData(startOffset, endOffset - startOffset, ec);
+            static_cast<CharacterData*>(container)->deleteData(startOffset, endOffset - startOffset, es);
         break;
     case Node::PROCESSING_INSTRUCTION_NODE:
         ASSERT(endOffset <= static_cast<ProcessingInstruction*>(container)->data().length());
@@ -807,7 +811,7 @@
             c->setData(c->data().substring(startOffset, endOffset - startOffset));
             if (fragment) {
                 result = fragment;
-                result->appendChild(c.release(), ec);
+                result->appendChild(c.release(), es);
             } else
                 result = c.release();
         }
@@ -841,31 +845,31 @@
         for (unsigned i = startOffset; n && i < endOffset; i++, n = n->nextSibling())
             nodes.append(n);
 
-        processNodes(action, nodes, container, result, ec);
+        processNodes(action, nodes, container, result, es);
         break;
     }
 
     return result.release();
 }
 
-void Range::processNodes(ActionType action, Vector<RefPtr<Node> >& nodes, PassRefPtr<Node> oldContainer, PassRefPtr<Node> newContainer, ExceptionCode& ec)
+void Range::processNodes(ActionType action, Vector<RefPtr<Node> >& nodes, PassRefPtr<Node> oldContainer, PassRefPtr<Node> newContainer, ExceptionState& es)
 {
     for (unsigned i = 0; i < nodes.size(); i++) {
         switch (action) {
         case DELETE_CONTENTS:
-            oldContainer->removeChild(nodes[i].get(), ec);
+            oldContainer->removeChild(nodes[i].get(), es);
             break;
         case EXTRACT_CONTENTS:
-            newContainer->appendChild(nodes[i].release(), ec); // will remove n from its parent
+            newContainer->appendChild(nodes[i].release(), es); // will remove n from its parent
             break;
         case CLONE_CONTENTS:
-            newContainer->appendChild(nodes[i]->cloneNode(true), ec);
+            newContainer->appendChild(nodes[i]->cloneNode(true), es);
             break;
         }
     }
 }
 
-PassRefPtr<Node> Range::processAncestorsAndTheirSiblings(ActionType action, Node* container, ContentsProcessDirection direction, PassRefPtr<Node> passedClonedContainer, Node* commonRoot, ExceptionCode& ec)
+PassRefPtr<Node> Range::processAncestorsAndTheirSiblings(ActionType action, Node* container, ContentsProcessDirection direction, PassRefPtr<Node> passedClonedContainer, Node* commonRoot, ExceptionState& es)
 {
     typedef Vector<RefPtr<Node> > NodeVector;
 
@@ -879,7 +883,7 @@
         RefPtr<Node> ancestor = *it;
         if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) {
             if (RefPtr<Node> clonedAncestor = ancestor->cloneNode(false)) { // Might have been removed already during mutation event.
-                clonedAncestor->appendChild(clonedContainer, ec);
+                clonedAncestor->appendChild(clonedContainer, es);
                 clonedContainer = clonedAncestor;
             }
         }
@@ -898,19 +902,19 @@
             Node* child = it->get();
             switch (action) {
             case DELETE_CONTENTS:
-                ancestor->removeChild(child, ec);
+                ancestor->removeChild(child, es);
                 break;
             case EXTRACT_CONTENTS: // will remove child from ancestor
                 if (direction == ProcessContentsForward)
-                    clonedContainer->appendChild(child, ec);
+                    clonedContainer->appendChild(child, es);
                 else
-                    clonedContainer->insertBefore(child, clonedContainer->firstChild(), ec);
+                    clonedContainer->insertBefore(child, clonedContainer->firstChild(), es);
                 break;
             case CLONE_CONTENTS:
                 if (direction == ProcessContentsForward)
-                    clonedContainer->appendChild(child->cloneNode(true), ec);
+                    clonedContainer->appendChild(child->cloneNode(true), es);
                 else
-                    clonedContainer->insertBefore(child->cloneNode(true), clonedContainer->firstChild(), ec);
+                    clonedContainer->insertBefore(child->cloneNode(true), clonedContainer->firstChild(), es);
                 break;
             }
         }
@@ -920,38 +924,38 @@
     return clonedContainer.release();
 }
 
-PassRefPtr<DocumentFragment> Range::extractContents(ExceptionCode& ec)
+PassRefPtr<DocumentFragment> Range::extractContents(ExceptionState& es)
 {
-    checkDeleteExtract(ec);
-    if (ec)
+    checkDeleteExtract(es);
+    if (es.hadException())
         return 0;
 
-    return processContents(EXTRACT_CONTENTS, ec);
+    return processContents(EXTRACT_CONTENTS, es);
 }
 
-PassRefPtr<DocumentFragment> Range::cloneContents(ExceptionCode& ec)
+PassRefPtr<DocumentFragment> Range::cloneContents(ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
-    return processContents(CLONE_CONTENTS, ec);
+    return processContents(CLONE_CONTENTS, es);
 }
 
-void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionCode& ec)
+void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionState& es)
 {
     RefPtr<Node> newNode = prpNewNode;
 
-    ec = 0;
+    es.clearException();
 
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
     if (!newNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -961,7 +965,7 @@
     // an extra one here - if a text node is going to split, it must have a parent to insert into
     bool startIsText = m_start.container()->isTextNode();
     if (startIsText && !m_start.container()->parentNode()) {
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
         return;
     }
 
@@ -980,7 +984,7 @@
         numNewChildren = 0;
         for (Node* c = newNode->firstChild(); c; c = c->nextSibling()) {
             if (!checkAgainst->childTypeAllowed(c->nodeType())) {
-                ec = HierarchyRequestError;
+                es.throwDOMException(HierarchyRequestError);
                 return;
             }
             ++numNewChildren;
@@ -988,14 +992,14 @@
     } else {
         numNewChildren = 1;
         if (!checkAgainst->childTypeAllowed(newNodeType)) {
-            ec = HierarchyRequestError;
+            es.throwDOMException(HierarchyRequestError);
             return;
         }
     }
 
     for (Node* n = m_start.container(); n; n = n->parentNode()) {
         if (n == newNode) {
-            ec = HierarchyRequestError;
+            es.throwDOMException(HierarchyRequestError);
             return;
         }
     }
@@ -1006,11 +1010,11 @@
     case Node::ENTITY_NODE:
     case Node::NOTATION_NODE:
     case Node::DOCUMENT_NODE:
-        ec = InvalidNodeTypeError;
+        es.throwDOMException(InvalidNodeTypeError);
         return;
     default:
         if (newNode->isShadowRoot()) {
-            ec = InvalidNodeTypeError;
+            es.throwDOMException(InvalidNodeTypeError);
             return;
         }
         break;
@@ -1021,13 +1025,13 @@
     RefPtr<Node> container;
     if (startIsText) {
         container = m_start.container();
-        RefPtr<Text> newText = toText(container.get())->splitText(m_start.offset(), ec);
-        if (ec)
+        RefPtr<Text> newText = toText(container.get())->splitText(m_start.offset(), es);
+        if (es.hadException())
             return;
 
         container = m_start.container();
-        container->parentNode()->insertBefore(newNode.release(), newText.get(), ec);
-        if (ec)
+        container->parentNode()->insertBefore(newNode.release(), newText.get(), es);
+        if (es.hadException())
             return;
 
         if (collapsed)
@@ -1039,8 +1043,8 @@
 
         int startOffset = m_start.offset();
         container = m_start.container();
-        container->insertBefore(newNode.release(), container->childNode(startOffset), ec);
-        if (ec)
+        container->insertBefore(newNode.release(), container->childNode(startOffset), es);
+        if (es.hadException())
             return;
 
         if (collapsed && numNewChildren)
@@ -1048,10 +1052,10 @@
     }
 }
 
-String Range::toString(ExceptionCode& ec) const
+String Range::toString(ExceptionState& es) const
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return String();
     }
 
@@ -1088,20 +1092,20 @@
     return plainText(this);
 }
 
-PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& markup, ExceptionCode& ec)
+PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& markup, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
     Node* element = m_start.container()->isElementNode() ? m_start.container() : m_start.container()->parentNode();
     if (!element || !element->isHTMLElement()) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return 0;
     }
 
-    RefPtr<DocumentFragment> fragment = WebCore::createContextualFragment(markup, toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadyStarted, ec);
+    RefPtr<DocumentFragment> fragment = WebCore::createContextualFragment(markup, toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadyStarted, es);
     if (!fragment)
         return 0;
 
@@ -1109,11 +1113,11 @@
 }
 
 
-void Range::detach(ExceptionCode& ec)
+void Range::detach(ExceptionState& es)
 {
     // Check first to see if we've already detached:
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
@@ -1123,23 +1127,23 @@
     m_end.clear();
 }
 
-Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionCode& ec) const
+Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& es) const
 {
     switch (n->nodeType()) {
         case Node::DOCUMENT_TYPE_NODE:
         case Node::ENTITY_NODE:
         case Node::NOTATION_NODE:
-            ec = InvalidNodeTypeError;
+            es.throwDOMException(InvalidNodeTypeError);
             return 0;
         case Node::CDATA_SECTION_NODE:
         case Node::COMMENT_NODE:
         case Node::TEXT_NODE:
             if (static_cast<unsigned>(offset) > static_cast<CharacterData*>(n)->length())
-                ec = IndexSizeError;
+                es.throwDOMException(IndexSizeError);
             return 0;
         case Node::PROCESSING_INSTRUCTION_NODE:
             if (static_cast<unsigned>(offset) > static_cast<ProcessingInstruction*>(n)->data().length())
-                ec = IndexSizeError;
+                es.throwDOMException(IndexSizeError);
             return 0;
         case Node::ATTRIBUTE_NODE:
         case Node::DOCUMENT_FRAGMENT_NODE:
@@ -1150,7 +1154,7 @@
                 return 0;
             Node* childBefore = n->childNode(offset - 1);
             if (!childBefore)
-                ec = IndexSizeError;
+                es.throwDOMException(IndexSizeError);
             return childBefore;
         }
     }
@@ -1158,7 +1162,7 @@
     return 0;
 }
 
-void Range::checkNodeBA(Node* n, ExceptionCode& ec) const
+void Range::checkNodeBA(Node* n, ExceptionState& es) const
 {
     // InvalidNodeTypeError: Raised if the root container of refNode is not an
     // Attr, Document, DocumentFragment or ShadowRoot node, or part of a SVG shadow DOM tree,
@@ -1170,7 +1174,7 @@
         case Node::DOCUMENT_NODE:
         case Node::ENTITY_NODE:
         case Node::NOTATION_NODE:
-            ec = InvalidNodeTypeError;
+            es.throwDOMException(InvalidNodeTypeError);
             return;
         case Node::CDATA_SECTION_NODE:
         case Node::COMMENT_NODE:
@@ -1200,90 +1204,90 @@
         case Node::PROCESSING_INSTRUCTION_NODE:
         case Node::TEXT_NODE:
         case Node::XPATH_NAMESPACE_NODE:
-            ec = InvalidNodeTypeError;
+            es.throwDOMException(InvalidNodeTypeError);
             return;
     }
 }
 
-PassRefPtr<Range> Range::cloneRange(ExceptionCode& ec) const
+PassRefPtr<Range> Range::cloneRange(ExceptionState& es) const
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return 0;
     }
 
     return Range::create(m_ownerDocument, m_start.container(), m_start.offset(), m_end.container(), m_end.offset());
 }
 
-void Range::setStartAfter(Node* refNode, ExceptionCode& ec)
+void Range::setStartAfter(Node* refNode, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
     if (!refNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
-    ec = 0;
-    checkNodeBA(refNode, ec);
-    if (ec)
+    es.clearException();
+    checkNodeBA(refNode, es);
+    if (es.hadException())
         return;
 
-    setStart(refNode->parentNode(), refNode->nodeIndex() + 1, ec);
+    setStart(refNode->parentNode(), refNode->nodeIndex() + 1, es);
 }
 
-void Range::setEndBefore(Node* refNode, ExceptionCode& ec)
+void Range::setEndBefore(Node* refNode, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
     if (!refNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
-    ec = 0;
-    checkNodeBA(refNode, ec);
-    if (ec)
+    es.clearException();
+    checkNodeBA(refNode, es);
+    if (es.hadException())
         return;
 
-    setEnd(refNode->parentNode(), refNode->nodeIndex(), ec);
+    setEnd(refNode->parentNode(), refNode->nodeIndex(), es);
 }
 
-void Range::setEndAfter(Node* refNode, ExceptionCode& ec)
+void Range::setEndAfter(Node* refNode, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
     if (!refNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
-    ec = 0;
-    checkNodeBA(refNode, ec);
-    if (ec)
+    es.clearException();
+    checkNodeBA(refNode, es);
+    if (es.hadException())
         return;
 
-    setEnd(refNode->parentNode(), refNode->nodeIndex() + 1, ec);
+    setEnd(refNode->parentNode(), refNode->nodeIndex() + 1, es);
 }
 
-void Range::selectNode(Node* refNode, ExceptionCode& ec)
+void Range::selectNode(Node* refNode, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
     if (!refNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -1305,7 +1309,7 @@
             case Node::DOCUMENT_TYPE_NODE:
             case Node::ENTITY_NODE:
             case Node::NOTATION_NODE:
-                ec = InvalidNodeTypeError;
+                es.throwDOMException(InvalidNodeTypeError);
                 return;
         }
     }
@@ -1324,29 +1328,29 @@
         case Node::DOCUMENT_NODE:
         case Node::ENTITY_NODE:
         case Node::NOTATION_NODE:
-            ec = InvalidNodeTypeError;
+            es.throwDOMException(InvalidNodeTypeError);
             return;
     }
 
     if (m_ownerDocument != refNode->document())
         setDocument(refNode->document());
 
-    ec = 0;
-    setStartBefore(refNode, ec);
-    if (ec)
+    es.clearException();
+    setStartBefore(refNode, es);
+    if (es.hadException())
         return;
-    setEndAfter(refNode, ec);
+    setEndAfter(refNode, es);
 }
 
-void Range::selectNodeContents(Node* refNode, ExceptionCode& ec)
+void Range::selectNodeContents(Node* refNode, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
     if (!refNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -1367,7 +1371,7 @@
             case Node::DOCUMENT_TYPE_NODE:
             case Node::ENTITY_NODE:
             case Node::NOTATION_NODE:
-                ec = InvalidNodeTypeError;
+                es.throwDOMException(InvalidNodeTypeError);
                 return;
         }
     }
@@ -1379,17 +1383,17 @@
     m_end.setToEndOfNode(refNode);
 }
 
-void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionCode& ec)
+void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionState& es)
 {
     RefPtr<Node> newParent = passNewParent;
 
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
     if (!newParent) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
@@ -1402,7 +1406,7 @@
         case Node::DOCUMENT_TYPE_NODE:
         case Node::ENTITY_NODE:
         case Node::NOTATION_NODE:
-            ec = InvalidNodeTypeError;
+            es.throwDOMException(InvalidNodeTypeError);
             return;
         case Node::CDATA_SECTION_NODE:
         case Node::COMMENT_NODE:
@@ -1422,12 +1426,12 @@
     if (parentOfNewParent->isCharacterDataNode())
         parentOfNewParent = parentOfNewParent->parentNode();
     if (!parentOfNewParent || !parentOfNewParent->childTypeAllowed(newParent->nodeType())) {
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
         return;
     }
 
     if (newParent->contains(m_start.container())) {
-        ec = HierarchyRequestError;
+        es.throwDOMException(HierarchyRequestError);
         return;
     }
 
@@ -1442,63 +1446,63 @@
     if (endNonTextContainer->nodeType() == Node::TEXT_NODE)
         endNonTextContainer = endNonTextContainer->parentNode();
     if (startNonTextContainer != endNonTextContainer) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
-    ec = 0;
+    es.clearException();
     while (Node* n = newParent->firstChild()) {
-        toContainerNode(newParent.get())->removeChild(n, ec);
-        if (ec)
+        toContainerNode(newParent.get())->removeChild(n, es);
+        if (es.hadException())
             return;
     }
-    RefPtr<DocumentFragment> fragment = extractContents(ec);
-    if (ec)
+    RefPtr<DocumentFragment> fragment = extractContents(es);
+    if (es.hadException())
         return;
-    insertNode(newParent, ec);
-    if (ec)
+    insertNode(newParent, es);
+    if (es.hadException())
         return;
-    newParent->appendChild(fragment.release(), ec);
-    if (ec)
+    newParent->appendChild(fragment.release(), es);
+    if (es.hadException())
         return;
-    selectNode(newParent.get(), ec);
+    selectNode(newParent.get(), es);
 }
 
-void Range::setStartBefore(Node* refNode, ExceptionCode& ec)
+void Range::setStartBefore(Node* refNode, ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
     if (!refNode) {
-        ec = NotFoundError;
+        es.throwDOMException(NotFoundError);
         return;
     }
 
-    ec = 0;
-    checkNodeBA(refNode, ec);
-    if (ec)
+    es.clearException();
+    checkNodeBA(refNode, es);
+    if (es.hadException())
         return;
 
-    setStart(refNode->parentNode(), refNode->nodeIndex(), ec);
+    setStart(refNode->parentNode(), refNode->nodeIndex(), es);
 }
 
-void Range::checkDeleteExtract(ExceptionCode& ec)
+void Range::checkDeleteExtract(ExceptionState& es)
 {
     if (!m_start.container()) {
-        ec = InvalidStateError;
+        es.throwDOMException(InvalidStateError);
         return;
     }
 
-    ec = 0;
-    if (!commonAncestorContainer(ec) || ec)
+    es.clearException();
+    if (!commonAncestorContainer(es) || es)
         return;
 
     Node* pastLast = pastLastNode();
     for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(n)) {
         if (n->nodeType() == Node::DOCUMENT_TYPE_NODE) {
-            ec = HierarchyRequestError;
+            es.throwDOMException(HierarchyRequestError);
             return;
         }
     }
@@ -1648,8 +1652,7 @@
 {
     ASSERT(node);
     RefPtr<Range> range = Range::create(node->document());
-    int exception = 0;
-    range->selectNodeContents(node, exception);
+    range->selectNodeContents(node, IGNORE_EXCEPTION_STATE);
     return range.release();
 }
 
@@ -1819,7 +1822,7 @@
     boundaryTextNodesSplit(m_end, oldNode);
 }
 
-void Range::expand(const String& unit, ExceptionCode& ec)
+void Range::expand(const String& unit, ExceptionState& es)
 {
     VisiblePosition start(startPosition());
     VisiblePosition end(endPosition());
@@ -1837,8 +1840,8 @@
         end = endOfDocument(end);
     } else
         return;
-    setStart(start.deepEquivalent().containerNode(), start.deepEquivalent().computeOffsetInContainerNode(), ec);
-    setEnd(end.deepEquivalent().containerNode(), end.deepEquivalent().computeOffsetInContainerNode(), ec);
+    setStart(start.deepEquivalent().containerNode(), start.deepEquivalent().computeOffsetInContainerNode(), es);
+    setEnd(end.deepEquivalent().containerNode(), end.deepEquivalent().computeOffsetInContainerNode(), es);
 }
 
 PassRefPtr<ClientRectList> Range::getClientRects() const
diff --git a/Source/core/dom/Range.h b/Source/core/dom/Range.h
index 1591515..f496cb7 100644
--- a/Source/core/dom/Range.h
+++ b/Source/core/dom/Range.h
@@ -25,8 +25,8 @@
 #ifndef Range_h
 #define Range_h
 
+#include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "bindings/v8/ScriptWrappable.h"
-#include "core/dom/ExceptionCodePlaceholder.h"
 #include "core/dom/RangeBoundaryPoint.h"
 #include "core/platform/graphics/FloatRect.h"
 #include "core/platform/graphics/IntRect.h"
@@ -41,6 +41,7 @@
 class ContainerNode;
 class Document;
 class DocumentFragment;
+class ExceptionState;
 class FloatQuad;
 class Node;
 class NodeWithIndex;
@@ -59,53 +60,53 @@
     Node* endContainer() const { return m_end.container(); }
     int endOffset() const { return m_end.offset(); }
 
-    Node* startContainer(ExceptionCode&) const;
-    int startOffset(ExceptionCode&) const;
-    Node* endContainer(ExceptionCode&) const;
-    int endOffset(ExceptionCode&) const;
-    bool collapsed(ExceptionCode&) const;
+    Node* startContainer(ExceptionState&) const;
+    int startOffset(ExceptionState&) const;
+    Node* endContainer(ExceptionState&) const;
+    int endOffset(ExceptionState&) const;
+    bool collapsed(ExceptionState&) const;
 
-    Node* commonAncestorContainer(ExceptionCode&) const;
+    Node* commonAncestorContainer(ExceptionState&) const;
     static Node* commonAncestorContainer(Node* containerA, Node* containerB);
-    void setStart(PassRefPtr<Node> container, int offset, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    void setEnd(PassRefPtr<Node> container, int offset, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    void collapse(bool toStart, ExceptionCode&);
-    bool isPointInRange(Node* refNode, int offset, ExceptionCode&);
-    short comparePoint(Node* refNode, int offset, ExceptionCode&) const;
+    void setStart(PassRefPtr<Node> container, int offset, ExceptionState& = ASSERT_NO_EXCEPTION_STATE);
+    void setEnd(PassRefPtr<Node> container, int offset, ExceptionState& = ASSERT_NO_EXCEPTION_STATE);
+    void collapse(bool toStart, ExceptionState&);
+    bool isPointInRange(Node* refNode, int offset, ExceptionState&);
+    short comparePoint(Node* refNode, int offset, ExceptionState&) const;
     enum CompareResults { NODE_BEFORE, NODE_AFTER, NODE_BEFORE_AND_AFTER, NODE_INSIDE };
-    CompareResults compareNode(Node* refNode, ExceptionCode&) const;
+    CompareResults compareNode(Node* refNode, ExceptionState&) const;
     enum CompareHow { START_TO_START, START_TO_END, END_TO_END, END_TO_START };
-    short compareBoundaryPoints(CompareHow, const Range* sourceRange, ExceptionCode&) const;
-    static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionCode&);
-    static short compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB, ExceptionCode&);
+    short compareBoundaryPoints(CompareHow, const Range* sourceRange, ExceptionState&) const;
+    static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionState&);
+    static short compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB, ExceptionState&);
     bool boundaryPointsValid() const;
-    bool intersectsNode(Node* refNode, ExceptionCode&);
-    void deleteContents(ExceptionCode&);
-    PassRefPtr<DocumentFragment> extractContents(ExceptionCode&);
-    PassRefPtr<DocumentFragment> cloneContents(ExceptionCode&);
-    void insertNode(PassRefPtr<Node>, ExceptionCode&);
-    String toString(ExceptionCode&) const;
+    bool intersectsNode(Node* refNode, ExceptionState&);
+    void deleteContents(ExceptionState&);
+    PassRefPtr<DocumentFragment> extractContents(ExceptionState&);
+    PassRefPtr<DocumentFragment> cloneContents(ExceptionState&);
+    void insertNode(PassRefPtr<Node>, ExceptionState&);
+    String toString(ExceptionState&) const;
 
     String toHTML() const;
     String text() const;
 
-    PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionCode&);
+    PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionState&);
 
-    void detach(ExceptionCode&);
-    PassRefPtr<Range> cloneRange(ExceptionCode&) const;
+    void detach(ExceptionState&);
+    PassRefPtr<Range> cloneRange(ExceptionState&) const;
 
-    void setStartAfter(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    void setEndBefore(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    void setEndAfter(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    void selectNode(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    void selectNodeContents(Node*, ExceptionCode&);
-    void surroundContents(PassRefPtr<Node>, ExceptionCode&);
-    void setStartBefore(Node*, ExceptionCode&);
+    void setStartAfter(Node*, ExceptionState& = ASSERT_NO_EXCEPTION_STATE);
+    void setEndBefore(Node*, ExceptionState& = ASSERT_NO_EXCEPTION_STATE);
+    void setEndAfter(Node*, ExceptionState& = ASSERT_NO_EXCEPTION_STATE);
+    void selectNode(Node*, ExceptionState& = ASSERT_NO_EXCEPTION_STATE);
+    void selectNodeContents(Node*, ExceptionState&);
+    void surroundContents(PassRefPtr<Node>, ExceptionState&);
+    void setStartBefore(Node*, ExceptionState&);
 
     const Position startPosition() const { return m_start.toPosition(); }
     const Position endPosition() const { return m_end.toPosition(); }
-    void setStart(const Position&, ExceptionCode& = ASSERT_NO_EXCEPTION);
-    void setEnd(const Position&, ExceptionCode& = ASSERT_NO_EXCEPTION);
+    void setStart(const Position&, ExceptionState& = ASSERT_NO_EXCEPTION_STATE);
+    void setEnd(const Position&, ExceptionState& = ASSERT_NO_EXCEPTION_STATE);
 
     Node* firstNode() const;
     Node* pastLastNode() const;
@@ -139,7 +140,7 @@
     // Expand range to a unit (word or sentence or block or document) boundary.
     // Please refer to https://bugs.webkit.org/show_bug.cgi?id=27632 comment #5
     // for details.
-    void expand(const String&, ExceptionCode&);
+    void expand(const String&, ExceptionState&);
 
     PassRefPtr<ClientRectList> getClientRects() const;
     PassRefPtr<ClientRect> getBoundingClientRect() const;
@@ -154,18 +155,18 @@
 
     void setDocument(Document*);
 
-    Node* checkNodeWOffset(Node*, int offset, ExceptionCode&) const;
-    void checkNodeBA(Node*, ExceptionCode&) const;
-    void checkDeleteExtract(ExceptionCode&);
+    Node* checkNodeWOffset(Node*, int offset, ExceptionState&) const;
+    void checkNodeBA(Node*, ExceptionState&) const;
+    void checkDeleteExtract(ExceptionState&);
     int maxStartOffset() const;
     int maxEndOffset() const;
 
     enum ActionType { DELETE_CONTENTS, EXTRACT_CONTENTS, CLONE_CONTENTS };
-    PassRefPtr<DocumentFragment> processContents(ActionType, ExceptionCode&);
-    static PassRefPtr<Node> processContentsBetweenOffsets(ActionType, PassRefPtr<DocumentFragment>, Node*, unsigned startOffset, unsigned endOffset, ExceptionCode&);
-    static void processNodes(ActionType, Vector<RefPtr<Node> >&, PassRefPtr<Node> oldContainer, PassRefPtr<Node> newContainer, ExceptionCode&);
+    PassRefPtr<DocumentFragment> processContents(ActionType, ExceptionState&);
+    static PassRefPtr<Node> processContentsBetweenOffsets(ActionType, PassRefPtr<DocumentFragment>, Node*, unsigned startOffset, unsigned endOffset, ExceptionState&);
+    static void processNodes(ActionType, Vector<RefPtr<Node> >&, PassRefPtr<Node> oldContainer, PassRefPtr<Node> newContainer, ExceptionState&);
     enum ContentsProcessDirection { ProcessContentsForward, ProcessContentsBackward };
-    static PassRefPtr<Node> processAncestorsAndTheirSiblings(ActionType, Node* container, ContentsProcessDirection, PassRefPtr<Node> clonedContainer, Node* commonRoot, ExceptionCode&);
+    static PassRefPtr<Node> processAncestorsAndTheirSiblings(ActionType, Node* container, ContentsProcessDirection, PassRefPtr<Node> clonedContainer, Node* commonRoot, ExceptionState&);
 
     RefPtr<Document> m_ownerDocument;
     RangeBoundaryPoint m_start;
diff --git a/Source/core/dom/SelectorQuery.cpp b/Source/core/dom/SelectorQuery.cpp
index 87b6d81..9e99139 100644
--- a/Source/core/dom/SelectorQuery.cpp
+++ b/Source/core/dom/SelectorQuery.cpp
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "core/dom/SelectorQuery.h"
 
+#include "bindings/v8/ExceptionState.h"
 #include "core/css/CSSParser.h"
 #include "core/css/CSSSelectorList.h"
 #include "core/css/SelectorChecker.h"
@@ -479,7 +480,7 @@
     return m_selectors.queryFirst(rootNode);
 }
 
-SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, Document* document, ExceptionCode& ec)
+SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, Document* document, ExceptionState& es)
 {
     HashMap<AtomicString, OwnPtr<SelectorQuery> >::iterator it = m_entries.find(selectors);
     if (it != m_entries.end())
@@ -490,13 +491,13 @@
     parser.parseSelector(selectors, selectorList);
 
     if (!selectorList.first() || selectorList.hasInvalidSelector()) {
-        ec = SyntaxError;
+        es.throwDOMException(SyntaxError);
         return 0;
     }
 
     // throw a NamespaceError if the selector includes any namespace prefixes.
     if (selectorList.selectorsNeedNamespaceResolution()) {
-        ec = NamespaceError;
+        es.throwDOMException(NamespaceError);
         return 0;
     }
 
diff --git a/Source/core/dom/SelectorQuery.h b/Source/core/dom/SelectorQuery.h
index 2e3bbe4..66f12a6 100644
--- a/Source/core/dom/SelectorQuery.h
+++ b/Source/core/dom/SelectorQuery.h
@@ -33,11 +33,10 @@
 
 namespace WebCore {
 
-typedef int ExceptionCode;
-
 class CSSSelector;
 class Document;
 class Element;
+class ExceptionState;
 class Node;
 class NodeList;
 class SimpleNodeList;
@@ -89,7 +88,7 @@
 class SelectorQueryCache {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    SelectorQuery* add(const AtomicString&, Document*, ExceptionCode&);
+    SelectorQuery* add(const AtomicString&, Document*, ExceptionState&);
     void invalidate();
 
 private:
diff --git a/Source/core/dom/Text.cpp b/Source/core/dom/Text.cpp
index 05d6e80..dce6f09 100644
--- a/Source/core/dom/Text.cpp
+++ b/Source/core/dom/Text.cpp
@@ -23,9 +23,10 @@
 #include "core/dom/Text.h"
 
 #include "SVGNames.h"
+#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "core/css/resolver/StyleResolver.h"
 #include "core/dom/ExceptionCode.h"
-#include "core/dom/ExceptionCodePlaceholder.h"
 #include "core/dom/NodeRenderStyle.h"
 #include "core/dom/NodeRenderingContext.h"
 #include "core/dom/ScopedEventQueue.h"
@@ -50,14 +51,14 @@
     return adoptRef(new Text(document, data, CreateEditingText));
 }
 
-PassRefPtr<Text> Text::splitText(unsigned offset, ExceptionCode& ec)
+PassRefPtr<Text> Text::splitText(unsigned offset, ExceptionState& es)
 {
-    ec = 0;
+    es.clearException();
 
     // IndexSizeError: Raised if the specified offset is negative or greater than
     // the number of 16-bit units in data.
     if (offset > length()) {
-        ec = IndexSizeError;
+        es.throwDOMException(IndexSizeError);
         return 0;
     }
 
@@ -69,8 +70,8 @@
     didModifyData(oldStr);
 
     if (parentNode())
-        parentNode()->insertBefore(newText.get(), nextSibling(), ec);
-    if (ec)
+        parentNode()->insertBefore(newText.get(), nextSibling(), es);
+    if (es.hadException())
         return 0;
 
     if (parentNode())
@@ -154,7 +155,7 @@
     for (RefPtr<Node> n = startText; n && n != this && n->isTextNode() && n->parentNode() == parent;) {
         RefPtr<Node> nodeToRemove(n.release());
         n = nodeToRemove->nextSibling();
-        parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION);
+        parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION_STATE);
     }
 
     if (this != endText) {
@@ -162,13 +163,13 @@
         for (RefPtr<Node> n = nextSibling(); n && n != onePastEndText && n->isTextNode() && n->parentNode() == parent;) {
             RefPtr<Node> nodeToRemove(n.release());
             n = nodeToRemove->nextSibling();
-            parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION);
+            parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION_STATE);
         }
     }
 
     if (newText.isEmpty()) {
         if (parent && parentNode() == parent)
-            parent->removeChild(this, IGNORE_EXCEPTION);
+            parent->removeChild(this, IGNORE_EXCEPTION_STATE);
         return 0;
     }
 
diff --git a/Source/core/dom/Text.h b/Source/core/dom/Text.h
index 1ca47b8..2384fbd 100644
--- a/Source/core/dom/Text.h
+++ b/Source/core/dom/Text.h
@@ -27,6 +27,7 @@
 
 namespace WebCore {
 
+class ExceptionState;
 class RenderText;
 class ScriptExecutionContext;
 
@@ -38,7 +39,7 @@
     static PassRefPtr<Text> createWithLengthLimit(Document*, const String&, unsigned positionInString, unsigned lengthLimit = defaultLengthLimit);
     static PassRefPtr<Text> createEditingText(Document*, const String&);
 
-    PassRefPtr<Text> splitText(unsigned offset, ExceptionCode&);
+    PassRefPtr<Text> splitText(unsigned offset, ExceptionState&);
 
     // DOM Level 3: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-1312295772
 
diff --git a/Source/core/dom/Text.idl b/Source/core/dom/Text.idl
index 8ed5b8d..aa82a41 100644
--- a/Source/core/dom/Text.idl
+++ b/Source/core/dom/Text.idl
@@ -23,10 +23,9 @@
 ] interface Text : CharacterData {
 
     // DOM Level 1
-
-    [RaisesException] Text splitText([IsIndex,Default=Undefined] optional unsigned long offset);
+    [RaisesException] Text splitText(unsigned long offset);
 
     // Introduced in DOM Level 3:
     readonly attribute DOMString       wholeText;
-    Text                               replaceWholeText([Default=Undefined] optional DOMString content);
+    Text                               replaceWholeText(DOMString content); // Removed from DOM4.
 };
diff --git a/Source/core/dom/TreeScope.cpp b/Source/core/dom/TreeScope.cpp
index 042539e..6afde25 100644
--- a/Source/core/dom/TreeScope.cpp
+++ b/Source/core/dom/TreeScope.cpp
@@ -55,7 +55,7 @@
 
 struct SameSizeAsTreeScope {
     virtual ~SameSizeAsTreeScope();
-    void* pointers[9];
+    void* pointers[8];
     int ints[1];
 };
 
@@ -162,29 +162,6 @@
     m_idTargetObserverRegistry->notifyObservers(elementId);
 }
 
-Element* TreeScope::getElementByName(const AtomicString& name) const
-{
-    if (name.isEmpty())
-        return 0;
-    if (!m_elementsByName)
-        return 0;
-    return m_elementsByName->getElementByName(name.impl(), this);
-}
-
-void TreeScope::addElementByName(const AtomicString& name, Element* element)
-{
-    if (!m_elementsByName)
-        m_elementsByName = adoptPtr(new DocumentOrderedMap);
-    m_elementsByName->add(name.impl(), element);
-}
-
-void TreeScope::removeElementByName(const AtomicString& name, Element* element)
-{
-    if (!m_elementsByName)
-        return;
-    m_elementsByName->remove(name.impl(), element);
-}
-
 Node* TreeScope::ancestorInThisScope(Node* node) const
 {
     while (node) {
diff --git a/Source/core/dom/TreeScope.h b/Source/core/dom/TreeScope.h
index 8edba5e..54144ab 100644
--- a/Source/core/dom/TreeScope.h
+++ b/Source/core/dom/TreeScope.h
@@ -56,17 +56,11 @@
 
     Element* adjustedFocusedElement();
     Element* getElementById(const AtomicString&) const;
-    bool hasElementWithId(const AtomicString&) const;
+    bool hasElementWithId(StringImpl* id) const;
     bool containsMultipleElementsWithId(const AtomicString& id) const;
     void addElementById(const AtomicString& elementId, Element*);
     void removeElementById(const AtomicString& elementId, Element*);
 
-    Element* getElementByName(const AtomicString&) const;
-    bool hasElementWithName(const AtomicString&) const;
-    bool containsMultipleElementsWithName(const AtomicString&) const;
-    void addElementByName(const AtomicString&, Element*);
-    void removeElementByName(const AtomicString&, Element*);
-
     Document* documentScope() const { return m_documentScope; }
 
     Node* ancestorInThisScope(Node*) const;
@@ -172,7 +166,6 @@
     int m_guardRefCount;
 
     OwnPtr<DocumentOrderedMap> m_elementsById;
-    OwnPtr<DocumentOrderedMap> m_elementsByName;
     OwnPtr<DocumentOrderedMap> m_imageMapsByName;
     OwnPtr<DocumentOrderedMap> m_labelsByForAttribute;
 
@@ -181,27 +174,15 @@
     mutable RefPtr<DOMSelection> m_selection;
 };
 
-inline bool TreeScope::hasElementWithId(const AtomicString& id) const
+inline bool TreeScope::hasElementWithId(StringImpl* id) const
 {
-    ASSERT(id.impl());
-    return m_elementsById && m_elementsById->contains(id.impl());
+    ASSERT(id);
+    return m_elementsById && m_elementsById->contains(id);
 }
 
 inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) const
 {
-    return m_elementsById && m_elementsById->mightContainMultiple(id.impl());
-}
-
-inline bool TreeScope::hasElementWithName(const AtomicString& id) const
-{
-    ASSERT(id.impl());
-    return m_elementsByName && m_elementsByName->contains(id.impl());
-}
-
-inline bool TreeScope::containsMultipleElementsWithName(const AtomicString& name) const
-{
-    ASSERT(name.impl());
-    return m_elementsByName && m_elementsByName->mightContainMultiple(name.impl());
+    return m_elementsById && m_elementsById->containsMultiple(id.impl());
 }
 
 Node* nodeFromPoint(Document*, int x, int y, LayoutPoint* localPoint = 0);
diff --git a/Source/core/dom/TreeWalker.cpp b/Source/core/dom/TreeWalker.cpp
index 626a4fc..bc0b775 100644
--- a/Source/core/dom/TreeWalker.cpp
+++ b/Source/core/dom/TreeWalker.cpp
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "core/dom/TreeWalker.h"
 
+#include "bindings/v8/ExceptionState.h"
 #include "bindings/v8/ScriptState.h"
 #include "core/dom/ContainerNode.h"
 #include "core/dom/ExceptionCode.h"
@@ -41,10 +42,10 @@
     ScriptWrappable::init(this);
 }
 
-void TreeWalker::setCurrentNode(PassRefPtr<Node> node, ExceptionCode& ec)
+void TreeWalker::setCurrentNode(PassRefPtr<Node> node, ExceptionState& es)
 {
     if (!node) {
-        ec = NotSupportedError;
+        es.throwDOMException(NotSupportedError);
         return;
     }
     m_current = node;
diff --git a/Source/core/dom/TreeWalker.h b/Source/core/dom/TreeWalker.h
index 9fcc954..354e449 100644
--- a/Source/core/dom/TreeWalker.h
+++ b/Source/core/dom/TreeWalker.h
@@ -33,33 +33,33 @@
 
 namespace WebCore {
 
-    typedef int ExceptionCode;
+class ExceptionState;
 
-    class TreeWalker : public ScriptWrappable, public RefCounted<TreeWalker>, public Traversal {
-    public:
-        static PassRefPtr<TreeWalker> create(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPtr<NodeFilter> filter)
-        {
-            return adoptRef(new TreeWalker(rootNode, whatToShow, filter));
-        }
+class TreeWalker : public ScriptWrappable, public RefCounted<TreeWalker>, public Traversal {
+public:
+    static PassRefPtr<TreeWalker> create(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPtr<NodeFilter> filter)
+    {
+        return adoptRef(new TreeWalker(rootNode, whatToShow, filter));
+    }
 
-        Node* currentNode() const { return m_current.get(); }
-        void setCurrentNode(PassRefPtr<Node>, ExceptionCode&);
+    Node* currentNode() const { return m_current.get(); }
+    void setCurrentNode(PassRefPtr<Node>, ExceptionState&);
 
-        Node* parentNode(ScriptState*);
-        Node* firstChild(ScriptState*);
-        Node* lastChild(ScriptState*);
-        Node* previousSibling(ScriptState*);
-        Node* nextSibling(ScriptState*);
-        Node* previousNode(ScriptState*);
-        Node* nextNode(ScriptState*);
+    Node* parentNode(ScriptState*);
+    Node* firstChild(ScriptState*);
+    Node* lastChild(ScriptState*);
+    Node* previousSibling(ScriptState*);
+    Node* nextSibling(ScriptState*);
+    Node* previousNode(ScriptState*);
+    Node* nextNode(ScriptState*);
 
-    private:
-        TreeWalker(PassRefPtr<Node>, unsigned whatToShow, PassRefPtr<NodeFilter>);
+private:
+    TreeWalker(PassRefPtr<Node>, unsigned whatToShow, PassRefPtr<NodeFilter>);
 
-        Node* setCurrent(PassRefPtr<Node>);
+    Node* setCurrent(PassRefPtr<Node>);
 
-        RefPtr<Node> m_current;
-    };
+    RefPtr<Node> m_current;
+};
 
 } // namespace WebCore
 
diff --git a/Source/core/dom/shadow/ShadowRoot.cpp b/Source/core/dom/shadow/ShadowRoot.cpp
index b993e91..e6d22f4 100644
--- a/Source/core/dom/shadow/ShadowRoot.cpp
+++ b/Source/core/dom/shadow/ShadowRoot.cpp
@@ -27,6 +27,7 @@
 #include "config.h"
 #include "core/dom/shadow/ShadowRoot.h"
 
+#include "bindings/v8/ExceptionState.h"
 #include "core/css/resolver/StyleResolver.h"
 #include "core/dom/Text.h"
 #include "core/dom/shadow/ContentDistributor.h"
@@ -106,9 +107,9 @@
     return older;
 }
 
-PassRefPtr<Node> ShadowRoot::cloneNode(bool, ExceptionCode& ec)
+PassRefPtr<Node> ShadowRoot::cloneNode(bool, ExceptionState& es)
 {
-    ec = DataCloneError;
+    es.throwDOMException(DataCloneError);
     return 0;
 }
 
@@ -117,15 +118,15 @@
     return createMarkup(this, ChildrenOnly);
 }
 
-void ShadowRoot::setInnerHTML(const String& markup, ExceptionCode& ec)
+void ShadowRoot::setInnerHTML(const String& markup, ExceptionState& es)
 {
     if (isOrphan()) {
-        ec = InvalidAccessError;
+        es.throwDOMException(InvalidAccessError);
         return;
     }
 
-    if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, host(), AllowScriptingContent, ec))
-        replaceChildrenWithFragment(this, fragment.release(), ec);
+    if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, host(), AllowScriptingContent, es))
+        replaceChildrenWithFragment(this, fragment.release(), es);
 }
 
 bool ShadowRoot::childTypeAllowed(NodeType type) const
@@ -161,7 +162,7 @@
     // When we're set to lazyAttach we'll have a SubtreeStyleChange and we'll need
     // to promote the change to a Force for all our descendants so they get a
     // recalc and will attach.
-    if (styleChangeType() == SubtreeStyleChange)
+    if (styleChangeType() >= SubtreeStyleChange)
         change = Force;
 
     // FIXME: This doesn't handle :hover + div properly like Element::recalcStyle does.
diff --git a/Source/core/dom/shadow/ShadowRoot.h b/Source/core/dom/shadow/ShadowRoot.h
index 3759557..f1bedcc 100644
--- a/Source/core/dom/shadow/ShadowRoot.h
+++ b/Source/core/dom/shadow/ShadowRoot.h
@@ -31,13 +31,13 @@
 #include "core/dom/Document.h"
 #include "core/dom/DocumentFragment.h"
 #include "core/dom/Element.h"
-#include "core/dom/ExceptionCode.h"
 #include "core/dom/TreeScope.h"
 #include "wtf/DoublyLinkedList.h"
 
 namespace WebCore {
 
 class ElementShadow;
+class ExceptionState;
 class InsertionPoint;
 class ScopeContentDistribution;
 
@@ -69,7 +69,7 @@
     ElementShadow* owner() const { return host() ? host()->shadow() : 0; }
 
     String innerHTML() const;
-    void setInnerHTML(const String&, ExceptionCode&);
+    void setInnerHTML(const String&, ExceptionState&);
 
     Element* activeElement() const;
 
@@ -102,8 +102,8 @@
 
     ShadowRootType type() const { return static_cast<ShadowRootType>(m_type); }
 
-    PassRefPtr<Node> cloneNode(bool, ExceptionCode&);
-    PassRefPtr<Node> cloneNode(ExceptionCode& ec) { return cloneNode(true, ec); }
+    PassRefPtr<Node> cloneNode(bool, ExceptionState&);
+    PassRefPtr<Node> cloneNode(ExceptionState& es) { return cloneNode(true, es); }
 
 private:
     ShadowRoot(Document*, ShadowRootType);