Changeset 99611 in webkit


Ignore:
Timestamp:
Nov 8, 2011, 12:59:47 PM (14 years ago)
Author:
adamk@chromium.org
Message:

WebKitMutationObserver.observe should raise a DOMException if passed invalid arguments
https://bugs.webkit.org/show_bug.cgi?id=71596

Reviewed by Ryosuke Niwa.

Source/WebCore:

Adds two cases where WebKitMutationObserver.observe throws an exception:

  • When passed a null Node*.
  • When passed options that don't make sense, e.g., 'attributeOldValue' but not 'attributes'.
  • bindings/js/JSWebKitMutationObserverCustom.cpp:

(WebCore::JSWebKitMutationObserver::observe):

  • bindings/v8/custom/V8WebKitMutationObserverCustom.cpp:

(WebCore::V8WebKitMutationObserver::observeCallback):

  • dom/WebKitMutationObserver.cpp:

(WebCore::WebKitMutationObserver::validateOptions):
(WebCore::WebKitMutationObserver::observe):

  • dom/WebKitMutationObserver.h:
  • dom/WebKitMutationObserver.idl:

LayoutTests:

  • fast/mutation/observe-exceptions-expected.txt:
  • fast/mutation/observe-exceptions.html:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r99609 r99611  
     12011-11-08  Adam Klein  <adamk@chromium.org>
     2
     3        WebKitMutationObserver.observe should raise a DOMException if passed invalid arguments
     4        https://bugs.webkit.org/show_bug.cgi?id=71596
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * fast/mutation/observe-exceptions-expected.txt:
     9        * fast/mutation/observe-exceptions.html:
     10
    1112011-11-08  Joshua Bell  <jsbell@chromium.org>
    212
  • trunk/LayoutTests/fast/mutation/observe-exceptions-expected.txt

    r97159 r99611  
    1010PASS observer.observe(document.body, null) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    1111PASS observer.observe(document.body, undefined) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
     12PASS observer.observe(null, {attributes: true}) threw exception Error: NOT_FOUND_ERR: DOM Exception 8.
     13PASS observer.observe(undefined, {attributes: true}) threw exception Error: NOT_FOUND_ERR: DOM Exception 8.
     14PASS observer.observe(document.body, {subtree: true}) threw exception Error: SYNTAX_ERR: DOM Exception 12.
     15PASS observer.observe(document.body, {childList: true, attributeOldValue: true}) threw exception Error: SYNTAX_ERR: DOM Exception 12.
     16PASS observer.observe(document.body, {attributes: true, characterDataOldValue: true}) threw exception Error: SYNTAX_ERR: DOM Exception 12.
    1217PASS successfullyParsed is true
    1318
  • trunk/LayoutTests/fast/mutation/observe-exceptions.html

    r98407 r99611  
    1919    shouldThrow('observer.observe(document.body, null)');
    2020    shouldThrow('observer.observe(document.body, undefined)');
     21    shouldThrow('observer.observe(null, {attributes: true})');
     22    shouldThrow('observer.observe(undefined, {attributes: true})');
     23    shouldThrow('observer.observe(document.body, {subtree: true})');
     24    shouldThrow('observer.observe(document.body, {childList: true, attributeOldValue: true})');
     25    shouldThrow('observer.observe(document.body, {attributes: true, characterDataOldValue: true})');
     26    // FIXME: Uncomment the below when attributeFilter is supported.
     27    //shouldThrow('observer.observe(document.body, {characterData: true, attributeFilter: ["id"]})');
    2128}
    2229
  • trunk/Source/WebCore/ChangeLog

    r99609 r99611  
     12011-11-08  Adam Klein  <adamk@chromium.org>
     2
     3        WebKitMutationObserver.observe should raise a DOMException if passed invalid arguments
     4        https://bugs.webkit.org/show_bug.cgi?id=71596
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Adds two cases where WebKitMutationObserver.observe throws an exception:
     9          - When passed a null Node*.
     10          - When passed options that don't make sense, e.g.,
     11            'attributeOldValue' but not 'attributes'.
     12
     13        * bindings/js/JSWebKitMutationObserverCustom.cpp:
     14        (WebCore::JSWebKitMutationObserver::observe):
     15        * bindings/v8/custom/V8WebKitMutationObserverCustom.cpp:
     16        (WebCore::V8WebKitMutationObserver::observeCallback):
     17        * dom/WebKitMutationObserver.cpp:
     18        (WebCore::WebKitMutationObserver::validateOptions):
     19        (WebCore::WebKitMutationObserver::observe):
     20        * dom/WebKitMutationObserver.h:
     21        * dom/WebKitMutationObserver.idl:
     22
    1232011-11-08  Joshua Bell  <jsbell@chromium.org>
    224
  • trunk/Source/WebCore/bindings/js/JSWebKitMutationObserverCustom.cpp

    r97714 r99611  
    9494        return jsUndefined();
    9595
    96     impl()->observe(target, options);
     96    ExceptionCode ec = 0;
     97    impl()->observe(target, options, ec);
     98    if (ec)
     99        setDOMException(exec, ec);
    97100    return jsUndefined();
    98101}
  • trunk/Source/WebCore/bindings/v8/custom/V8WebKitMutationObserverCustom.cpp

    r98572 r99611  
    104104        options |= WebKitMutationObserver::CharacterDataOldValue;
    105105
    106     imp->observe(target, options);
     106    ExceptionCode ec = 0;
     107    imp->observe(target, options, ec);
     108    if (ec)
     109        V8Proxy::setDOMException(ec);
    107110    return v8::Handle<v8::Value>();
    108111}
  • trunk/Source/WebCore/dom/WebKitMutationObserver.cpp

    r99593 r99611  
    3636
    3737#include "Document.h"
     38#include "ExceptionCode.h"
    3839#include "MutationCallback.h"
    3940#include "MutationObserverRegistration.h"
     
    5960}
    6061
    61 void WebKitMutationObserver::observe(Node* node, MutationObserverOptions options)
     62bool WebKitMutationObserver::validateOptions(MutationObserverOptions options)
    6263{
     64    return (options & (Attributes | CharacterData | ChildList))
     65        && ((options & Attributes) || !(options & AttributeOldValue))
     66        // FIXME: Uncomment the line below once attributeFilter is supported.
     67        // && ((options & Attributes) || !(options & AttributeFilter))
     68        && ((options & CharacterData) || !(options & CharacterDataOldValue));
     69}
     70
     71void WebKitMutationObserver::observe(Node* node, MutationObserverOptions options, ExceptionCode& ec)
     72{
     73    if (!node) {
     74        ec = NOT_FOUND_ERR;
     75        return;
     76    }
     77
     78    if (!validateOptions(options)) {
     79        // FIXME: Revisit this once the spec specifies the exception type; SYNTAX_ERR may not be appropriate.
     80        ec = SYNTAX_ERR;
     81        return;
     82    }
     83
    6384    MutationObserverRegistration* registration = node->registerMutationObserver(this);
    6485    registration->resetObservation(options);
  • trunk/Source/WebCore/dom/WebKitMutationObserver.h

    r99593 r99611  
    3434#if ENABLE(MUTATION_OBSERVERS)
    3535
     36#include "ExceptionCode.h"
    3637#include <wtf/HashSet.h>
    3738#include <wtf/PassRefPtr.h>
     
    7677    ~WebKitMutationObserver();
    7778
    78     void observe(Node*, MutationObserverOptions);
     79    void observe(Node*, MutationObserverOptions, ExceptionCode&);
    7980    void disconnect();
    8081    void observationStarted(MutationObserverRegistration*);
     
    8586    WebKitMutationObserver(PassRefPtr<MutationCallback>);
    8687    void deliver();
     88
     89    static bool validateOptions(MutationObserverOptions);
    8790
    8891    RefPtr<MutationCallback> m_callback;
  • trunk/Source/WebCore/dom/WebKitMutationObserver.idl

    r97159 r99611  
    3535        CustomConstructor
    3636    ] WebKitMutationObserver {
    37         [Custom] void observe(in Node target, in MutationObserverOptions options);
     37        [Custom] void observe(in Node target, in MutationObserverOptions options)
     38            raises(DOMException);
    3839        void disconnect();
    3940    };
Note: See TracChangeset for help on using the changeset viewer.