Changeset 199878 in webkit


Ignore:
Timestamp:
Apr 22, 2016 8:59:10 AM (8 years ago)
Author:
Chris Dumez
Message:

Drop [UsePointersEvenForNonNullableObjectArguments] from MutationObserver
https://bugs.webkit.org/show_bug.cgi?id=156890

Reviewed by Darin Adler.

Source/WebCore:

Drop [UsePointersEvenForNonNullableObjectArguments] from MutationObserver
and clean up / modernize the code a bit. There is not significant Web-
exposed behavior change except that MutationObserver.observe() now throws
a different kind of exception (a TypeError as per Web IDL) when passed in
a null Node.

No new tests, rebaselined existing test.

  • bindings/js/JSMutationCallback.cpp:

(WebCore::JSMutationCallback::call):

  • bindings/js/JSMutationCallback.h:
  • bindings/js/JSMutationObserverCustom.cpp:

(WebCore::constructJSMutationObserver):

  • css/PropertySetCSSStyleDeclaration.cpp:
  • dom/ChildListMutationScope.cpp:

(WebCore::ChildListMutationAccumulator::enqueueMutationRecord):

  • dom/MutationCallback.h:
  • dom/MutationObserver.cpp:

(WebCore::MutationObserver::create):
(WebCore::MutationObserver::MutationObserver):
(WebCore::MutationObserver::observe):
(WebCore::MutationObserver::takeRecords):
(WebCore::MutationObserver::enqueueMutationRecord):
(WebCore::MutationObserver::deliver):
(WebCore::MutationObserver::disconnect): Deleted.

  • dom/MutationObserver.h:
  • dom/MutationObserver.idl:
  • dom/MutationObserverInterestGroup.cpp:

(WebCore::MutationObserverInterestGroup::enqueueMutationRecord):

  • dom/MutationObserverInterestGroup.h:
  • dom/MutationRecord.cpp:

(WebCore::MutationRecord::createChildList):

  • dom/MutationRecord.h:

LayoutTests:

