Changeset 208135 in webkit


Ignore:
Timestamp:
Oct 30, 2016 3:36:07 PM (7 years ago)
Author:
Darin Adler
Message:

Move Element, NamedNodeMap, and DOMStringMap from ExceptionCode to Exception
https://bugs.webkit.org/show_bug.cgi?id=164206

Reviewed by Chris Dumez.

Source/WebCore:

  • bindings/js/JSDOMStringMapCustom.cpp:

(WebCore::JSDOMStringMap::getOwnPropertyNames): Use modern for loop, and
updates since the names function now returns a vector.
(WebCore::JSDOMStringMap::putDelegate): Use propagateException. Also return
true any time an exception is raised. Since true tells the caller to return
without doing any work, we always want to return that on an exception.

  • dom/DatasetDOMStringMap.cpp:

(WebCore::DatasetDOMStringMap::names): Renamed from getNames and made this
return a Vector instead of populating a passed-in vector.
(WebCore::DatasetDOMStringMap::setItem): Use ExceptionOr.

  • dom/DatasetDOMStringMap.h: Updated for above.
  • dom/Document.cpp:

(WebCore::Document::adoptNode): Updated to use ExceptionOr for
removeAttributeNode. Changed to use remove rather than removeChild for
better clarity.

  • dom/Element.cpp:

(WebCore::Element::setAttribute): Use ExceptionOr.
(WebCore::Element::createShadowRoot): Deleted. Unused.
(WebCore::Element::attachShadow): Use ExceptionOr.
(WebCore::Element::shadowRootForBindings): Tweaked a bit.
(WebCore::Element::userAgentShadowRoot): Removed unneeded if statemment.
(WebCore::Element::ensureUserAgentShadowRoot): Tweaked a bit.
(WebCore::Element::setAttributeNode): Use ExceptionOr.
(WebCore::Element::setAttributeNodeNS): Ditto.
(WebCore::Element::removeAttributeNode): Ditto.
(WebCore::Element::parseAttributeName): Ditto. Also changed return result
to be a QualifiedName instead of using an out argument.
(WebCore::Element::setAttributeNS): Ditto.
(WebCore::Element::mergeWithNextTextNode): Ditto.
(WebCore::Element::setOuterHTML): Ditto.
(WebCore::Element::setInnerHTML): Ditto.
(WebCore::Element::matches): Ditto.
(WebCore::Element::closest): Ditto.
(WebCore::Element::insertAdjacent): Ditto.
(WebCore::Element::insertAdjacentElement): Ditto.
(WebCore::contextNodeForInsertion): Ditto.
(WebCore::contextElementForInsertion): Added. Helper for the
insertAdjacentHTML function to eliminate a local variable.
(WebCore::Element::insertAdjacentHTML): Use ExceptionOr.
(WebCore::Element::insertAdjacentText): Ditto.

  • dom/Element.h: Updated for above.
  • dom/Element.idl: Use non-legacy exceptions.
  • dom/NamedNodeMap.cpp:

(WebCore::NamedNodeMap::removeNamedItem): Use ExceptionOr.
(WebCore::NamedNodeMap::supportedPropertyNames): Updated to check
which strings should be removed without copying the strings.
(WebCore::NamedNodeMap::removeNamedItemNS): Use ExceptionOr.
(WebCore::NamedNodeMap::setNamedItem): Ditto. Removed overload for
legacy bindings; move that to the bindings themselves.

  • dom/NamedNodeMap.h: Updated for above.
  • dom/NamedNodeMap.idl: Use non-legacy exceptions.
  • html/HTMLElement.cpp:

(WebCore::HTMLElement::setOuterText): Updated since mergeWithNextTextNode
now uses ExceptionOr.

  • inspector/DOMEditor.cpp: Updated to use ExceptionOr.
  • inspector/InspectorDOMAgent.cpp:

(WebCore::InspectorDOMAgent::toErrorString): Added an overload for
Exception.
(WebCore::InspectorDOMAgent::setAttributesAsText): Updated to use ExceptionOr.

  • inspector/InspectorDOMAgent.h: Updated for above.
  • inspector/InspectorStyleSheet.cpp:

(WebCore::InspectorStyleSheetForInlineStyle::setStyleText): Updated to
use the correct version of setAttribute; there was never a risk that there
would be an exception, but now that's clearer.

  • testing/Internals.cpp:

(WebCore::Internals::ensureShadowRoot): Deleted. Was unused.
(WebCore::Internals::createShadowRoot): Ditto.

  • testing/Internals.idl: Updated for above.
  • xml/parser/XMLDocumentParserLibxml2.cpp:

(WebCore::handleNamespaceAttributes): Use updated parseAttributeName,
which uses ExceptionOr and a return value instead of an out argument.
(WebCore::handleElementAttributes): Ditto.

Source/WebKit/mac:

  • DOM/DOMElement.mm:

(-[DOMElement setInnerHTML:]): Updated exception handling.
(-[DOMElement setOuterHTML:]): Ditto.
(-[DOMElement setAttribute:value:]): Ditto.
(-[DOMElement setAttributeNode:]): Ditto.
(-[DOMElement removeAttributeNode:]): Ditto.
(-[DOMElement setAttributeNS:qualifiedName:value:]): Ditto.
(-[DOMElement setAttributeNodeNS:]): Ditto.
(-[DOMElement matches:]): Ditto.
(-[DOMElement closest:]): Ditto.
(-[DOMElement webkitMatchesSelector:]): Ditto.

  • DOM/DOMHTMLElement.mm:

(-[DOMHTMLElement insertAdjacentElement:element:]): Ditto.
(-[DOMHTMLElement insertAdjacentHTML:html:]): Ditto.
(-[DOMHTMLElement insertAdjacentText:text:]): Ditto.

  • DOM/DOMNamedNodeMap.mm:

(-[DOMNamedNodeMap setNamedItem:]): Ditto.
(-[DOMNamedNodeMap removeNamedItem:]): Ditto.
(-[DOMNamedNodeMap setNamedItemNS:]): Ditto.
(-[DOMNamedNodeMap removeNamedItemNS:localName:]): Ditto.

Source/WebKit/win:

  • DOMCoreClasses.cpp:

(DOMElement::setAttribute): Updated exception handling.

  • DOMHTMLClasses.cpp:

(DOMHTMLElement::setInnerHTML): Ditto.

Source/WebKit2:

  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMNamedNodeMap.cpp:

(webkit_dom_named_node_map_set_named_item): Updated exception handling.
(webkit_dom_named_node_map_remove_named_item): Ditto.
(webkit_dom_named_node_map_set_named_item_ns): Ditto.
(webkit_dom_named_node_map_remove_named_item_ns): Ditto.

  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElement.cpp:

(webkit_dom_element_set_attribute): Ditto.
(webkit_dom_element_set_attribute_node): Ditto.
(webkit_dom_element_remove_attribute_node): Ditto.
(webkit_dom_element_set_attribute_ns): Ditto.
(webkit_dom_element_set_attribute_node_ns): Ditto.
(webkit_dom_element_matches): Ditto.
(webkit_dom_element_closest): Ditto.
(webkit_dom_element_webkit_matches_selector): Ditto.
(webkit_dom_element_insert_adjacent_element): Ditto.
(webkit_dom_element_insert_adjacent_html): Ditto.
(webkit_dom_element_insert_adjacent_text): Ditto.
(webkit_dom_element_set_inner_html): Ditto.
(webkit_dom_element_set_outer_html): Ditto.

  • WebProcess/InjectedBundle/API/mac/WKDOMElement.mm:

(-[WKDOMElement setAttribute:value:]): Ditto.

LayoutTests:

  • fast/dom/resources/shadow-test-driver.js: Deleted. Unused.
Location:
trunk
Files:
1 deleted
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r208128 r208135  
     12016-10-30  Darin Adler  <darin@apple.com>
     2
     3        Move Element, NamedNodeMap, and DOMStringMap from ExceptionCode to Exception
     4        https://bugs.webkit.org/show_bug.cgi?id=164206
     5
     6        Reviewed by Chris Dumez.
     7
     8        * fast/dom/resources/shadow-test-driver.js: Deleted. Unused.
     9
    1102016-10-30  Frederic Wang  <fwang@igalia.com>
    211
  • trunk/Source/WebCore/ChangeLog

    r208134 r208135  
     12016-10-30  Darin Adler  <darin@apple.com>
     2
     3        Move Element, NamedNodeMap, and DOMStringMap from ExceptionCode to Exception
     4        https://bugs.webkit.org/show_bug.cgi?id=164206
     5
     6        Reviewed by Chris Dumez.
     7
     8        * bindings/js/JSDOMStringMapCustom.cpp:
     9        (WebCore::JSDOMStringMap::getOwnPropertyNames): Use modern for loop, and
     10        updates since the names function now returns a vector.
     11        (WebCore::JSDOMStringMap::putDelegate): Use propagateException. Also return
     12        true any time an exception is raised. Since true tells the caller to return
     13        without doing any work, we always want to return that on an exception.
     14        * dom/DatasetDOMStringMap.cpp:
     15        (WebCore::DatasetDOMStringMap::names): Renamed from getNames and made this
     16        return a Vector instead of populating a passed-in vector.
     17        (WebCore::DatasetDOMStringMap::setItem): Use ExceptionOr.
     18        * dom/DatasetDOMStringMap.h: Updated for above.
     19
     20        * dom/Document.cpp:
     21        (WebCore::Document::adoptNode): Updated to use ExceptionOr for
     22        removeAttributeNode. Changed to use remove rather than removeChild for
     23        better clarity.
     24
     25        * dom/Element.cpp:
     26        (WebCore::Element::setAttribute): Use ExceptionOr.
     27        (WebCore::Element::createShadowRoot): Deleted. Unused.
     28        (WebCore::Element::attachShadow): Use ExceptionOr.
     29        (WebCore::Element::shadowRootForBindings): Tweaked a bit.
     30        (WebCore::Element::userAgentShadowRoot): Removed unneeded if statemment.
     31        (WebCore::Element::ensureUserAgentShadowRoot): Tweaked a bit.
     32        (WebCore::Element::setAttributeNode): Use ExceptionOr.
     33        (WebCore::Element::setAttributeNodeNS): Ditto.
     34        (WebCore::Element::removeAttributeNode): Ditto.
     35        (WebCore::Element::parseAttributeName): Ditto. Also changed return result
     36        to be a QualifiedName instead of using an out argument.
     37        (WebCore::Element::setAttributeNS): Ditto.
     38        (WebCore::Element::mergeWithNextTextNode): Ditto.
     39        (WebCore::Element::setOuterHTML): Ditto.
     40        (WebCore::Element::setInnerHTML): Ditto.
     41        (WebCore::Element::matches): Ditto.
     42        (WebCore::Element::closest): Ditto.
     43        (WebCore::Element::insertAdjacent): Ditto.
     44        (WebCore::Element::insertAdjacentElement): Ditto.
     45        (WebCore::contextNodeForInsertion): Ditto.
     46        (WebCore::contextElementForInsertion): Added. Helper for the
     47        insertAdjacentHTML function to eliminate a local variable.
     48        (WebCore::Element::insertAdjacentHTML): Use ExceptionOr.
     49        (WebCore::Element::insertAdjacentText): Ditto.
     50        * dom/Element.h: Updated for above.
     51        * dom/Element.idl: Use non-legacy exceptions.
     52
     53        * dom/NamedNodeMap.cpp:
     54        (WebCore::NamedNodeMap::removeNamedItem): Use ExceptionOr.
     55        (WebCore::NamedNodeMap::supportedPropertyNames): Updated to check
     56        which strings should be removed without copying the strings.
     57        (WebCore::NamedNodeMap::removeNamedItemNS): Use ExceptionOr.
     58        (WebCore::NamedNodeMap::setNamedItem): Ditto. Removed overload for
     59        legacy bindings; move that to the bindings themselves.
     60        * dom/NamedNodeMap.h: Updated for above.
     61        * dom/NamedNodeMap.idl: Use non-legacy exceptions.
     62
     63        * html/HTMLElement.cpp:
     64        (WebCore::HTMLElement::setOuterText): Updated since mergeWithNextTextNode
     65        now uses ExceptionOr.
     66
     67        * inspector/DOMEditor.cpp: Updated to use ExceptionOr.
     68
     69        * inspector/InspectorDOMAgent.cpp:
     70        (WebCore::InspectorDOMAgent::toErrorString): Added an overload for
     71        Exception.
     72        (WebCore::InspectorDOMAgent::setAttributesAsText): Updated to use ExceptionOr.
     73        * inspector/InspectorDOMAgent.h: Updated for above.
     74
     75        * inspector/InspectorStyleSheet.cpp:
     76        (WebCore::InspectorStyleSheetForInlineStyle::setStyleText): Updated to
     77        use the correct version of setAttribute; there was never a risk that there
     78        would be an exception, but now that's clearer.
     79
     80        * testing/Internals.cpp:
     81        (WebCore::Internals::ensureShadowRoot): Deleted. Was unused.
     82        (WebCore::Internals::createShadowRoot): Ditto.
     83        * testing/Internals.idl: Updated for above.
     84
     85        * xml/parser/XMLDocumentParserLibxml2.cpp:
     86        (WebCore::handleNamespaceAttributes): Use updated parseAttributeName,
     87        which uses ExceptionOr and a return value instead of an out argument.
     88        (WebCore::handleElementAttributes): Ditto.
     89
    1902016-10-30  Sam Weinig  <sam@webkit.org>
    291
  • trunk/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp

    r207912 r208135  
    343343    if (setPropertyInternalResult.hasException()) {
    344344        propagateException(*state, setPropertyInternalResult.releaseException());
    345         return false;
     345        return true;
    346346    }
    347347    putResult = setPropertyInternalResult.releaseReturnValue();
  • trunk/Source/WebCore/bindings/js/JSDOMStringMapCustom.cpp

    r208083 r208135  
    3838namespace WebCore {
    3939
    40 bool JSDOMStringMap::getOwnPropertySlotDelegate(ExecState* exec, PropertyName propertyName, PropertySlot& slot)
     40bool JSDOMStringMap::getOwnPropertySlotDelegate(ExecState* state, PropertyName propertyName, PropertySlot& slot)
    4141{
    4242    if (propertyName.isSymbol())
     
    4545    const AtomicString& item = wrapped().item(propertyNameToString(propertyName), nameIsValid);
    4646    if (nameIsValid) {
    47         slot.setValue(this, 0, toJS<IDLDOMString>(*exec, item));
     47        slot.setValue(this, 0, toJS<IDLDOMString>(*state, item));
    4848        return true;
    4949    }
     
    5151}
    5252
    53 void JSDOMStringMap::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
     53void JSDOMStringMap::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
    5454{
    55     JSDOMStringMap* thisObject = jsCast<JSDOMStringMap*>(object);
    56     Vector<String> names;
    57     thisObject->wrapped().getNames(names);
    58     size_t length = names.size();
    59     for (size_t i = 0; i < length; ++i)
    60         propertyNames.add(Identifier::fromString(exec, names[i]));
    61 
    62     Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
     55    for (auto& name : jsCast<JSDOMStringMap*>(object)->wrapped().names())
     56        propertyNames.add(Identifier::fromString(state, name));
     57    Base::getOwnPropertyNames(object, state, propertyNames, mode);
    6358}
    6459
    65 bool JSDOMStringMap::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
     60bool JSDOMStringMap::deleteProperty(JSCell* cell, ExecState* state, PropertyName propertyName)
    6661{
    6762#if ENABLE(CUSTOM_ELEMENTS)
     
    6964#endif
    7065
    71     JSDOMStringMap* thisObject = jsCast<JSDOMStringMap*>(cell);
    7266    if (propertyName.isSymbol())
    73         return Base::deleteProperty(thisObject, exec, propertyName);
    74     return thisObject->wrapped().deleteItem(propertyNameToString(propertyName));
     67        return Base::deleteProperty(cell, state, propertyName);
     68    return jsCast<JSDOMStringMap*>(cell)->wrapped().deleteItem(propertyNameToString(propertyName));
    7569}
    7670
    77 bool JSDOMStringMap::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned index)
     71bool JSDOMStringMap::deletePropertyByIndex(JSCell* cell, ExecState* state, unsigned index)
    7872{
    79     return deleteProperty(cell, exec, Identifier::from(exec, index));
     73    return deleteProperty(cell, state, Identifier::from(state, index));
    8074}
    8175
    82 bool JSDOMStringMap::putDelegate(ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot&, bool& putResult)
     76bool JSDOMStringMap::putDelegate(ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot&, bool& putResult)
    8377{
    84     VM& vm = exec->vm();
     78    VM& vm = state->vm();
    8579    auto scope = DECLARE_THROW_SCOPE(vm);
    8680
     
    9286#endif
    9387
    94     String stringValue = value.toString(exec)->value(exec);
    95     RETURN_IF_EXCEPTION(scope, false);
     88    String stringValue = value.toWTFString(state);
     89    RETURN_IF_EXCEPTION(scope, true);
    9690
    97     ExceptionCode ec = 0;
    98     wrapped().setItem(propertyNameToString(propertyName), stringValue, ec);
    99     setDOMException(exec, ec);
    100     putResult = !ec;
    101     return !ec;
     91    auto result = wrapped().setItem(propertyNameToString(propertyName), WTFMove(stringValue));
     92    if (result.hasException()) {
     93        propagateException(*state, scope, result.releaseException());
     94        return true;
     95    }
     96
     97    putResult = true;
     98    return true;
    10299}
    103100
  • trunk/Source/WebCore/bindings/js/JSStorageCustom.cpp

    r207522 r208135  
    112112    // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
    113113    // the native property slots manually.
    114     PropertySlot slot(this, PropertySlot::InternalMethodType::GetOwnProperty);
     114    PropertySlot slot { this, PropertySlot::InternalMethodType::GetOwnProperty };
    115115
    116116    JSValue prototype = this->getPrototypeDirect();
     
    121121        return false;
    122122
    123     String stringValue = value.toString(state)->value(state);
    124     if (UNLIKELY(scope.exception())) {
    125         // The return value indicates whether putDelegate() should handle the put operation (which
    126         // if true, tells the caller not to execute the generic put). It does not indicate whether
    127         // putDelegate() did successfully complete the operation or not (which it didn't in this
    128         // case due to the exception).
    129         putResult = false;
     123    String stringValue = value.toWTFString(state);
     124    RETURN_IF_EXCEPTION(scope, true);
     125
     126    auto setItemResult = wrapped().setItem(propertyNameToString(propertyName), stringValue);
     127    if (setItemResult.hasException()) {
     128        propagateException(*state, scope, setItemResult.releaseException());
    130129        return true;
    131130    }
    132131
    133     auto setItemResult = wrapped().setItem(propertyNameToString(propertyName), stringValue);
    134     putResult = !setItemResult.hasException();
    135     propagateException(*state, scope, WTFMove(setItemResult));
     132    putResult = true;
    136133    return true;
    137134}
  • trunk/Source/WebCore/dom/DatasetDOMStringMap.cpp

    r164176 r208135  
    3232#include <wtf/text/AtomicString.h>
    3333#include <wtf/text/StringBuilder.h>
    34 #include <wtf/text/WTFString.h>
    3534
    3635namespace WebCore {
     
    153152}
    154153
    155 void DatasetDOMStringMap::getNames(Vector<String>& names)
    156 {
    157     if (!m_element.hasAttributes())
    158         return;
    159 
    160     for (const Attribute& attribute : m_element.attributesIterator()) {
    161         if (isValidAttributeName(attribute.localName()))
    162             names.append(convertAttributeNameToPropertyName(attribute.localName()));
    163     }
    164 }
    165 
    166 const AtomicString& DatasetDOMStringMap::item(const String& propertyName, bool& isValid)
     154Vector<String> DatasetDOMStringMap::names() const
     155{
     156    Vector<String> names;
     157
     158    if (m_element.hasAttributes()) {
     159        for (auto& attribute : m_element.attributesIterator()) {
     160            if (isValidAttributeName(attribute.localName()))
     161                names.append(convertAttributeNameToPropertyName(attribute.localName()));
     162        }
     163    }
     164
     165    return names;
     166}
     167
     168const AtomicString& DatasetDOMStringMap::item(const String& propertyName, bool& isValid) const
    167169{
    168170    isValid = false;
     
    192194}
    193195
    194 void DatasetDOMStringMap::setItem(const String& name, const String& value, ExceptionCode& ec)
    195 {
    196     if (!isValidPropertyName(name)) {
    197         ec = SYNTAX_ERR;
    198         return;
    199     }
    200 
    201     m_element.setAttribute(convertPropertyNameToAttributeName(name), value, ec);
     196ExceptionOr<void> DatasetDOMStringMap::setItem(const String& name, const String& value)
     197{
     198    if (!isValidPropertyName(name))
     199        return Exception { SYNTAX_ERR };
     200    return m_element.setAttribute(convertPropertyNameToAttributeName(name), value);
    202201}
    203202
  • trunk/Source/WebCore/dom/DatasetDOMStringMap.h

    r173890 r208135  
    2424 */
    2525
    26 #ifndef DatasetDOMStringMap_h
    27 #define DatasetDOMStringMap_h
     26#pragma once
    2827
     28#include "ExceptionOr.h"
    2929#include "ScriptWrappable.h"
    30 #include <wtf/Forward.h>
    31 #include <wtf/Noncopyable.h>
    32 #include <wtf/Vector.h>
    3330
    3431namespace WebCore {
    3532
    3633class Element;
    37 typedef int ExceptionCode;
    3834
    3935class DatasetDOMStringMap final : public ScriptWrappable {
    40     WTF_MAKE_NONCOPYABLE(DatasetDOMStringMap); WTF_MAKE_FAST_ALLOCATED;
     36    WTF_MAKE_FAST_ALLOCATED;
    4137public:
    4238    explicit DatasetDOMStringMap(Element& element)
     
    4844    void deref();
    4945
    50     void getNames(Vector<String>&);
    51     const AtomicString& item(const String& name, bool& isValid);
    52     void setItem(const String& name, const String& value, ExceptionCode&);
     46    Vector<String> names() const;
     47    const AtomicString& item(const String& name, bool& isValid) const;
     48    ExceptionOr<void> setItem(const String& name, const String& value);
    5349    bool deleteItem(const String& name);
    5450
     
    6056
    6157} // namespace WebCore
    62 
    63 #endif // DatasetDOMStringMap_h
  • trunk/Source/WebCore/dom/Document.cpp

    r208112 r208135  
    10141014        ec = NOT_SUPPORTED_ERR;
    10151015        return nullptr;
    1016     case ATTRIBUTE_NODE: {                   
     1016    case ATTRIBUTE_NODE: {
    10171017        auto& attr = downcast<Attr>(source);
    1018         if (attr.ownerElement())
    1019             attr.ownerElement()->removeAttributeNode(attr, ec);
     1018        if (auto* element = attr.ownerElement()) {
     1019            auto result = element->removeAttributeNode(attr);
     1020            if (result.hasException()) {
     1021                ec = result.releaseException().code();
     1022                // FIXME: Why fall through here instead of returning early?
     1023            }
     1024        }
    10201025        break;
    10211026    }       
     
    10331038            }
    10341039        }
    1035         if (source.parentNode()) {
    1036             source.parentNode()->removeChild(source, ec);
    1037             if (ec)
    1038                 return nullptr;
     1040        auto result = source.remove();
     1041        if (result.hasException()) {
     1042            ec = result.releaseException().code();
     1043            return nullptr;
    10391044        }
    10401045    }
  • trunk/Source/WebCore/dom/Element.cpp

    r208112 r208135  
    12181218}
    12191219
    1220 void Element::setAttribute(const AtomicString& localName, const AtomicString& value, ExceptionCode& ec)
    1221 {
    1222     if (!Document::isValidName(localName)) {
    1223         ec = INVALID_CHARACTER_ERR;
    1224         return;
    1225     }
     1220ExceptionOr<void> Element::setAttribute(const AtomicString& localName, const AtomicString& value)
     1221{
     1222    if (!Document::isValidName(localName))
     1223        return Exception { INVALID_CHARACTER_ERR };
    12261224
    12271225    synchronizeAttribute(localName);
    1228     const AtomicString& caseAdjustedLocalName = shouldIgnoreAttributeCase(*this) ? localName.convertToASCIILowercase() : localName;
    1229 
     1226    auto caseAdjustedLocalName = shouldIgnoreAttributeCase(*this) ? localName.convertToASCIILowercase() : localName;
    12301227    unsigned index = elementData() ? elementData()->findAttributeIndexByName(caseAdjustedLocalName, false) : ElementData::attributeNotFound;
    1231     const QualifiedName& qName = index != ElementData::attributeNotFound ? attributeAt(index).name() : QualifiedName(nullAtom, caseAdjustedLocalName, nullAtom);
    1232     setAttributeInternal(index, qName, value, NotInSynchronizationOfLazyAttribute);
     1228    auto name = index != ElementData::attributeNotFound ? attributeAt(index).name() : QualifiedName { nullAtom, caseAdjustedLocalName, nullAtom };
     1229    setAttributeInternal(index, name, value, NotInSynchronizationOfLazyAttribute);
     1230
     1231    return { };
    12331232}
    12341233
     
    17571756}
    17581757
    1759 
    17601758void Element::addShadowRoot(Ref<ShadowRoot>&& newShadowRoot)
    17611759{
    17621760    ASSERT(!shadowRoot());
    17631761
    1764     ShadowRoot& shadowRoot = newShadowRoot.get();
     1762    ShadowRoot& shadowRoot = newShadowRoot;
    17651763    ensureElementRareData().setShadowRoot(WTFMove(newShadowRoot));
    17661764
     
    17861784    if (!oldRoot)
    17871785        return;
     1786
    17881787    InspectorInstrumentation::willPopShadowRoot(*this, *oldRoot);
    17891788    document().removeFocusedNodeOfSubtree(oldRoot.get());
     
    17981797    notifyChildNodeRemoved(*this, *oldRoot);
    17991798}
    1800 
    1801 ShadowRoot* Element::createShadowRoot(ExceptionCode& ec)
    1802 {
    1803     if (alwaysCreateUserAgentShadowRoot())
    1804         return &ensureUserAgentShadowRoot();
    1805 
    1806     ec = HIERARCHY_REQUEST_ERR;
    1807     return nullptr;
    1808 }
    1809 
    18101799
    18111800static bool canAttachAuthorShadowRoot(const Element& element)
     
    18441833}
    18451834
    1846 RefPtr<ShadowRoot> Element::attachShadow(const ShadowRootInit& init, ExceptionCode& ec)
    1847 {
    1848     if (!canAttachAuthorShadowRoot(*this)) {
    1849         ec = NOT_SUPPORTED_ERR;
    1850         return nullptr;
    1851     }
    1852 
    1853     if (shadowRoot()) {
    1854         ec = INVALID_STATE_ERR;
    1855         return nullptr;
    1856     }
    1857 
    1858     if (init.mode == ShadowRootMode::UserAgent) {
    1859         ec = TypeError;
    1860         return nullptr;
    1861     }
    1862 
     1835ExceptionOr<Ref<ShadowRoot>> Element::attachShadow(const ShadowRootInit& init)
     1836{
     1837    if (!canAttachAuthorShadowRoot(*this))
     1838        return Exception { NOT_SUPPORTED_ERR };
     1839    if (shadowRoot())
     1840        return Exception { INVALID_STATE_ERR };
     1841    if (init.mode == ShadowRootMode::UserAgent)
     1842        return Exception { TypeError };
    18631843    auto shadow = ShadowRoot::create(document(), init.mode);
    18641844    addShadowRoot(shadow.copyRef());
     
    18681848ShadowRoot* Element::shadowRootForBindings(JSC::ExecState& state) const
    18691849{
    1870     ShadowRoot* root = shadowRoot();
    1871     if (!root)
     1850    auto* shadow = shadowRoot();
     1851    if (!shadow)
    18721852        return nullptr;
    1873 
    1874     if (root->mode() != ShadowRootMode::Open) {
    1875         if (!JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())->world().shadowRootIsAlwaysOpen())
    1876             return nullptr;
    1877     }
    1878     return root;
    1879 }
    1880 
     1853    if (shadow->mode() == ShadowRootMode::Open)
     1854        return shadow;
     1855    if (JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())->world().shadowRootIsAlwaysOpen())
     1856        return shadow;
     1857    return nullptr;
     1858}
    18811859
    18821860ShadowRoot* Element::userAgentShadowRoot() const
    18831861{
    1884     if (ShadowRoot* shadowRoot = this->shadowRoot()) {
    1885         ASSERT(shadowRoot->mode() == ShadowRootMode::UserAgent);
    1886         return shadowRoot;
    1887     }
    1888     return nullptr;
     1862    ASSERT(!shadowRoot() || shadowRoot()->mode() == ShadowRootMode::UserAgent);
     1863    return shadowRoot();
    18891864}
    18901865
    18911866ShadowRoot& Element::ensureUserAgentShadowRoot()
    18921867{
    1893     ShadowRoot* shadowRoot = userAgentShadowRoot();
    1894     if (!shadowRoot) {
    1895         addShadowRoot(ShadowRoot::create(document(), ShadowRootMode::UserAgent));
    1896         shadowRoot = userAgentShadowRoot();
    1897     }
    1898     return *shadowRoot;
    1899 }
    1900 
    1901    
     1868    if (auto* shadow = userAgentShadowRoot())
     1869        return *shadow;
     1870    auto newShadow = ShadowRoot::create(document(), ShadowRootMode::UserAgent);
     1871    ShadowRoot& shadow = newShadow;
     1872    addShadowRoot(WTFMove(newShadow));
     1873    return shadow;
     1874}
     1875
    19021876#if ENABLE(CUSTOM_ELEMENTS)
    19031877
     
    19531927
    19541928#endif
    1955 
    19561929
    19571930const AtomicString& Element::shadowPseudoId() const
     
    21602133}
    21612134
    2162 RefPtr<Attr> Element::setAttributeNode(Attr& attrNode, ExceptionCode& ec)
     2135ExceptionOr<RefPtr<Attr>> Element::setAttributeNode(Attr& attrNode)
    21632136{
    21642137    RefPtr<Attr> oldAttrNode = attrIfExists(attrNode.qualifiedName().localName(), shouldIgnoreAttributeCase(*this));
    21652138    if (oldAttrNode.get() == &attrNode)
    2166         return &attrNode; // This Attr is already attached to the element.
     2139        return WTFMove(oldAttrNode);
    21672140
    21682141    // INUSE_ATTRIBUTE_ERR: Raised if node is an Attr that is already an attribute of another Element object.
    21692142    // The DOM user must explicitly clone Attr nodes to re-use them in other elements.
    2170     if (attrNode.ownerElement() && attrNode.ownerElement() != this) {
    2171         ec = INUSE_ATTRIBUTE_ERR;
    2172         return nullptr;
    2173     }
     2143    if (attrNode.ownerElement() && attrNode.ownerElement() != this)
     2144        return Exception { INUSE_ATTRIBUTE_ERR };
    21742145
    21752146    synchronizeAllAttributes();
    2176     UniqueElementData& elementData = ensureUniqueElementData();
    2177 
    2178     unsigned existingAttributeIndex = elementData.findAttributeIndexByName(attrNode.qualifiedName().localName(), shouldIgnoreAttributeCase(*this));
    2179     if (existingAttributeIndex != ElementData::attributeNotFound) {
     2147    auto& elementData = ensureUniqueElementData();
     2148
     2149    auto existingAttributeIndex = elementData.findAttributeIndexByName(attrNode.qualifiedName().localName(), shouldIgnoreAttributeCase(*this));
     2150    if (existingAttributeIndex == ElementData::attributeNotFound)
     2151        setAttributeInternal(elementData.findAttributeIndexByName(attrNode.qualifiedName()), attrNode.qualifiedName(), attrNode.value(), NotInSynchronizationOfLazyAttribute);
     2152    else {
    21802153        const Attribute& attribute = attributeAt(existingAttributeIndex);
    21812154        if (oldAttrNode)
     
    21882161        else {
    21892162            removeAttributeInternal(existingAttributeIndex, NotInSynchronizationOfLazyAttribute);
    2190             unsigned existingAttributeIndexForFullQualifiedName = elementData.findAttributeIndexByName(attrNode.qualifiedName());
    2191             setAttributeInternal(existingAttributeIndexForFullQualifiedName, attrNode.qualifiedName(), attrNode.value(), NotInSynchronizationOfLazyAttribute);
     2163            setAttributeInternal(elementData.findAttributeIndexByName(attrNode.qualifiedName()), attrNode.qualifiedName(), attrNode.value(), NotInSynchronizationOfLazyAttribute);
    21922164        }
    2193     } else {
    2194         unsigned existingAttributeIndexForFullQualifiedName = elementData.findAttributeIndexByName(attrNode.qualifiedName());
    2195         setAttributeInternal(existingAttributeIndexForFullQualifiedName, attrNode.qualifiedName(), attrNode.value(), NotInSynchronizationOfLazyAttribute);
    21962165    }
    21972166    if (attrNode.ownerElement() != this) {
     
    22002169        ensureAttrNodeListForElement(*this).append(&attrNode);
    22012170    }
    2202     return oldAttrNode;
    2203 }
    2204 
    2205 RefPtr<Attr> Element::setAttributeNodeNS(Attr& attrNode, ExceptionCode& ec)
     2171    return WTFMove(oldAttrNode);
     2172}
     2173
     2174ExceptionOr<RefPtr<Attr>> Element::setAttributeNodeNS(Attr& attrNode)
    22062175{
    22072176    RefPtr<Attr> oldAttrNode = attrIfExists(attrNode.qualifiedName());
    22082177    if (oldAttrNode.get() == &attrNode)
    2209         return &attrNode; // This Attr is already attached to the element.
     2178        return WTFMove(oldAttrNode);
    22102179
    22112180    // INUSE_ATTRIBUTE_ERR: Raised if node is an Attr that is already an attribute of another Element object.
    22122181    // The DOM user must explicitly clone Attr nodes to re-use them in other elements.
    2213     if (attrNode.ownerElement() && attrNode.ownerElement() != this) {
    2214         ec = INUSE_ATTRIBUTE_ERR;
    2215         return nullptr;
    2216     }
     2182    if (attrNode.ownerElement() && attrNode.ownerElement() != this)
     2183        return Exception { INUSE_ATTRIBUTE_ERR };
    22172184
    22182185    synchronizeAllAttributes();
    2219     UniqueElementData& elementData = ensureUniqueElementData();
    2220 
    2221     unsigned index = elementData.findAttributeIndexByName(attrNode.qualifiedName());
     2186    auto& elementData = ensureUniqueElementData();
     2187
     2188    auto index = elementData.findAttributeIndexByName(attrNode.qualifiedName());
    22222189    if (index != ElementData::attributeNotFound) {
    22232190        if (oldAttrNode)
     
    22332200    ensureAttrNodeListForElement(*this).append(&attrNode);
    22342201
    2235     return oldAttrNode;
    2236 }
    2237 
    2238 RefPtr<Attr> Element::removeAttributeNode(Attr& attr, ExceptionCode& ec)
    2239 {
    2240     if (attr.ownerElement() != this) {
    2241         ec = NOT_FOUND_ERR;
    2242         return nullptr;
    2243     }
     2202    return WTFMove(oldAttrNode);
     2203}
     2204
     2205ExceptionOr<Ref<Attr>> Element::removeAttributeNode(Attr& attr)
     2206{
     2207    if (attr.ownerElement() != this)
     2208        return Exception { NOT_FOUND_ERR };
    22442209
    22452210    ASSERT(&document() == &attr.document());
     
    22472212    synchronizeAllAttributes();
    22482213
    2249     if (!m_elementData) {
    2250         ec = NOT_FOUND_ERR;
    2251         return nullptr;
    2252     }
    2253 
    2254     unsigned existingAttributeIndex = m_elementData->findAttributeIndexByName(attr.qualifiedName());
    2255 
    2256     if (existingAttributeIndex == ElementData::attributeNotFound) {
    2257         ec = NOT_FOUND_ERR;
    2258         return nullptr;
    2259     }
    2260 
    2261     RefPtr<Attr> attrNode = &attr;
     2214    if (!m_elementData)
     2215        return Exception { NOT_FOUND_ERR };
     2216
     2217    auto existingAttributeIndex = m_elementData->findAttributeIndexByName(attr.qualifiedName());
     2218    if (existingAttributeIndex == ElementData::attributeNotFound)
     2219        return Exception { NOT_FOUND_ERR };
     2220
     2221    Ref<Attr> oldAttrNode { attr };
     2222
    22622223    detachAttrNodeFromElementWithValue(&attr, m_elementData->attributeAt(existingAttributeIndex).value());
    22632224    removeAttributeInternal(existingAttributeIndex, NotInSynchronizationOfLazyAttribute);
    2264     return attrNode;
    2265 }
    2266 
    2267 bool Element::parseAttributeName(QualifiedName& out, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionCode& ec)
    2268 {
     2225
     2226    return WTFMove(oldAttrNode);
     2227}
     2228
     2229ExceptionOr<QualifiedName> Element::parseAttributeName(const AtomicString& namespaceURI, const AtomicString& qualifiedName)
     2230{
     2231    ExceptionCode ec = 0;
    22692232    String prefix, localName;
    22702233    if (!Document::parseQualifiedName(qualifiedName, prefix, localName, ec))
    2271         return false;
     2234        return Exception { ec };
    22722235    ASSERT(!ec);
    22732236
    2274     QualifiedName qName(prefix, localName, namespaceURI);
    2275 
    2276     if (!Document::hasValidNamespaceForAttributes(qName)) {
    2277         ec = NAMESPACE_ERR;
    2278         return false;
    2279     }
    2280 
    2281     out = qName;
    2282     return true;
    2283 }
    2284 
    2285 void Element::setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode& ec)
    2286 {
    2287     QualifiedName parsedName = anyName;
    2288     if (!parseAttributeName(parsedName, namespaceURI, qualifiedName, ec))
    2289         return;
    2290     setAttribute(parsedName, value);
     2237    QualifiedName result { prefix, localName, namespaceURI };
     2238
     2239    if (!Document::hasValidNamespaceForAttributes(result))
     2240        return Exception { NAMESPACE_ERR };
     2241
     2242    return WTFMove(result);
     2243}
     2244
     2245ExceptionOr<void> Element::setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value)
     2246{
     2247    auto result = parseAttributeName(namespaceURI, qualifiedName);
     2248    if (result.hasException())
     2249        return result.releaseException();
     2250    setAttribute(result.releaseReturnValue(), value);
     2251    return { };
    22912252}
    22922253
     
    25562517}
    25572518
    2558 void Element::mergeWithNextTextNode(Text& node, ExceptionCode& ec)
     2519ExceptionOr<void> Element::mergeWithNextTextNode(Text& node)
    25592520{
    25602521    auto* next = node.nextSibling();
    25612522    if (!is<Text>(next))
    2562         return;
     2523        return { };
    25632524    Ref<Text> textNext { downcast<Text>(*next) };
    2564 
    25652525    node.appendData(textNext->data());
    2566     auto result = textNext->remove();
    2567     if (result.hasException())
    2568         ec = result.releaseException().code();
     2526    return textNext->remove();
    25692527}
    25702528
     
    25792537}
    25802538
    2581 void Element::setOuterHTML(const String& html, ExceptionCode& ec)
    2582 {
    2583     Element* p = parentElement();
    2584     if (!is<HTMLElement>(p)) {
    2585         ec = NO_MODIFICATION_ALLOWED_ERR;
    2586         return;
    2587     }
    2588     RefPtr<HTMLElement> parent = downcast<HTMLElement>(p);
     2539ExceptionOr<void> Element::setOuterHTML(const String& html)
     2540{
     2541    auto* parentElement = this->parentElement();
     2542    if (!is<HTMLElement>(parentElement))
     2543        return Exception { NO_MODIFICATION_ALLOWED_ERR };
     2544
     2545    Ref<HTMLElement> parent = downcast<HTMLElement>(*parentElement);
    25892546    RefPtr<Node> prev = previousSibling();
    25902547    RefPtr<Node> next = nextSibling();
    25912548
    2592     auto fragment = createFragmentForInnerOuterHTML(*parent, html, AllowScriptingContent);
    2593     if (fragment.hasException()) {
    2594         ec = fragment.releaseException().code();
    2595         return;
    2596     }
    2597    
     2549    auto fragment = createFragmentForInnerOuterHTML(parent, html, AllowScriptingContent);
     2550    if (fragment.hasException())
     2551        return fragment.releaseException();
     2552
     2553    ExceptionCode ec = 0;
    25982554    parent->replaceChild(fragment.releaseReturnValue().get(), *this, ec);
     2555    if (ec)
     2556        return Exception { ec };
     2557
    25992558    RefPtr<Node> node = next ? next->previousSibling() : nullptr;
    2600     if (!ec && is<Text>(node.get()))
    2601         mergeWithNextTextNode(downcast<Text>(*node), ec);
    2602     if (!ec && is<Text>(prev.get()))
    2603         mergeWithNextTextNode(downcast<Text>(*prev), ec);
    2604 }
    2605 
    2606 
    2607 void Element::setInnerHTML(const String& html, ExceptionCode& ec)
     2559    if (is<Text>(node.get())) {
     2560        auto result = mergeWithNextTextNode(downcast<Text>(*node));
     2561        if (result.hasException())
     2562            return result.releaseException();
     2563    }
     2564    if (is<Text>(prev.get())) {
     2565        auto result = mergeWithNextTextNode(downcast<Text>(*prev));
     2566        if (result.hasException())
     2567            return result.releaseException();
     2568    }
     2569    return { };
     2570}
     2571
     2572
     2573ExceptionOr<void> Element::setInnerHTML(const String& html)
    26082574{
    26092575    auto fragment = createFragmentForInnerOuterHTML(*this, html, AllowScriptingContent);
    2610     if (fragment.hasException()) {
    2611         ec = fragment.releaseException().code();
    2612         return;
    2613     }
     2576    if (fragment.hasException())
     2577        return fragment.releaseException();
    26142578
    26152579    ContainerNode* container;
     
    26192583        container = &downcast<HTMLTemplateElement>(*this).content();
    26202584
    2621     auto result = replaceChildrenWithFragment(*container, fragment.releaseReturnValue());
    2622     if (result.hasException())
    2623         ec = fragment.releaseException().code();
     2585    return replaceChildrenWithFragment(*container, fragment.releaseReturnValue());
    26242586}
    26252587
     
    29942956}
    29952957
    2996 bool Element::matches(const String& selector, ExceptionCode& ec)
    2997 {
    2998     SelectorQuery* selectorQuery = document().selectorQueryForString(selector, ec);
    2999     return selectorQuery && selectorQuery->matches(*this);
    3000 }
    3001 
    3002 Element* Element::closest(const String& selector, ExceptionCode& ec)
    3003 {
    3004     SelectorQuery* selectorQuery = document().selectorQueryForString(selector, ec);
    3005     if (selectorQuery)
    3006         return selectorQuery->closest(*this);
    3007     return nullptr;
     2958ExceptionOr<bool> Element::matches(const String& selector)
     2959{
     2960    ExceptionCode ec = 0;
     2961    auto* query = document().selectorQueryForString(selector, ec);
     2962    if (ec)
     2963        return Exception { ec };
     2964    return query && query->matches(*this);
     2965}
     2966
     2967ExceptionOr<Element*> Element::closest(const String& selector)
     2968{
     2969    ExceptionCode ec = 0;
     2970    auto* query = document().selectorQueryForString(selector, ec);
     2971    if (ec)
     2972        return Exception { ec };
     2973    if (!query)
     2974        return nullptr;
     2975    return query->closest(*this);
    30082976}
    30092977
     
    30803048
    30813049#if ENABLE(INDIE_UI)
     3050
    30823051void Element::setUIActions(const AtomicString& actions)
    30833052{
     
    30893058    return getAttribute(uiactionsAttr);
    30903059}
     3060
    30913061#endif
    30923062
     
    36843654}
    36853655
    3686 Node* Element::insertAdjacent(const String& where, Ref<Node>&& newChild, ExceptionCode& ec)
     3656ExceptionOr<Node*> Element::insertAdjacent(const String& where, Ref<Node>&& newChild)
    36873657{
    36883658    // In Internet Explorer if the element has no parent and where is "beforeBegin" or "afterEnd",
     
    36943664
    36953665    if (equalLettersIgnoringASCIICase(where, "beforebegin")) {
    3696         ContainerNode* parent = this->parentNode();
    3697         return (parent && parent->insertBefore(newChild, this, ec)) ? newChild.ptr() : nullptr;
    3698     }
    3699 
    3700     if (equalLettersIgnoringASCIICase(where, "afterbegin"))
    3701         return insertBefore(newChild, firstChild(), ec) ? newChild.ptr() : nullptr;
    3702 
    3703     if (equalLettersIgnoringASCIICase(where, "beforeend"))
    3704         return appendChild(newChild, ec) ? newChild.ptr() : nullptr;
     3666        auto* parent = this->parentNode();
     3667        if (!parent)
     3668            return nullptr;
     3669        ExceptionCode ec = 0;
     3670        bool success = parent->insertBefore(newChild, this, ec);
     3671        if (ec)
     3672            return Exception { ec };
     3673        return success ? newChild.ptr() : nullptr;
     3674    }
     3675
     3676    if (equalLettersIgnoringASCIICase(where, "afterbegin")) {
     3677        ExceptionCode ec = 0;
     3678        bool success = insertBefore(newChild, firstChild(), ec);
     3679        if (ec)
     3680            return Exception { ec };
     3681        return success ? newChild.ptr() : nullptr;
     3682    }
     3683
     3684    if (equalLettersIgnoringASCIICase(where, "beforeend")) {
     3685        ExceptionCode ec = 0;
     3686        bool success = appendChild(newChild, ec);
     3687        if (ec)
     3688            return Exception { ec };
     3689        return success ? newChild.ptr() : nullptr;
     3690    }
    37053691
    37063692    if (equalLettersIgnoringASCIICase(where, "afterend")) {
    3707         ContainerNode* parent = this->parentNode();
    3708         return (parent && parent->insertBefore(newChild, nextSibling(), ec)) ? newChild.ptr() : nullptr;
    3709     }
    3710 
    3711     ec = SYNTAX_ERR;
    3712     return nullptr;
    3713 }
    3714 
    3715 Element* Element::insertAdjacentElement(const String& where, Element& newChild, ExceptionCode& ec)
    3716 {
    3717     Node* returnValue = insertAdjacent(where, newChild, ec);
    3718     ASSERT_WITH_SECURITY_IMPLICATION(!returnValue || is<Element>(*returnValue));
    3719     return downcast<Element>(returnValue);
     3693        auto* parent = this->parentNode();
     3694        if (!parent)
     3695            return nullptr;
     3696        ExceptionCode ec = 0;
     3697        bool success = parent->insertBefore(newChild, nextSibling(), ec);
     3698        if (ec)
     3699            return Exception { ec };
     3700        return success ? newChild.ptr() : nullptr;
     3701    }
     3702
     3703    return Exception { SYNTAX_ERR };
     3704}
     3705
     3706ExceptionOr<Element*> Element::insertAdjacentElement(const String& where, Element& newChild)
     3707{
     3708    auto result = insertAdjacent(where, newChild);
     3709    if (result.hasException())
     3710        return result.releaseException();
     3711    return downcast<Element>(result.releaseReturnValue());
    37203712}
    37213713
    37223714// Step 1 of https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml.
    3723 static ContainerNode* contextNodeForInsertion(const String& where, Element* element, ExceptionCode& ec)
     3715static ExceptionOr<ContainerNode*> contextNodeForInsertion(const String& where, Element& element)
    37243716{
    37253717    if (equalLettersIgnoringASCIICase(where, "beforebegin") || equalLettersIgnoringASCIICase(where, "afterend")) {
    3726         auto* parent = element->parentNode();
    3727         if (!parent || is<Document>(*parent)) {
    3728             ec = NO_MODIFICATION_ALLOWED_ERR;
    3729             return nullptr;
    3730         }
     3718        auto* parent = element.parentNode();
     3719        if (!parent || is<Document>(*parent))
     3720            return Exception { NO_MODIFICATION_ALLOWED_ERR };
    37313721        return parent;
    37323722    }
    37333723    if (equalLettersIgnoringASCIICase(where, "afterbegin") || equalLettersIgnoringASCIICase(where, "beforeend"))
    3734         return element;
    3735     ec =  SYNTAX_ERR;
    3736     return nullptr;
     3724        return &element;
     3725    return Exception { SYNTAX_ERR };
     3726}
     3727
     3728// Step 2 of https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml.
     3729static ExceptionOr<Ref<Element>> contextElementForInsertion(const String& where, Element& element)
     3730{
     3731    auto contextNodeResult = contextNodeForInsertion(where, element);
     3732    if (contextNodeResult.hasException())
     3733        return contextNodeResult.releaseException();
     3734    auto& contextNode = *contextNodeResult.releaseReturnValue();
     3735    if (!is<Element>(contextNode) || (contextNode.document().isHTMLDocument() && is<HTMLHtmlElement>(contextNode)))
     3736        return Ref<Element> { HTMLBodyElement::create(contextNode.document()) };
     3737    return Ref<Element> { downcast<Element>(contextNode) };
    37373738}
    37383739
    37393740// https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml
    3740 void Element::insertAdjacentHTML(const String& where, const String& markup, ExceptionCode& ec)
    3741 {
    3742     // Step 1.
    3743     auto* contextNode = contextNodeForInsertion(where, this, ec);
    3744     if (!contextNode)
    3745         return;
    3746     RefPtr<Element> contextElement;
    3747     // Step 2.
    3748     if (!is<Element>(*contextNode)
    3749         || (contextNode->document().isHTMLDocument() && is<HTMLHtmlElement>(*contextNode))) {
    3750         contextElement = HTMLBodyElement::create(contextNode->document());
    3751     } else
    3752         contextElement = downcast<Element>(contextNode);
     3741ExceptionOr<void> Element::insertAdjacentHTML(const String& where, const String& markup)
     3742{
     3743    // Steps 1 and 2.
     3744    auto contextElement = contextElementForInsertion(where, *this);
     3745    if (contextElement.hasException())
     3746        return contextElement.releaseException();
    37533747    // Step 3.
    3754     auto fragment = createFragmentForInnerOuterHTML(*contextElement, markup, AllowScriptingContent);
    3755     if (fragment.hasException()) {
    3756         ec = fragment.releaseException().code();
    3757         return;
    3758     }
     3748    auto fragment = createFragmentForInnerOuterHTML(contextElement.releaseReturnValue(), markup, AllowScriptingContent);
     3749    if (fragment.hasException())
     3750        return fragment.releaseException();
    37593751    // Step 4.
    3760     insertAdjacent(where, fragment.releaseReturnValue(), ec);
    3761 }
    3762 
    3763 void Element::insertAdjacentText(const String& where, const String& text, ExceptionCode& ec)
    3764 {
    3765     insertAdjacent(where, document().createTextNode(text), ec);
     3752    auto result = insertAdjacent(where, fragment.releaseReturnValue());
     3753    if (result.hasException())
     3754        return result.releaseException();
     3755    return { };
     3756}
     3757
     3758ExceptionOr<void> Element::insertAdjacentText(const String& where, const String& text)
     3759{
     3760    auto result = insertAdjacent(where, document().createTextNode(text));
     3761    if (result.hasException())
     3762        return result.releaseException();
     3763    return { };
    37663764}
    37673765
  • trunk/Source/WebCore/dom/Element.h

    r208001 r208135  
    2323 */
    2424
    25 #ifndef Element_h
    26 #define Element_h
     25#pragma once
    2726
    2827#include "AXTextStateChangeIntent.h"
     
    113112    WEBCORE_EXPORT const AtomicString& getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
    114113
    115     WEBCORE_EXPORT void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionCode&);
    116     static bool parseAttributeName(QualifiedName&, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionCode&);
    117     WEBCORE_EXPORT void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode&);
     114    WEBCORE_EXPORT ExceptionOr<void> setAttribute(const AtomicString& name, const AtomicString& value);
     115    static ExceptionOr<QualifiedName> parseAttributeName(const AtomicString& namespaceURI, const AtomicString& qualifiedName);
     116    WEBCORE_EXPORT ExceptionOr<void> setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value);
    118117
    119118    const AtomicString& getIdAttribute() const;
     
    191190    WEBCORE_EXPORT RefPtr<Attr> getAttributeNode(const AtomicString& name);
    192191    WEBCORE_EXPORT RefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
    193     WEBCORE_EXPORT RefPtr<Attr> setAttributeNode(Attr&, ExceptionCode&);
    194     WEBCORE_EXPORT RefPtr<Attr> setAttributeNodeNS(Attr&, ExceptionCode&);
    195     WEBCORE_EXPORT RefPtr<Attr> removeAttributeNode(Attr&, ExceptionCode&);
     192    WEBCORE_EXPORT ExceptionOr<RefPtr<Attr>> setAttributeNode(Attr&);
     193    WEBCORE_EXPORT ExceptionOr<RefPtr<Attr>> setAttributeNodeNS(Attr&);
     194    WEBCORE_EXPORT ExceptionOr<Ref<Attr>> removeAttributeNode(Attr&);
    196195
    197196    RefPtr<Attr> attrIfExists(const QualifiedName&);
     
    270269
    271270    WEBCORE_EXPORT ShadowRoot* shadowRoot() const;
    272     WEBCORE_EXPORT ShadowRoot* createShadowRoot(ExceptionCode&);
     271    ShadowRoot* shadowRootForBindings(JSC::ExecState&) const;
    273272
    274273    struct ShadowRootInit {
    275274        ShadowRootMode mode;
    276275    };
    277 
    278     ShadowRoot* shadowRootForBindings(JSC::ExecState&) const;
    279     RefPtr<ShadowRoot> attachShadow(const ShadowRootInit&, ExceptionCode&);
     276    ExceptionOr<Ref<ShadowRoot>> attachShadow(const ShadowRootInit&);
    280277
    281278    ShadowRoot* userAgentShadowRoot() const;
     
    316313    virtual Element* focusDelegate();
    317314
    318     WEBCORE_EXPORT Element* insertAdjacentElement(const String& where, Element& newChild, ExceptionCode&);
    319     WEBCORE_EXPORT void insertAdjacentHTML(const String& where, const String& html, ExceptionCode&);
    320     WEBCORE_EXPORT void insertAdjacentText(const String& where, const String& text, ExceptionCode&);
     315    WEBCORE_EXPORT ExceptionOr<Element*> insertAdjacentElement(const String& where, Element& newChild);
     316    WEBCORE_EXPORT ExceptionOr<void> insertAdjacentHTML(const String& where, const String& html);
     317    WEBCORE_EXPORT ExceptionOr<void> insertAdjacentText(const String& where, const String& text);
    321318
    322319    bool ieForbidsInsertHTML() const;
     
    381378    WEBCORE_EXPORT String innerHTML() const;
    382379    WEBCORE_EXPORT String outerHTML() const;
    383     WEBCORE_EXPORT void setInnerHTML(const String&, ExceptionCode&);
    384     WEBCORE_EXPORT void setOuterHTML(const String&, ExceptionCode&);
     380    WEBCORE_EXPORT ExceptionOr<void> setInnerHTML(const String&);
     381    WEBCORE_EXPORT ExceptionOr<void> setOuterHTML(const String&);
    385382    WEBCORE_EXPORT String innerText();
    386383    WEBCORE_EXPORT String outerText();
     
    430427    virtual bool matchesIndeterminatePseudoClass() const;
    431428    virtual bool matchesDefaultPseudoClass() const;
    432     WEBCORE_EXPORT bool matches(const String& selectors, ExceptionCode&);
    433     WEBCORE_EXPORT Element* closest(const String& selectors, ExceptionCode&);
     429    WEBCORE_EXPORT ExceptionOr<bool> matches(const String& selectors);
     430    WEBCORE_EXPORT ExceptionOr<Element*> closest(const String& selectors);
    434431    virtual bool shouldAppearIndeterminate() const;
    435432
     
    602599    void addShadowRoot(Ref<ShadowRoot>&&);
    603600
    604     static void mergeWithNextTextNode(Text& node, ExceptionCode&);
     601    static ExceptionOr<void> mergeWithNextTextNode(Text&);
    605602
    606603private:
     
    640637    void updateLabel(TreeScope&, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
    641638
    642     Node* insertAdjacent(const String& where, Ref<Node>&& newChild, ExceptionCode&);
     639    ExceptionOr<Node*> insertAdjacent(const String& where, Ref<Node>&& newChild);
    643640
    644641    void scrollByUnits(int units, ScrollGranularity);
     
    839836    static bool isType(const WebCore::Node& node) { return node.isElementNode(); }
    840837SPECIALIZE_TYPE_TRAITS_END()
    841 
    842 #endif
  • trunk/Source/WebCore/dom/Element.idl

    r208082 r208135  
    2929    DOMString? getAttribute(DOMString name);
    3030
    31     [CEReactions, MayThrowLegacyException] void setAttribute(DOMString name, DOMString value);
     31    [CEReactions, MayThrowException] void setAttribute(DOMString name, DOMString value);
    3232
    3333    [CEReactions] void removeAttribute(DOMString name);
    3434    Attr? getAttributeNode(DOMString name);
    3535
    36     [CEReactions, MayThrowLegacyException] Attr? setAttributeNode(Attr newAttr);
    37     [CEReactions, MayThrowLegacyException] Attr removeAttributeNode(Attr oldAttr);
     36    [CEReactions, MayThrowException] Attr? setAttributeNode(Attr newAttr);
     37    [CEReactions, MayThrowException] Attr removeAttributeNode(Attr oldAttr);
    3838
    3939    HTMLCollection getElementsByTagName(DOMString name);
     
    4444    DOMString? getAttributeNS(DOMString? namespaceURI, DOMString localName);
    4545
    46     [CEReactions, MayThrowLegacyException] void setAttributeNS(DOMString? namespaceURI, DOMString qualifiedName, DOMString value);
     46    [CEReactions, MayThrowException] void setAttributeNS(DOMString? namespaceURI, DOMString qualifiedName, DOMString value);
    4747    [CEReactions] void removeAttributeNS(DOMString? namespaceURI, DOMString localName);
    4848
     
    5050
    5151    Attr? getAttributeNodeNS(DOMString? namespaceURI, DOMString localName);
    52     [CEReactions, MayThrowLegacyException] Attr? setAttributeNodeNS(Attr newAttr);
     52    [CEReactions, MayThrowException] Attr? setAttributeNodeNS(Attr newAttr);
    5353    boolean hasAttribute(DOMString name);
    5454
     
    9898
    9999    HTMLCollection getElementsByClassName(DOMString name);
    100     [CEReactions, TreatNullAs=EmptyString, SetterMayThrowLegacyException] attribute DOMString innerHTML;
    101     [CEReactions, TreatNullAs=EmptyString, SetterMayThrowLegacyException] attribute DOMString outerHTML;
     100    [CEReactions, TreatNullAs=EmptyString, SetterMayThrowException] attribute DOMString innerHTML;
     101    [CEReactions, TreatNullAs=EmptyString, SetterMayThrowException] attribute DOMString outerHTML;
    102102
    103103    [CEReactions, Reflect=class] attribute DOMString className;
    104104    [PutForwards=value] readonly attribute DOMTokenList classList;
    105105
    106     [MayThrowLegacyException] boolean matches(DOMString selectors);
    107     [MayThrowLegacyException] Element closest(DOMString selectors);   
    108     [ImplementedAs=matches, MayThrowLegacyException] boolean webkitMatchesSelector(DOMString selectors);
     106    [MayThrowException] boolean matches(DOMString selectors);
     107    [MayThrowException] Element closest(DOMString selectors);
     108    [ImplementedAs=matches, MayThrowException] boolean webkitMatchesSelector(DOMString selectors);
    109109
    110110    // CSSOM View Module API
     
    125125#endif
    126126
    127     [CEReactions, MayThrowLegacyException] Element insertAdjacentElement(DOMString where, Element element);
    128     [CEReactions, MayThrowLegacyException] void insertAdjacentHTML(DOMString where, DOMString html);
    129     [MayThrowLegacyException] void insertAdjacentText(DOMString where, DOMString text);
     127    [CEReactions, MayThrowException] Element insertAdjacentElement(DOMString where, Element element);
     128    [CEReactions, MayThrowException] void insertAdjacentHTML(DOMString where, DOMString html);
     129    [MayThrowException] void insertAdjacentText(DOMString where, DOMString text);
    130130
    131131    [Conditional=POINTER_LOCK] void requestPointerLock();
     
    136136
    137137    // Shadow DOM API
    138     [EnabledAtRuntime=ShadowDOM, MayThrowLegacyException] ShadowRoot attachShadow(ShadowRootInit init);
     138    [EnabledAtRuntime=ShadowDOM, MayThrowException] ShadowRoot attachShadow(ShadowRootInit init);
    139139    [EnabledAtRuntime=ShadowDOM, ImplementedAs=shadowRootForBindings, CallWith=ScriptState] readonly attribute ShadowRoot shadowRoot;
    140140    [CEReactions, EnabledAtRuntime=ShadowDOM, Reflect] attribute DOMString slot;
  • trunk/Source/WebCore/dom/NamedNodeMap.cpp

    r204115 r208135  
    2727
    2828#include "Attr.h"
    29 #include "Element.h"
    3029#include "ExceptionCode.h"
    3130#include "HTMLDocument.h"
     
    5655}
    5756
    58 RefPtr<Attr> NamedNodeMap::removeNamedItem(const AtomicString& name, ExceptionCode& ec)
     57ExceptionOr<Ref<Attr>> NamedNodeMap::removeNamedItem(const AtomicString& name)
    5958{
    60     unsigned index = m_element.hasAttributes() ? m_element.findAttributeIndexByName(name, shouldIgnoreAttributeCase(m_element)) : ElementData::attributeNotFound;
    61     if (index == ElementData::attributeNotFound) {
    62         ec = NOT_FOUND_ERR;
    63         return nullptr;
    64     }
     59    if (!m_element.hasAttributes())
     60        return Exception { NOT_FOUND_ERR };
     61    auto index = m_element.findAttributeIndexByName(name, shouldIgnoreAttributeCase(m_element));
     62    if (index == ElementData::attributeNotFound)
     63        return Exception { NOT_FOUND_ERR };
    6564    return m_element.detachAttribute(index);
    6665}
    6766
    68 Vector<String> NamedNodeMap::supportedPropertyNames()
     67Vector<String> NamedNodeMap::supportedPropertyNames() const
    6968{
    7069    Vector<String> names = m_element.getAttributeNames();
    7170    if (is<HTMLElement>(m_element) && is<HTMLDocument>(m_element.document())) {
    7271        names.removeAllMatching([](String& name) {
    73             return name.convertToASCIILowercase() != name;
     72            for (auto character : StringView { name }.codeUnits()) {
     73                if (isASCIIUpper(character))
     74                    return true;
     75            }
     76            return false;
    7477        });
    7578    }
     
    7780}
    7881
    79 RefPtr<Attr> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionCode& ec)
     82ExceptionOr<Ref<Attr>> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName)
    8083{
    81     unsigned index = m_element.hasAttributes() ? m_element.findAttributeIndexByName(QualifiedName(nullAtom, localName, namespaceURI)) : ElementData::attributeNotFound;
    82     if (index == ElementData::attributeNotFound) {
    83         ec = NOT_FOUND_ERR;
    84         return nullptr;
    85     }
     84    if (!m_element.hasAttributes())
     85        return Exception { NOT_FOUND_ERR };
     86    auto index = m_element.findAttributeIndexByName(QualifiedName { nullAtom, localName, namespaceURI });
     87    if (index == ElementData::attributeNotFound)
     88        return Exception { NOT_FOUND_ERR };
    8689    return m_element.detachAttribute(index);
    8790}
    8891
    89 RefPtr<Attr> NamedNodeMap::setNamedItem(Attr& attr, ExceptionCode& ec)
     92ExceptionOr<RefPtr<Attr>> NamedNodeMap::setNamedItem(Attr& attr)
    9093{
    91     return m_element.setAttributeNode(attr, ec);
    92 }
    93 
    94 RefPtr<Attr> NamedNodeMap::setNamedItem(Node& node, ExceptionCode& ec)
    95 {
    96     if (!is<Attr>(node)) {
    97         ec = TypeError;
    98         return nullptr;
    99     }
    100     return setNamedItem(downcast<Attr>(node), ec);
     94    return m_element.setAttributeNode(attr);
    10195}
    10296
     
    10498{
    10599    if (index >= length())
    106         return 0;
     100        return nullptr;
    107101    return m_element.ensureAttr(m_element.attributeAt(index).name());
    108102}
  • trunk/Source/WebCore/dom/NamedNodeMap.h

    r204717 r208135  
    2525#pragma once
    2626
    27 #include "Attr.h"
     27#include "ExceptionOr.h"
     28#include "ScriptWrappable.h"
    2829
    2930namespace WebCore {
    3031
     32class Attr;
     33class Element;
     34
    3135class NamedNodeMap : public ScriptWrappable {
    3236    WTF_MAKE_FAST_ALLOCATED;
    33     friend class Element;
    3437public:
    3538    explicit NamedNodeMap(Element& element)
    3639        : m_element(element)
    3740    {
    38         // Only supports NamedNodeMaps with Element associated, DocumentType.entities and DocumentType.notations are not supported yet.
    3941    }
    4042
     
    4244    WEBCORE_EXPORT void deref();
    4345
    44     // Public DOM interface.
     46    WEBCORE_EXPORT unsigned length() const;
     47    WEBCORE_EXPORT RefPtr<Attr> item(unsigned index) const;
     48    WEBCORE_EXPORT RefPtr<Attr> getNamedItem(const AtomicString&) const;
     49    WEBCORE_EXPORT RefPtr<Attr> getNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
     50    WEBCORE_EXPORT ExceptionOr<RefPtr<Attr>> setNamedItem(Attr&);
     51    WEBCORE_EXPORT ExceptionOr<Ref<Attr>> removeNamedItem(const AtomicString& name);
     52    WEBCORE_EXPORT ExceptionOr<Ref<Attr>> removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName);
    4553
    46     WEBCORE_EXPORT RefPtr<Attr> getNamedItem(const AtomicString&) const;
    47     WEBCORE_EXPORT RefPtr<Attr> removeNamedItem(const AtomicString& name, ExceptionCode&);
    48     Vector<String> supportedPropertyNames();
     54    Vector<String> supportedPropertyNames() const;
    4955
    50     WEBCORE_EXPORT RefPtr<Attr> getNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
    51     WEBCORE_EXPORT RefPtr<Attr> removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionCode&);
    52 
    53     RefPtr<Attr> setNamedItem(Attr&, ExceptionCode&);
    54     WEBCORE_EXPORT RefPtr<Attr> setNamedItem(Node&, ExceptionCode&); // for legacy bindings.
    55 
    56     WEBCORE_EXPORT RefPtr<Attr> item(unsigned index) const;
    57     WEBCORE_EXPORT unsigned length() const;
    58 
    59     Element& element() const { return m_element; }
     56    Element& element() { return m_element; }
    6057
    6158private:
  • trunk/Source/WebCore/dom/NamedNodeMap.idl

    r207170 r208135  
    2525] interface NamedNodeMap {
    2626    readonly attribute unsigned long length;
    27 
     27    getter Attr? item(unsigned long index);
    2828    getter Attr? getNamedItem(DOMString name);
    29     [CEReactions, MayThrowLegacyException] Attr? setNamedItem(Attr attr);
    30     [CEReactions, MayThrowLegacyException] Attr removeNamedItem(DOMString name);
    31     getter Attr? item(unsigned long index);
    3229    Attr? getNamedItemNS(DOMString? namespaceURI, DOMString localName);
    33     [CEReactions, MayThrowLegacyException, ImplementedAs=setNamedItem] Attr? setNamedItemNS(Attr attr);
    34     [CEReactions, MayThrowLegacyException] Attr removeNamedItemNS(DOMString? namespaceURI, DOMString localName);
     30    [CEReactions, MayThrowException] Attr? setNamedItem(Attr attr);
     31    [CEReactions, MayThrowException, ImplementedAs=setNamedItem] Attr? setNamedItemNS(Attr attr);
     32    [CEReactions, MayThrowException] Attr removeNamedItem(DOMString name);
     33    [CEReactions, MayThrowException] Attr removeNamedItemNS(DOMString? namespaceURI, DOMString localName);
    3534};
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r208112 r208135  
    585585    RefPtr<Node> node = next ? next->previousSibling() : nullptr;
    586586    if (is<Text>(node.get())) {
    587         ExceptionCode ec = 0;
    588         mergeWithNextTextNode(downcast<Text>(*node), ec);
    589         if (ec)
    590             return Exception { ec };
     587        auto result = mergeWithNextTextNode(downcast<Text>(*node));
     588        if (result.hasException())
     589            return result.releaseException();
    591590    }
    592591    if (is<Text>(prev.get())) {
    593         ExceptionCode ec = 0;
    594         mergeWithNextTextNode(downcast<Text>(*prev), ec);
    595         if (ec)
    596             return Exception { ec };
     592        auto result = mergeWithNextTextNode(downcast<Text>(*prev));
     593        if (result.hasException())
     594            return result.releaseException();
    597595    }
    598596    return { };
  • trunk/Source/WebCore/inspector/DOMEditor.cpp

    r208118 r208135  
    139139    bool undo(ExceptionCode& ec) override
    140140    {
    141         m_element->setAttribute(m_name, m_value, ec);
     141        auto result = m_element->setAttribute(m_name, m_value);
     142        if (result.hasException())
     143            ec = result.releaseException().code();
    142144        return true;
    143145    }
     
    177179    bool undo(ExceptionCode& ec) override
    178180    {
    179         if (m_hadAttribute)
    180             m_element->setAttribute(m_name, m_oldValue, ec);
    181         else
     181        if (m_hadAttribute) {
     182            auto result = m_element->setAttribute(m_name, m_oldValue);
     183            if (result.hasException())
     184                ec = result.releaseException().code();
     185        } else
    182186            m_element->removeAttribute(m_name);
    183187        return true;
     
    186190    bool redo(ExceptionCode& ec) override
    187191    {
    188         m_element->setAttribute(m_name, m_value, ec);
     192        auto result = m_element->setAttribute(m_name, m_value);
     193        if (result.hasException())
     194            ec = result.releaseException().code();
    189195        return true;
    190196    }
  • trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp

    r208124 r208135  
    199199}
    200200
    201 String InspectorDOMAgent::toErrorString(const ExceptionCode& ec)
     201String InspectorDOMAgent::toErrorString(ExceptionCode ec)
    202202{
    203203    if (ec) {
     
    206206    }
    207207    return emptyString();
     208}
     209
     210String InspectorDOMAgent::toErrorString(Exception&& exception)
     211{
     212    return ExceptionCodeDescription { exception.code() }.name;
    208213}
    209214
     
    661666        return;
    662667
    663     RefPtr<HTMLElement> parsedElement = createHTMLElement(element->document(), spanTag);
    664     ExceptionCode ec = 0;
    665     parsedElement.get()->setInnerHTML("<span " + text + "></span>", ec);
    666     if (ec) {
    667         errorString = toErrorString(ec);
     668    auto parsedElement = createHTMLElement(element->document(), spanTag);
     669    auto result = parsedElement.get().setInnerHTML("<span " + text + "></span>");
     670    if (result.hasException()) {
     671        errorString = toErrorString(result.releaseException());
    668672        return;
    669673    }
  • trunk/Source/WebCore/inspector/InspectorDOMAgent.h

    r206093 r208135  
    6161class Element;
    6262class Event;
     63class Exception;
    6364class FloatQuad;
    6465class Frame;
     
    108109    virtual ~InspectorDOMAgent();
    109110
    110     static String toErrorString(const ExceptionCode&);
     111    static String toErrorString(ExceptionCode);
     112    static String toErrorString(Exception&&);
    111113
    112114    void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp

    r207767 r208135  
    13021302    {
    13031303        InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->document());
    1304         m_element->setAttribute("style", text, ec);
     1304        m_element->setAttribute(HTMLNames::styleAttr, text);
    13051305    }
    13061306
     
    13081308    m_isStyleTextValid = true;
    13091309    m_ruleSourceData = nullptr;
    1310     return !ec;
     1310
     1311    ec = 0;
     1312    return true;
    13111313}
    13121314
  • trunk/Source/WebCore/testing/Internals.cpp

    r208001 r208135  
    781781}
    782782
    783 ExceptionOr<Node*> Internals::ensureShadowRoot(Element& host)
    784 {
    785     if (ShadowRoot* shadowRoot = host.shadowRoot())
    786         return shadowRoot;
    787 
    788     ExceptionCode ec = 0;
    789     auto result = host.createShadowRoot(ec);
    790     if (ec)
    791         return Exception { ec };
    792     return result;
    793 }
    794 
    795783Node* Internals::ensureUserAgentShadowRoot(Element& host)
    796784{
    797785    return &host.ensureUserAgentShadowRoot();
    798 }
    799 
    800 ExceptionOr<Node*> Internals::createShadowRoot(Element& host)
    801 {
    802     ExceptionCode ec = 0;
    803     auto result = host.createShadowRoot(ec);
    804     if (ec)
    805         return Exception { ec };
    806     return result;
    807786}
    808787
  • trunk/Source/WebCore/testing/Internals.idl

    r207839 r208135  
    101101    CSSStyleDeclaration computedStyleIncludingVisitedInfo(Element element);
    102102
    103     [MayThrowException] Node ensureShadowRoot(Element host);
    104103    Node ensureUserAgentShadowRoot(Element host);
    105     [MayThrowException] Node createShadowRoot(Element host);
    106104    Node shadowRoot(Element host);
    107105
  • trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp

    r208096 r208135  
    740740            namespaceQName = "xmlns:" + toString(namespaces[i].prefix);
    741741
    742         QualifiedName parsedName = anyName;
    743         if (!Element::parseAttributeName(parsedName, XMLNSNames::xmlnsNamespaceURI, namespaceQName, ec))
     742        auto result = Element::parseAttributeName(XMLNSNames::xmlnsNamespaceURI, namespaceQName);
     743        if (result.hasException()) {
     744            ec = result.releaseException().code();
    744745            return;
    745        
    746         prefixedAttributes.append(Attribute(parsedName, namespaceURI));
     746        }
     747
     748        prefixedAttributes.append(Attribute(result.releaseReturnValue(), namespaceURI));
    747749    }
    748750}
     
    767769        AtomicString attrQName = attrPrefix.isEmpty() ? toAtomicString(attributes[i].localname) : attrPrefix + ":" + toString(attributes[i].localname);
    768770
    769         QualifiedName parsedName = anyName;
    770         if (!Element::parseAttributeName(parsedName, attrURI, attrQName, ec))
     771        auto result = Element::parseAttributeName(attrURI, attrQName);
     772        if (result.hasException()) {
     773            ec = result.releaseException().code();
    771774            return;
    772 
    773         prefixedAttributes.append(Attribute(parsedName, attrValue));
     775        }
     776
     777        prefixedAttributes.append(Attribute(result.releaseReturnValue(), attrValue));
    774778    }
    775779}
  • trunk/Source/WebKit/mac/ChangeLog

    r208118 r208135  
     12016-10-30  Darin Adler  <darin@apple.com>
     2
     3        Move Element, NamedNodeMap, and DOMStringMap from ExceptionCode to Exception
     4        https://bugs.webkit.org/show_bug.cgi?id=164206
     5
     6        Reviewed by Chris Dumez.
     7
     8        * DOM/DOMElement.mm:
     9        (-[DOMElement setInnerHTML:]): Updated exception handling.
     10        (-[DOMElement setOuterHTML:]): Ditto.
     11        (-[DOMElement setAttribute:value:]): Ditto.
     12        (-[DOMElement setAttributeNode:]): Ditto.
     13        (-[DOMElement removeAttributeNode:]): Ditto.
     14        (-[DOMElement setAttributeNS:qualifiedName:value:]): Ditto.
     15        (-[DOMElement setAttributeNodeNS:]): Ditto.
     16        (-[DOMElement matches:]): Ditto.
     17        (-[DOMElement closest:]): Ditto.
     18        (-[DOMElement webkitMatchesSelector:]): Ditto.
     19        * DOM/DOMHTMLElement.mm:
     20        (-[DOMHTMLElement insertAdjacentElement:element:]): Ditto.
     21        (-[DOMHTMLElement insertAdjacentHTML:html:]): Ditto.
     22        (-[DOMHTMLElement insertAdjacentText:text:]): Ditto.
     23        * DOM/DOMNamedNodeMap.mm:
     24        (-[DOMNamedNodeMap setNamedItem:]): Ditto.
     25        (-[DOMNamedNodeMap removeNamedItem:]): Ditto.
     26        (-[DOMNamedNodeMap setNamedItemNS:]): Ditto.
     27        (-[DOMNamedNodeMap removeNamedItemNS:localName:]): Ditto.
     28
    1292016-10-29  Darin Adler  <darin@apple.com>
    230
  • trunk/Source/WebKit/mac/DOM/DOMElement.mm

    r208096 r208135  
    178178{
    179179    JSMainThreadNullState state;
    180     ExceptionCode ec = 0;
    181     unwrap(*self).setInnerHTML(newInnerHTML, ec);
    182     raiseOnDOMError(ec);
     180    raiseOnDOMError(unwrap(*self).setInnerHTML(newInnerHTML));
    183181}
    184182
     
    192190{
    193191    JSMainThreadNullState state;
    194     ExceptionCode ec = 0;
    195     unwrap(*self).setOuterHTML(newOuterHTML, ec);
    196     raiseOnDOMError(ec);
     192    raiseOnDOMError(unwrap(*self).setOuterHTML(newOuterHTML));
    197193}
    198194
     
    286282{
    287283    JSMainThreadNullState state;
    288     ExceptionCode ec = 0;
    289     unwrap(*self).setAttribute(name, value, ec);
    290     raiseOnDOMError(ec);
     284    raiseOnDOMError(unwrap(*self).setAttribute(name, value));
    291285}
    292286
     
    308302    if (!newAttr)
    309303        raiseTypeErrorException();
    310     ExceptionCode ec = 0;
    311     DOMAttr *result = kit(unwrap(*self).setAttributeNode(*core(newAttr), ec).get());
    312     raiseOnDOMError(ec);
    313     return result;
     304    return kit(raiseOnDOMError(unwrap(*self).setAttributeNode(*core(newAttr))).get());
    314305}
    315306
     
    319310    if (!oldAttr)
    320311        raiseTypeErrorException();
    321     ExceptionCode ec = 0;
    322     DOMAttr *result = kit(unwrap(*self).removeAttributeNode(*core(oldAttr), ec).get());
    323     raiseOnDOMError(ec);
    324     return result;
     312    return kit(raiseOnDOMError(unwrap(*self).removeAttributeNode(*core(oldAttr))).ptr());
    325313}
    326314
     
    344332{
    345333    JSMainThreadNullState state;
    346     ExceptionCode ec = 0;
    347     unwrap(*self).setAttributeNS(namespaceURI, qualifiedName, value, ec);
    348     raiseOnDOMError(ec);
     334    raiseOnDOMError(unwrap(*self).setAttributeNS(namespaceURI, qualifiedName, value));
    349335}
    350336
     
    376362    if (!newAttr)
    377363        raiseTypeErrorException();
    378     ExceptionCode ec = 0;
    379     DOMAttr *result = kit(unwrap(*self).setAttributeNodeNS(*core(newAttr), ec).get());
    380     raiseOnDOMError(ec);
    381     return result;
     364    return kit(raiseOnDOMError(unwrap(*self).setAttributeNodeNS(*core(newAttr))).get());
    382365}
    383366
     
    440423{
    441424    JSMainThreadNullState state;
    442     ExceptionCode ec = 0;
    443     BOOL result = unwrap(*self).matches(selectors, ec);
    444     raiseOnDOMError(ec);
    445     return result;
     425    return raiseOnDOMError(unwrap(*self).matches(selectors));
    446426}
    447427
     
    449429{
    450430    JSMainThreadNullState state;
    451     ExceptionCode ec = 0;
    452     DOMElement *result = kit(unwrap(*self).closest(selectors, ec));
    453     raiseOnDOMError(ec);
    454     return result;
     431    return kit(raiseOnDOMError(unwrap(*self).closest(selectors)));
    455432}
    456433
     
    458435{
    459436    JSMainThreadNullState state;
    460     ExceptionCode ec = 0;
    461     BOOL result = unwrap(*self).matches(selectors, ec);
    462     raiseOnDOMError(ec);
    463     return result;
     437    return raiseOnDOMError(unwrap(*self).matches(selectors));
    464438}
    465439
  • trunk/Source/WebKit/mac/DOM/DOMHTMLElement.mm

    r208096 r208135  
    236236    if (!element)
    237237        raiseTypeErrorException();
    238     WebCore::ExceptionCode ec = 0;
    239     DOMElement *result = kit(WTF::getPtr(IMPL->insertAdjacentElement(where, *core(element), ec)));
    240     raiseOnDOMError(ec);
    241     return result;
     238    return kit(raiseOnDOMError(IMPL->insertAdjacentElement(where, *core(element))));
    242239}
    243240
     
    245242{
    246243    WebCore::JSMainThreadNullState state;
    247     WebCore::ExceptionCode ec = 0;
    248     IMPL->insertAdjacentHTML(where, html, ec);
    249     raiseOnDOMError(ec);
     244    raiseOnDOMError(IMPL->insertAdjacentHTML(where, html));
    250245}
    251246
     
    253248{
    254249    WebCore::JSMainThreadNullState state;
    255     WebCore::ExceptionCode ec = 0;
    256     IMPL->insertAdjacentText(where, text, ec);
    257     raiseOnDOMError(ec);
     250    raiseOnDOMError(IMPL->insertAdjacentText(where, text));
    258251}
    259252
  • trunk/Source/WebKit/mac/DOM/DOMNamedNodeMap.mm

    r204717 r208135  
    6969    if (!node)
    7070        raiseTypeErrorException();
    71     WebCore::ExceptionCode ec = 0;
    72     DOMNode *result = kit(WTF::getPtr(IMPL->setNamedItem(*core(node), ec)));
    73     raiseOnDOMError(ec);
    74     return result;
     71    auto& coreNode = *core(node);
     72    if (!is<WebCore::Attr>(coreNode))
     73        raiseTypeErrorException();
     74    return kit(raiseOnDOMError(IMPL->setNamedItem(downcast<WebCore::Attr>(coreNode))).get());
    7575}
    7676
     
    7878{
    7979    WebCore::JSMainThreadNullState state;
    80     WebCore::ExceptionCode ec = 0;
    81     DOMNode *result = kit(WTF::getPtr(IMPL->removeNamedItem(name, ec)));
    82     raiseOnDOMError(ec);
    83     return result;
     80    return kit(raiseOnDOMError(IMPL->removeNamedItem(name)).ptr());
    8481}
    8582
     
    9895- (DOMNode *)setNamedItemNS:(DOMNode *)node
    9996{
    100     WebCore::JSMainThreadNullState state;
    101     if (!node)
    102         raiseTypeErrorException();
    103     WebCore::ExceptionCode ec = 0;
    104     DOMNode *result = kit(WTF::getPtr(IMPL->setNamedItem(*core(node), ec)));
    105     raiseOnDOMError(ec);
    106     return result;
     97    return [self setNamedItem:node];
    10798}
    10899
     
    110101{
    111102    WebCore::JSMainThreadNullState state;
    112     WebCore::ExceptionCode ec = 0;
    113     DOMNode *result = kit(WTF::getPtr(IMPL->removeNamedItemNS(namespaceURI, localName, ec)));
    114     raiseOnDOMError(ec);
    115     return result;
     103    return kit(raiseOnDOMError(IMPL->removeNamedItemNS(namespaceURI, localName)).ptr());
    116104}
    117105
  • trunk/Source/WebKit/win/ChangeLog

    r208132 r208135  
     12016-10-30  Darin Adler  <darin@apple.com>
     2
     3        Move Element, NamedNodeMap, and DOMStringMap from ExceptionCode to Exception
     4        https://bugs.webkit.org/show_bug.cgi?id=164206
     5
     6        Reviewed by Chris Dumez.
     7
     8        * DOMCoreClasses.cpp:
     9        (DOMElement::setAttribute): Updated exception handling.
     10        * DOMHTMLClasses.cpp:
     11        (DOMHTMLElement::setInnerHTML): Ditto.
     12
    1132016-10-30  Brent Fulgham  <bfulgham@apple.com>
    214
  • trunk/Source/WebKit/win/DOMCoreClasses.cpp

    r207522 r208135  
    3232#include "WebKitGraphics.h"
    3333
     34#include <WebCore/Attr.h>
    3435#include <WebCore/BString.h>
    3536#include <WebCore/COMPtr.h>
     
    10711072    WTF::String nameString(name, SysStringLen(name));
    10721073    WTF::String valueString(value, SysStringLen(value));
    1073     WebCore::ExceptionCode ec = 0;
    1074     m_element->setAttribute(nameString, valueString, ec);
    1075     return ec ? E_FAIL : S_OK;
     1074    auto result = m_element->setAttribute(nameString, valueString);
     1075    return result.hasException() ? E_FAIL : S_OK;
    10761076}
    10771077   
  • trunk/Source/WebKit/win/DOMHTMLClasses.cpp

    r208096 r208135  
    515515    HTMLElement* htmlElement = downcast<HTMLElement>(m_element);
    516516    String htmlString(html, SysStringLen(html));
    517     ExceptionCode ec = 0;
    518     htmlElement->setInnerHTML(htmlString, ec);
     517    htmlElement->setInnerHTML(htmlString);
    519518    return S_OK;
    520519}
  • trunk/Source/WebKit2/ChangeLog

    r208124 r208135  
     12016-10-30  Darin Adler  <darin@apple.com>
     2
     3        Move Element, NamedNodeMap, and DOMStringMap from ExceptionCode to Exception
     4        https://bugs.webkit.org/show_bug.cgi?id=164206
     5
     6        Reviewed by Chris Dumez.
     7
     8        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMNamedNodeMap.cpp:
     9        (webkit_dom_named_node_map_set_named_item): Updated exception handling.
     10        (webkit_dom_named_node_map_remove_named_item): Ditto.
     11        (webkit_dom_named_node_map_set_named_item_ns): Ditto.
     12        (webkit_dom_named_node_map_remove_named_item_ns): Ditto.
     13        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElement.cpp:
     14        (webkit_dom_element_set_attribute): Ditto.
     15        (webkit_dom_element_set_attribute_node): Ditto.
     16        (webkit_dom_element_remove_attribute_node): Ditto.
     17        (webkit_dom_element_set_attribute_ns): Ditto.
     18        (webkit_dom_element_set_attribute_node_ns): Ditto.
     19        (webkit_dom_element_matches): Ditto.
     20        (webkit_dom_element_closest): Ditto.
     21        (webkit_dom_element_webkit_matches_selector): Ditto.
     22        (webkit_dom_element_insert_adjacent_element): Ditto.
     23        (webkit_dom_element_insert_adjacent_html): Ditto.
     24        (webkit_dom_element_insert_adjacent_text): Ditto.
     25        (webkit_dom_element_set_inner_html): Ditto.
     26        (webkit_dom_element_set_outer_html): Ditto.
     27        * WebProcess/InjectedBundle/API/mac/WKDOMElement.mm:
     28        (-[WKDOMElement setAttribute:value:]): Ditto.
     29
    1302016-10-30  Yusuke Suzuki  <utatane.tea@gmail.com>
    231
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElement.cpp

    r208096 r208135  
    614614    WTF::String convertedName = WTF::String::fromUTF8(name);
    615615    WTF::String convertedValue = WTF::String::fromUTF8(value);
    616     WebCore::ExceptionCode ec = 0;
    617     item->setAttribute(convertedName, convertedValue, ec);
    618     if (ec) {
    619         WebCore::ExceptionCodeDescription ecdesc(ec);
     616    auto result = item->setAttribute(convertedName, convertedValue);
     617    if (result.hasException()) {
     618        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
    620619        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    621620    }
     
    651650    WebCore::Element* item = WebKit::core(self);
    652651    WebCore::Attr* convertedNewAttr = WebKit::core(newAttr);
    653     WebCore::ExceptionCode ec = 0;
    654     RefPtr<WebCore::Attr> gobjectResult = WTF::getPtr(item->setAttributeNode(*convertedNewAttr, ec));
    655     if (ec) {
    656         WebCore::ExceptionCodeDescription ecdesc(ec);
    657         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    658     }
    659     return WebKit::kit(gobjectResult.get());
     652    auto result = item->setAttributeNode(*convertedNewAttr);
     653    if (result.hasException()) {
     654        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     655        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     656        return nullptr;
     657    }
     658    return WebKit::kit(result.releaseReturnValue().get());
    660659}
    661660
     
    668667    WebCore::Element* item = WebKit::core(self);
    669668    WebCore::Attr* convertedOldAttr = WebKit::core(oldAttr);
    670     WebCore::ExceptionCode ec = 0;
    671     RefPtr<WebCore::Attr> gobjectResult = WTF::getPtr(item->removeAttributeNode(*convertedOldAttr, ec));
    672     if (ec) {
    673         WebCore::ExceptionCodeDescription ecdesc(ec);
    674         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    675     }
    676     return WebKit::kit(gobjectResult.get());
     669    auto result = item->removeAttributeNode(*convertedOldAttr);
     670    if (result.hasException()) {
     671        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     672        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     673        return nullptr;
     674    }
     675    return WebKit::kit(result.releaseReturnValue().ptr());
    677676}
    678677
     
    721720    WTF::String convertedQualifiedName = WTF::String::fromUTF8(qualifiedName);
    722721    WTF::String convertedValue = WTF::String::fromUTF8(value);
    723     WebCore::ExceptionCode ec = 0;
    724     item->setAttributeNS(convertedNamespaceURI, convertedQualifiedName, convertedValue, ec);
    725     if (ec) {
    726         WebCore::ExceptionCodeDescription ecdesc(ec);
     722    auto result = item->setAttributeNS(convertedNamespaceURI, convertedQualifiedName, convertedValue);
     723    if (result.hasException()) {
     724        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
    727725        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    728726    }
     
    775773    WebCore::Element* item = WebKit::core(self);
    776774    WebCore::Attr* convertedNewAttr = WebKit::core(newAttr);
    777     WebCore::ExceptionCode ec = 0;
    778     RefPtr<WebCore::Attr> gobjectResult = WTF::getPtr(item->setAttributeNodeNS(*convertedNewAttr, ec));
    779     if (ec) {
    780         WebCore::ExceptionCodeDescription ecdesc(ec);
    781         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    782     }
    783     return WebKit::kit(gobjectResult.get());
     775    auto result = item->setAttributeNodeNS(*convertedNewAttr);
     776    if (result.hasException()) {
     777        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     778        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     779        return nullptr;
     780    }
     781    return WebKit::kit(result.releaseReturnValue().get());
    784782}
    785783
     
    875873    WebCore::Element* item = WebKit::core(self);
    876874    WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
    877     WebCore::ExceptionCode ec = 0;
    878     gboolean result = item->matches(convertedSelectors, ec);
    879     if (ec) {
    880         WebCore::ExceptionCodeDescription ecdesc(ec);
    881         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    882     }
    883     return result;
     875    auto result = item->matches(convertedSelectors);
     876    if (result.hasException()) {
     877        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     878        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     879        return false;
     880    }
     881    return result.releaseReturnValue();
    884882}
    885883
     
    892890    WebCore::Element* item = WebKit::core(self);
    893891    WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
    894     WebCore::ExceptionCode ec = 0;
    895     RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->closest(convertedSelectors, ec));
    896     if (ec) {
    897         WebCore::ExceptionCodeDescription ecdesc(ec);
    898         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    899     }
    900     return WebKit::kit(gobjectResult.get());
     892    auto result = item->closest(convertedSelectors);
     893    if (result.hasException()) {
     894        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     895        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     896        return nullptr;
     897    }
     898    return WebKit::kit(result.releaseReturnValue());
    901899}
    902900
    903901gboolean webkit_dom_element_webkit_matches_selector(WebKitDOMElement* self, const gchar* selectors, GError** error)
    904902{
    905     WebCore::JSMainThreadNullState state;
    906     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), FALSE);
    907     g_return_val_if_fail(selectors, FALSE);
    908     g_return_val_if_fail(!error || !*error, FALSE);
    909     WebCore::Element* item = WebKit::core(self);
    910     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
    911     WebCore::ExceptionCode ec = 0;
    912     gboolean result = item->matches(convertedSelectors, ec);
    913     if (ec) {
    914         WebCore::ExceptionCodeDescription ecdesc(ec);
    915         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    916     }
    917     return result;
     903    return webkit_dom_element_matches(self, selectors, error);
    918904}
    919905
     
    936922    WTF::String convertedWhere = WTF::String::fromUTF8(where);
    937923    WebCore::Element* convertedElement = WebKit::core(element);
    938     WebCore::ExceptionCode ec = 0;
    939     RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->insertAdjacentElement(convertedWhere, *convertedElement, ec));
    940     if (ec) {
    941         WebCore::ExceptionCodeDescription ecdesc(ec);
    942         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    943     }
    944     return WebKit::kit(gobjectResult.get());
     924    auto result = item->insertAdjacentElement(convertedWhere, *convertedElement);
     925    if (result.hasException()) {
     926        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     927        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     928        return nullptr;
     929    }
     930    return WebKit::kit(result.releaseReturnValue());
    945931}
    946932
     
    955941    WTF::String convertedWhere = WTF::String::fromUTF8(where);
    956942    WTF::String convertedHtml = WTF::String::fromUTF8(html);
    957     WebCore::ExceptionCode ec = 0;
    958     item->insertAdjacentHTML(convertedWhere, convertedHtml, ec);
    959     if (ec) {
    960         WebCore::ExceptionCodeDescription ecdesc(ec);
     943    auto result = item->insertAdjacentHTML(convertedWhere, convertedHtml);
     944    if (result.hasException()) {
     945        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
    961946        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    962947    }
     
    973958    WTF::String convertedWhere = WTF::String::fromUTF8(where);
    974959    WTF::String convertedText = WTF::String::fromUTF8(text);
    975     WebCore::ExceptionCode ec = 0;
    976     item->insertAdjacentText(convertedWhere, convertedText, ec);
    977     if (ec) {
    978         WebCore::ExceptionCodeDescription ecdesc(ec);
     960    auto result = item->insertAdjacentText(convertedWhere, convertedText);
     961    if (result.hasException()) {
     962        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
    979963        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    980964    }
     
    12641248    WebCore::Element* item = WebKit::core(self);
    12651249    WTF::String convertedValue = WTF::String::fromUTF8(value);
    1266     WebCore::ExceptionCode ec = 0;
    1267     item->setInnerHTML(convertedValue, ec);
    1268     if (ec) {
    1269         WebCore::ExceptionCodeDescription ecdesc(ec);
     1250    auto result = item->setInnerHTML(convertedValue);
     1251    if (result.hasException()) {
     1252        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
    12701253        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    12711254    }
     
    12891272    WebCore::Element* item = WebKit::core(self);
    12901273    WTF::String convertedValue = WTF::String::fromUTF8(value);
    1291     WebCore::ExceptionCode ec = 0;
    1292     item->setOuterHTML(convertedValue, ec);
    1293     if (ec) {
    1294         WebCore::ExceptionCodeDescription ecdesc(ec);
     1274    auto result = item->setOuterHTML(convertedValue);
     1275    if (result.hasException()) {
     1276        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
    12951277        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    12961278    }
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMNamedNodeMap.cpp

    r207735 r208135  
    2121#include "WebKitDOMNamedNodeMap.h"
    2222
     23#include "ConvertToUTF8String.h"
     24#include "DOMObjectCache.h"
     25#include "WebKitDOMNamedNodeMapPrivate.h"
     26#include "WebKitDOMNodePrivate.h"
     27#include "WebKitDOMPrivate.h"
     28#include <WebCore/Attr.h>
    2329#include <WebCore/CSSImportRule.h>
    24 #include "DOMObjectCache.h"
    2530#include <WebCore/Document.h>
    2631#include <WebCore/ExceptionCode.h>
    2732#include <WebCore/ExceptionCodeDescription.h>
    2833#include <WebCore/JSMainThreadExecState.h>
    29 #include "WebKitDOMNamedNodeMapPrivate.h"
    30 #include "WebKitDOMNodePrivate.h"
    31 #include "WebKitDOMPrivate.h"
    32 #include "ConvertToUTF8String.h"
    3334#include <wtf/GetPtr.h>
    3435#include <wtf/RefPtr.h>
     
    153154    WebCore::NamedNodeMap* item = WebKit::core(self);
    154155    WebCore::Node* convertedNode = WebKit::core(node);
    155     WebCore::ExceptionCode ec = 0;
    156     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->setNamedItem(*convertedNode, ec));
    157     if (ec) {
    158         WebCore::ExceptionCodeDescription ecdesc(ec);
    159         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    160     }
    161     return WebKit::kit(gobjectResult.get());
     156    if (!is<WebCore::Attr>(*convertedNode)) {
     157        WebCore::ExceptionCodeDescription ecdesc(WebCore::TypeError);
     158        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     159        return nullptr;
     160    }
     161    auto result = item->setNamedItem(downcast<WebCore::Attr>(*convertedNode));
     162    if (result.hasException()) {
     163        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     164        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     165        return nullptr;
     166    }
     167    return WebKit::kit(result.releaseReturnValue().get());
    162168}
    163169
     
    170176    WebCore::NamedNodeMap* item = WebKit::core(self);
    171177    WTF::String convertedName = WTF::String::fromUTF8(name);
    172     WebCore::ExceptionCode ec = 0;
    173     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->removeNamedItem(convertedName, ec));
    174     if (ec) {
    175         WebCore::ExceptionCodeDescription ecdesc(ec);
    176         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    177     }
    178     return WebKit::kit(gobjectResult.get());
     178    auto result = item->removeNamedItem(convertedName);
     179    if (result.hasException()) {
     180        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     181        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     182        return nullptr;
     183    }
     184    return WebKit::kit(result.releaseReturnValue().ptr());
    179185}
    180186
     
    203209WebKitDOMNode* webkit_dom_named_node_map_set_named_item_ns(WebKitDOMNamedNodeMap* self, WebKitDOMNode* node, GError** error)
    204210{
    205     WebCore::JSMainThreadNullState state;
    206     g_return_val_if_fail(WEBKIT_DOM_IS_NAMED_NODE_MAP(self), 0);
    207     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(node), 0);
    208     g_return_val_if_fail(!error || !*error, 0);
    209     WebCore::NamedNodeMap* item = WebKit::core(self);
    210     WebCore::Node* convertedNode = WebKit::core(node);
    211     WebCore::ExceptionCode ec = 0;
    212     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->setNamedItem(*convertedNode, ec));
    213     if (ec) {
    214         WebCore::ExceptionCodeDescription ecdesc(ec);
    215         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    216     }
    217     return WebKit::kit(gobjectResult.get());
     211    return webkit_dom_named_node_map_set_named_item(self, node, error);
    218212}
    219213
     
    228222    WTF::String convertedNamespaceURI = WTF::String::fromUTF8(namespaceURI);
    229223    WTF::String convertedLocalName = WTF::String::fromUTF8(localName);
    230     WebCore::ExceptionCode ec = 0;
    231     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->removeNamedItemNS(convertedNamespaceURI, convertedLocalName, ec));
    232     if (ec) {
    233         WebCore::ExceptionCodeDescription ecdesc(ec);
    234         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
    235     }
    236     return WebKit::kit(gobjectResult.get());
     224    auto result = item->removeNamedItemNS(convertedNamespaceURI, convertedLocalName);
     225    if (result.hasException()) {
     226        WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
     227        g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
     228        return nullptr;
     229    }
     230    return WebKit::kit(result.releaseReturnValue().ptr());
    237231}
    238232
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMElement.mm

    r174125 r208135  
    4646- (void)setAttribute:(NSString *)name value:(NSString *)value
    4747{
    48     // FIXME: Do something about the exception.
    49     WebCore::ExceptionCode ec;
    50     downcast<WebCore::Element>(*_impl).setAttribute(name, value, ec);
     48    downcast<WebCore::Element>(*_impl).setAttribute(name, value);
    5149}
    5250
Note: See TracChangeset for help on using the changeset viewer.