Rebaseline now that MutationObserver.observe() throws a TypeError instead
of a NOT_FOUND_ERR when passed a null Node.

  • fast/dom/MutationObserver/observe-exceptions-expected.txt:
Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r199877 r199878  
     12016-04-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Drop [UsePointersEvenForNonNullableObjectArguments] from MutationObserver
     4        https://bugs.webkit.org/show_bug.cgi?id=156890
     5
     6        Reviewed by Darin Adler.
     7
     8        Rebaseline now that MutationObserver.observe() throws a TypeError instead
     9        of a NOT_FOUND_ERR when passed a null Node.
     10
     11        * fast/dom/MutationObserver/observe-exceptions-expected.txt:
     12
    1132016-04-22  Dave Hyatt  <hyatt@apple.com>
    214
  • trunk/LayoutTests/fast/dom/MutationObserver/observe-exceptions-expected.txt

    r189271 r199878  
    88PASS observer.observe(undefined) threw exception TypeError: Not enough arguments.
    99PASS observer.observe(document.body) threw exception TypeError: Not enough arguments.
    10 PASS observer.observe(document.body, null) threw exception Error: SyntaxError: DOM Exception 12.
    11 PASS observer.observe(document.body, undefined) threw exception Error: SyntaxError: DOM Exception 12.
    12 PASS observer.observe(null, {attributes: true}) threw exception Error: NotFoundError: DOM Exception 8.
    13 PASS observer.observe(undefined, {attributes: true}) threw exception Error: NotFoundError: DOM Exception 8.
    14 PASS observer.observe(document.body, {subtree: true}) threw exception Error: SyntaxError: DOM Exception 12.
     10PASS observer.observe(document.body, null) threw exception TypeError: Type error.
     11PASS observer.observe(document.body, undefined) threw exception TypeError: Type error.
     12PASS observer.observe(null, {attributes: true}) threw exception TypeError: Type error.
     13PASS observer.observe(undefined, {attributes: true}) threw exception TypeError: Type error.
     14PASS observer.observe(document.body, {subtree: true}) threw exception TypeError: Type error.
    1515PASS observer.observe(document.body, {childList: true, attributeOldValue: true}) did not throw exception.
    1616PASS observer.observe(document.body, {attributes: true, characterDataOldValue: true}) did not throw exception.
    1717PASS observer.observe(document.body, {characterData: true, attributeFilter: ["id"]}) did not throw exception.
    18 PASS observer.observe(document.body, {attributes: false, attributeOldValue: true}) threw exception Error: SyntaxError: DOM Exception 12.
    19 PASS observer.observe(document.body, {attributes: false, attributeFilter: ["id"]}) threw exception Error: SyntaxError: DOM Exception 12.
    20 PASS observer.observe(document.body, {characterData: false, characterDataOldValue: true}) threw exception Error: SyntaxError: DOM Exception 12.
     18PASS observer.observe(document.body, {attributes: false, attributeOldValue: true}) threw exception TypeError: Type error.
     19PASS observer.observe(document.body, {attributes: false, attributeFilter: ["id"]}) threw exception TypeError: Type error.
     20PASS observer.observe(document.body, {characterData: false, characterDataOldValue: true}) threw exception TypeError: Type error.
    2121PASS successfullyParsed is true
    2222
  • trunk/Source/WebCore/ChangeLog

    r199877 r199878  
     12016-04-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Drop [UsePointersEvenForNonNullableObjectArguments] from MutationObserver
     4        https://bugs.webkit.org/show_bug.cgi?id=156890
     5
     6        Reviewed by Darin Adler.
     7
     8        Drop [UsePointersEvenForNonNullableObjectArguments] from MutationObserver
     9        and clean up / modernize the code a bit. There is not significant Web-
     10        exposed behavior change except that MutationObserver.observe() now throws
     11        a different kind of exception (a TypeError as per Web IDL) when passed in
     12        a null Node.
     13
     14        No new tests, rebaselined existing test.
     15
     16        * bindings/js/JSMutationCallback.cpp:
     17        (WebCore::JSMutationCallback::call):
     18        * bindings/js/JSMutationCallback.h:
     19        * bindings/js/JSMutationObserverCustom.cpp:
     20        (WebCore::constructJSMutationObserver):
     21        * css/PropertySetCSSStyleDeclaration.cpp:
     22        * dom/ChildListMutationScope.cpp:
     23        (WebCore::ChildListMutationAccumulator::enqueueMutationRecord):
     24        * dom/MutationCallback.h:
     25        * dom/MutationObserver.cpp:
     26        (WebCore::MutationObserver::create):
     27        (WebCore::MutationObserver::MutationObserver):
     28        (WebCore::MutationObserver::observe):
     29        (WebCore::MutationObserver::takeRecords):
     30        (WebCore::MutationObserver::enqueueMutationRecord):
     31        (WebCore::MutationObserver::deliver):
     32        (WebCore::MutationObserver::disconnect): Deleted.
     33        * dom/MutationObserver.h:
     34        * dom/MutationObserver.idl:
     35        * dom/MutationObserverInterestGroup.cpp:
     36        (WebCore::MutationObserverInterestGroup::enqueueMutationRecord):
     37        * dom/MutationObserverInterestGroup.h:
     38        * dom/MutationRecord.cpp:
     39        (WebCore::MutationRecord::createChildList):
     40        * dom/MutationRecord.h:
     41
    1422016-04-22  Dave Hyatt  <hyatt@apple.com>
    243
  • trunk/Source/WebCore/bindings/js/JSMutationCallback.cpp

    r197614 r199878  
    5252}
    5353
    54 void JSMutationCallback::call(const Vector<RefPtr<MutationRecord>>& mutations, MutationObserver* observer)
     54void JSMutationCallback::call(const Vector<Ref<MutationRecord>>& mutations, MutationObserver* observer)
    5555{
    5656    if (!canInvokeCallback())
  • trunk/Source/WebCore/bindings/js/JSMutationCallback.h

    r197563 r199878  
    4747    virtual ~JSMutationCallback();
    4848
    49     void call(const Vector<RefPtr<MutationRecord>>&, MutationObserver*) override;
     49    void call(const Vector<Ref<MutationRecord>>&, MutationObserver*) override;
    5050
    5151    ScriptExecutionContext* scriptExecutionContext() const override { return ContextDestructionObserver::scriptExecutionContext(); }
  • trunk/Source/WebCore/bindings/js/JSMutationObserverCustom.cpp

    r197614 r199878  
    5555
    5656    DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec->callee());
    57     RefPtr<JSMutationCallback> callback = JSMutationCallback::create(object, jsConstructor->globalObject());
    58     JSObject* jsObserver = asObject(toJS(exec, jsConstructor->globalObject(), MutationObserver::create(callback.release())));
     57    auto callback = JSMutationCallback::create(object, jsConstructor->globalObject());
     58    JSObject* jsObserver = asObject(toJS(exec, jsConstructor->globalObject(), MutationObserver::create(WTFMove(callback))));
    5959    PrivateName propertyName;
    6060    jsObserver->putDirect(jsConstructor->globalObject()->vm(), propertyName, object);
  • trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp

    r198284 r199878  
    7878
    7979        if (m_mutation && s_shouldDeliver)
    80             m_mutationRecipients->enqueueMutationRecord(m_mutation);
     80            m_mutationRecipients->enqueueMutationRecord(m_mutation.releaseNonNull());
    8181
    8282        s_shouldDeliver = false;
  • trunk/Source/WebCore/dom/ChildListMutationScope.cpp

    r194819 r199878  
    128128    ASSERT(!isEmpty());
    129129
    130     RefPtr<NodeList> addedNodes = StaticNodeList::adopt(m_addedNodes);
    131     RefPtr<NodeList> removedNodes = StaticNodeList::adopt(m_removedNodes);
    132     RefPtr<MutationRecord> record = MutationRecord::createChildList(m_target, addedNodes.release(), removedNodes.release(), m_previousSibling.release(), m_nextSibling.release());
    133     m_observers->enqueueMutationRecord(record.release());
     130    auto record = MutationRecord::createChildList(m_target, StaticNodeList::adopt(m_addedNodes), StaticNodeList::adopt(m_removedNodes), WTFMove(m_previousSibling), WTFMove(m_nextSibling));
     131    m_observers->enqueueMutationRecord(WTFMove(record));
    134132    m_lastAdded = nullptr;
    135133    ASSERT(isEmpty());
  • trunk/Source/WebCore/dom/MutationCallback.h

    r157653 r199878  
    4545    virtual ~MutationCallback() { }
    4646
    47     virtual void call(const Vector<RefPtr<MutationRecord>>&, MutationObserver*) = 0;
     47    virtual void call(const Vector<Ref<MutationRecord>>&, MutationObserver*) = 0;
    4848    virtual ScriptExecutionContext* scriptExecutionContext() const = 0;
    4949};
  • trunk/Source/WebCore/dom/MutationObserver.cpp

    r199735 r199878  
    4747static unsigned s_observerPriority = 0;
    4848
    49 Ref<MutationObserver> MutationObserver::create(PassRefPtr<MutationCallback> callback)
    50 {
    51     ASSERT(isMainThread());
    52     return adoptRef(*new MutationObserver(callback));
    53 }
    54 
    55 MutationObserver::MutationObserver(PassRefPtr<MutationCallback> callback)
    56     : m_callback(callback)
     49Ref<MutationObserver> MutationObserver::create(Ref<MutationCallback>&& callback)
     50{
     51    ASSERT(isMainThread());
     52    return adoptRef(*new MutationObserver(WTFMove(callback)));
     53}
     54
     55MutationObserver::MutationObserver(Ref<MutationCallback>&& callback)
     56    : m_callback(WTFMove(callback))
    5757    , m_priority(s_observerPriority++)
    5858{
     
    7272}
    7373
    74 void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary, ExceptionCode& ec)
    75 {
    76     if (!node) {
    77         ec = NOT_FOUND_ERR;
    78         return;
    79     }
    80 
     74void MutationObserver::observe(Node& node, const Dictionary& optionsDictionary, ExceptionCode& ec)
     75{
    8176    static const struct {
    8277        const char* name;
     
    108103
    109104    if (!validateOptions(options)) {
    110         ec = SYNTAX_ERR;
    111         return;
    112     }
    113 
    114     node->registerMutationObserver(this, options, attributeFilter);
    115 }
    116 
    117 Vector<RefPtr<MutationRecord>> MutationObserver::takeRecords()
    118 {
    119     Vector<RefPtr<MutationRecord>> records;
     105        ec = TypeError;
     106        return;
     107    }
     108
     109    node.registerMutationObserver(this, options, attributeFilter);
     110}
     111
     112Vector<Ref<MutationRecord>> MutationObserver::takeRecords()
     113{
     114    Vector<Ref<MutationRecord>> records;
    120115    records.swap(m_records);
    121116    return records;
     
    190185}
    191186
    192 void MutationObserver::enqueueMutationRecord(PassRefPtr<MutationRecord> mutation)
    193 {
    194     ASSERT(isMainThread());
    195     m_records.append(mutation);
     187void MutationObserver::enqueueMutationRecord(Ref<MutationRecord>&& mutation)
     188{
     189    ASSERT(isMainThread());
     190    m_records.append(WTFMove(mutation));
    196191    activeMutationObservers().add(this);
    197192
     
    237232        return;
    238233
    239     Vector<RefPtr<MutationRecord>> records;
     234    Vector<Ref<MutationRecord>> records;
    240235    records.swap(m_records);
    241236
  • trunk/Source/WebCore/dom/MutationObserver.h

    r193286 r199878  
    7474    };
    7575
    76     static Ref<MutationObserver> create(PassRefPtr<MutationCallback>);
     76    static Ref<MutationObserver> create(Ref<MutationCallback>&&);
    7777
    7878    ~MutationObserver();
    7979
    80     void observe(Node*, const Dictionary&, ExceptionCode&);
    81     Vector<RefPtr<MutationRecord>> takeRecords();
     80    void observe(Node&, const Dictionary&, ExceptionCode&);
     81    Vector<Ref<MutationRecord>> takeRecords();
    8282    void disconnect();
    8383    void observationStarted(MutationObserverRegistration*);
    8484    void observationEnded(MutationObserverRegistration*);
    85     void enqueueMutationRecord(PassRefPtr<MutationRecord>);
     85    void enqueueMutationRecord(Ref<MutationRecord>&&);
    8686    void setHasTransientRegistration();
    8787    bool canDeliver();
     
    9292    struct ObserverLessThan;
    9393
    94     explicit MutationObserver(PassRefPtr<MutationCallback>);
     94    explicit MutationObserver(Ref<MutationCallback>&&);
    9595    void deliver();
    9696
     
    9898    static bool validateOptions(MutationObserverOptions);
    9999
    100     RefPtr<MutationCallback> m_callback;
    101     Vector<RefPtr<MutationRecord>> m_records;
     100    Ref<MutationCallback> m_callback;
     101    Vector<Ref<MutationRecord>> m_records;
    102102    HashSet<MutationObserverRegistration*> m_registrations;
    103103    unsigned m_priority;
  • trunk/Source/WebCore/dom/MutationObserver.idl

    r198833 r199878  
    3232    CustomConstructor(MutationCallback callback),
    3333    CustomIsReachable,
    34     UsePointersEvenForNonNullableObjectArguments,
    3534    ImplementationLacksVTable,
    3635] interface MutationObserver {
  • trunk/Source/WebCore/dom/MutationObserverInterestGroup.cpp

    r195243 r199878  
    6565}
    6666
    67 void MutationObserverInterestGroup::enqueueMutationRecord(PassRefPtr<MutationRecord> prpMutation)
     67void MutationObserverInterestGroup::enqueueMutationRecord(Ref<MutationRecord>&& mutation)
    6868{
    69     RefPtr<MutationRecord> mutation = prpMutation;
    7069    RefPtr<MutationRecord> mutationWithNullOldValue;
    7170    for (auto& observerOptionsPair : m_observers) {
    7271        MutationObserver* observer = observerOptionsPair.key;
    7372        if (hasOldValue(observerOptionsPair.value)) {
    74             observer->enqueueMutationRecord(mutation);
     73            observer->enqueueMutationRecord(mutation.copyRef());
    7574            continue;
    7675        }
    7776        if (!mutationWithNullOldValue) {
    7877            if (mutation->oldValue().isNull())
    79                 mutationWithNullOldValue = mutation;
     78                mutationWithNullOldValue = mutation.ptr();
    8079            else
    81                 mutationWithNullOldValue = MutationRecord::createWithNullOldValue(*mutation).ptr();
     80                mutationWithNullOldValue = MutationRecord::createWithNullOldValue(mutation).ptr();
    8281        }
    83         observer->enqueueMutationRecord(mutationWithNullOldValue);
     82        observer->enqueueMutationRecord(*mutationWithNullOldValue);
    8483    }
    8584}
  • trunk/Source/WebCore/dom/MutationObserverInterestGroup.h

    r199735 r199878  
    7171
    7272    bool isOldValueRequested();
    73     void enqueueMutationRecord(PassRefPtr<MutationRecord>);
     73    void enqueueMutationRecord(Ref<MutationRecord>&&);
    7474
    7575private:
  • trunk/Source/WebCore/dom/MutationRecord.cpp

    r197563 r199878  
    4343class ChildListRecord : public MutationRecord {
    4444public:
    45     ChildListRecord(ContainerNode& target, PassRefPtr<NodeList> added, PassRefPtr<NodeList> removed, PassRefPtr<Node> previousSibling, PassRefPtr<Node> nextSibling)
     45    ChildListRecord(ContainerNode& target, Ref<NodeList>&& added, Ref<NodeList>&& removed, RefPtr<Node>&& previousSibling, RefPtr<Node>&& nextSibling)
    4646        : m_target(target)
    47         , m_addedNodes(added)
    48         , m_removedNodes(removed)
    49         , m_previousSibling(previousSibling)
    50         , m_nextSibling(nextSibling)
     47        , m_addedNodes(WTFMove(added))
     48        , m_removedNodes(WTFMove(removed))
     49        , m_previousSibling(WTFMove(previousSibling))
     50        , m_nextSibling(WTFMove(nextSibling))
    5151    {
    5252    }
     
    165165} // namespace
    166166
    167 Ref<MutationRecord> MutationRecord::createChildList(ContainerNode& target, PassRefPtr<NodeList> added, PassRefPtr<NodeList> removed, PassRefPtr<Node> previousSibling, PassRefPtr<Node> nextSibling)
     167Ref<MutationRecord> MutationRecord::createChildList(ContainerNode& target, Ref<NodeList>&& added, Ref<NodeList>&& removed, RefPtr<Node>&& previousSibling, RefPtr<Node>&& nextSibling)
    168168{
    169     return adoptRef(static_cast<MutationRecord&>(*new ChildListRecord(target, added, removed, previousSibling, nextSibling)));
     169    return adoptRef(static_cast<MutationRecord&>(*new ChildListRecord(target, WTFMove(added), WTFMove(removed), WTFMove(previousSibling), WTFMove(nextSibling))));
    170170}
    171171
  • trunk/Source/WebCore/dom/MutationRecord.h

    r195243 r199878  
    4848class MutationRecord : public RefCounted<MutationRecord> {
    4949public:
    50     static Ref<MutationRecord> createChildList(ContainerNode& target, PassRefPtr<NodeList> added, PassRefPtr<NodeList> removed, PassRefPtr<Node> previousSibling, PassRefPtr<Node> nextSibling);
     50    static Ref<MutationRecord> createChildList(ContainerNode& target, Ref<NodeList>&& added, Ref<NodeList>&& removed, RefPtr<Node>&& previousSibling, RefPtr<Node>&& nextSibling);
    5151    static Ref<MutationRecord> createAttributes(Element& target, const QualifiedName&, const AtomicString& oldValue);
    5252    static Ref<MutationRecord> createCharacterData(CharacterData& target, const String& oldValue);
Note: See TracChangeset for help on using the changeset viewer.