WebCore:
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Jul 2008 21:29:56 +0000 (21:29 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Jul 2008 21:29:56 +0000 (21:29 +0000)
2008-07-07  Sam Weinig  <sam@webkit.org>

        Reviewed by Geoffrey Garen.

        Fix for https://bugs.webkit.org/show_bug.cgi?id=19928
        querySelectorAll should throw an exception if a NSResolver is passed in.

        - Throw an NOT_SUPPORTED_ERR if a non-null or undefined parameter is passed
          as the second argument to querySelector or querySelectorAll.

        Test: fast/dom/SelectorAPI/not-supported-NSResolver.html

        * bindings/js/JSDocumentCustom.cpp:
        (WebCore::JSDocument::querySelector):
        (WebCore::JSDocument::querySelectorAll):
        * bindings/js/JSElementCustom.cpp:
        (WebCore::JSElement::querySelector):
        (WebCore::JSElement::querySelectorAll):
        * dom/Document.idl:
        * dom/Element.idl:

LayoutTests:

2008-07-07  Sam Weinig  <sam@webkit.org>

        Reviewed by Geoffrey Garen.

        Fix for https://bugs.webkit.org/show_bug.cgi?id=19928
        querySelectorAll should throw an exception if a NSResolver is passed in.

        * fast/dom/SelectorAPI/not-supported-NSResolver-expected.txt: Added.
        * fast/dom/SelectorAPI/not-supported-NSResolver.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@35041 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/SelectorAPI/not-supported-NSResolver-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/SelectorAPI/not-supported-NSResolver.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/bindings/js/JSDocumentCustom.cpp
WebCore/bindings/js/JSElementCustom.cpp
WebCore/dom/Document.idl
WebCore/dom/Element.idl

index cc2e844..7f5ea68 100644 (file)
@@ -1,3 +1,13 @@
+2008-07-07  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Geoffrey Garen.
+
+        Fix for https://bugs.webkit.org/show_bug.cgi?id=19928
+        querySelectorAll should throw an exception if a NSResolver is passed in.
+
+        * fast/dom/SelectorAPI/not-supported-NSResolver-expected.txt: Added.
+        * fast/dom/SelectorAPI/not-supported-NSResolver.html: Added.
+
 2008-07-07  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Mitz and Geoff
diff --git a/LayoutTests/fast/dom/SelectorAPI/not-supported-NSResolver-expected.txt b/LayoutTests/fast/dom/SelectorAPI/not-supported-NSResolver-expected.txt
new file mode 100644 (file)
index 0000000..93a5c7a
--- /dev/null
@@ -0,0 +1,7 @@
+This tests that we throw a NOT_SUPPORTED_ERR when passing a NSResolver to querySelector and querySelectorAll since we do not support it.
+
+PASS: Document.querySelector throws: Error: NOT_SUPPORTED_ERR: DOM Exception 9
+PASS: Document.querySelectorAll throws: Error: NOT_SUPPORTED_ERR: DOM Exception 9
+PASS: Element.querySelector throws: Error: NOT_SUPPORTED_ERR: DOM Exception 9
+PASS: Element.querySelectorAll throws: Error: NOT_SUPPORTED_ERR: DOM Exception 9
+
diff --git a/LayoutTests/fast/dom/SelectorAPI/not-supported-NSResolver.html b/LayoutTests/fast/dom/SelectorAPI/not-supported-NSResolver.html
new file mode 100644 (file)
index 0000000..4cb4b79
--- /dev/null
@@ -0,0 +1,49 @@
+<html>
+<head>
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    log = function(msg)
+    {
+        document.getElementById('console').appendChild(document.createTextNode(msg + "\n"));
+    }
+
+    onload = function()
+    {
+        try {
+            document.querySelector("bbb|pre", function(prefix) { return "aaa"; });
+            log("FAIL: Document.querySelector did not throw");
+        } catch(ex) {
+            log("PASS: Document.querySelector throws: " + ex);
+        }
+
+        try {
+            document.querySelectorAll("bbb|pre", function(prefix) { return "aaa"; });
+            log("FAIL: Document.querySelectorAll did not throw");
+        } catch(ex) {
+            log("PASS: Document.querySelectorAll throws: " + ex);
+        }
+
+        try {
+            document.body.querySelector("bbb|pre", function(prefix) { return "aaa"; });
+            log("FAIL: Element.querySelector did not throw");
+        } catch(ex) {
+            log("PASS: Element.querySelector throws: " + ex);
+        }
+
+        try {
+            document.body.querySelectorAll("bbb|pre", function(prefix) { return "aaa"; });
+            log("FAIL: Element.querySelectorAll did not throw");
+        } catch(ex) {
+            log("PASS: Element.querySelectorAll throws: " + ex);
+        }
+    }
+</script>
+</head>
+<body>
+    <p>This tests that we throw a NOT_SUPPORTED_ERR when passing a NSResolver to querySelector and querySelectorAll
+        since we do not support it.</p>
+    <pre id="console"></pre>
+</body>
+</html>
index d8f7c6c..1802453 100644 (file)
@@ -1,3 +1,24 @@
+2008-07-07  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Geoffrey Garen.
+
+        Fix for https://bugs.webkit.org/show_bug.cgi?id=19928
+        querySelectorAll should throw an exception if a NSResolver is passed in.
+
+        - Throw an NOT_SUPPORTED_ERR if a non-null or undefined parameter is passed
+          as the second argument to querySelector or querySelectorAll.
+
+        Test: fast/dom/SelectorAPI/not-supported-NSResolver.html
+
+        * bindings/js/JSDocumentCustom.cpp:
+        (WebCore::JSDocument::querySelector):
+        (WebCore::JSDocument::querySelectorAll):
+        * bindings/js/JSElementCustom.cpp:
+        (WebCore::JSElement::querySelector):
+        (WebCore::JSElement::querySelectorAll):
+        * dom/Document.idl:
+        * dom/Element.idl:
+
 2008-07-07  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Mitz and Geoff
index 75cc6fa..00408ac 100644 (file)
 #include "JSDocument.h"
 
 #include "DOMWindow.h"
+#include "ExceptionCode.h"
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "HTMLDocument.h"
 #include "JSDOMWindowCustom.h"
 #include "JSHTMLDocument.h"
 #include "JSLocation.h"
+#include "JSNodeList.h"
 #include "Location.h"
+#include "NodeList.h"
 #include "ScriptController.h"
 
 #if ENABLE(SVG)
@@ -72,6 +75,34 @@ void JSDocument::setLocation(ExecState* exec, JSValue* value)
     frame->loader()->scheduleLocationChange(str, activeFrame->loader()->outgoingReferrer(), false, userGesture);
 }
 
+JSValue* JSDocument::querySelector(ExecState* exec, const ArgList& args)
+{
+    if (!args[1]->isUndefinedOrNull()) {
+        setDOMException(exec, NOT_SUPPORTED_ERR);
+        return jsUndefined();
+    }
+
+    Document* imp = impl();
+    ExceptionCode ec = 0;
+    JSValue* result = toJS(exec, imp->querySelector(valueToStringWithUndefinedOrNullCheck(exec, args[0]), ec));
+    setDOMException(exec, ec);
+    return result;
+}
+
+JSValue* JSDocument::querySelectorAll(ExecState* exec, const ArgList& args)
+{
+    if (!args[1]->isUndefinedOrNull()) {
+        setDOMException(exec, NOT_SUPPORTED_ERR);
+        return jsUndefined();
+    }
+
+    Document* imp = impl();
+    ExceptionCode ec = 0;
+    JSValue* result = toJS(exec, imp->querySelectorAll(valueToStringWithUndefinedOrNullCheck(exec, args[0]), ec));
+    setDOMException(exec, ec);
+    return result;
+}
+
 JSValue* toJS(ExecState* exec, Document* doc)
 {
     if (!doc)
index ffb5477..29858d0 100644 (file)
@@ -36,6 +36,8 @@
 #include "HTMLNames.h"
 #include "JSAttr.h"
 #include "JSHTMLElementWrapperFactory.h"
+#include "JSNodeList.h"
+#include "NodeList.h"
 
 #if ENABLE(SVG)
 #include "JSSVGElementWrapperFactory.h"
@@ -125,7 +127,34 @@ JSValue* JSElement::setAttributeNodeNS(ExecState* exec, const ArgList& args)
     return result;
 }
 
-    
+JSValue* JSElement::querySelector(ExecState* exec, const ArgList& args)
+{
+    if (!args[1]->isUndefinedOrNull()) {
+        setDOMException(exec, NOT_SUPPORTED_ERR);
+        return jsUndefined();
+    }
+
+    Element* imp = impl();
+    ExceptionCode ec = 0;
+    JSValue* result = toJS(exec, imp->querySelector(valueToStringWithUndefinedOrNullCheck(exec, args[0]), ec));
+    setDOMException(exec, ec);
+    return result;
+}
+
+JSValue* JSElement::querySelectorAll(ExecState* exec, const ArgList& args)
+{
+    if (!args[1]->isUndefinedOrNull()) {
+        setDOMException(exec, NOT_SUPPORTED_ERR);
+        return jsUndefined();
+    }
+
+    Element* imp = impl();
+    ExceptionCode ec = 0;
+    JSValue* result = toJS(exec, imp->querySelectorAll(valueToStringWithUndefinedOrNullCheck(exec, args[0]), ec));
+    setDOMException(exec, ec);
+    return result;
+}
+
 JSValue* toJSNewlyCreated(ExecState* exec, Element* element)
 {
     if (!element)
index 0fbd15f..68b529b 100644 (file)
@@ -233,12 +233,12 @@ module core {
 #endif
 
         // HTML 5
-        NodeList            getElementsByClassName(in DOMString tagname);
+        NodeList getElementsByClassName(in DOMString tagname);
 
-        // DocumentSelector - Selector API
-        Element             querySelector(in [ConvertUndefinedOrNullToNullString] DOMString selectors)
+        // NodeSelector - Selector API
+        [Custom] Element querySelector(in [ConvertUndefinedOrNullToNullString] DOMString selectors)
             raises(DOMException);
-        NodeList            querySelectorAll(in [ConvertUndefinedOrNullToNullString] DOMString selectors)
+        [Custom] NodeList querySelectorAll(in [ConvertUndefinedOrNullToNullString] DOMString selectors)
             raises(DOMException);
     };
 
index 569e87c..46b960e 100644 (file)
@@ -103,10 +103,10 @@ module core {
         // HTML 5
         NodeList getElementsByClassName(in DOMString name);
 
-        // ElementSelector - Selector API
-        Element             querySelector(in [ConvertUndefinedOrNullToNullString] DOMString selectors)
+        // NodeSelector - Selector API
+        [Custom] Element querySelector(in [ConvertUndefinedOrNullToNullString] DOMString selectors)
             raises(DOMException);
-        NodeList            querySelectorAll(in [ConvertUndefinedOrNullToNullString] DOMString selectors)
+        [Custom] NodeList querySelectorAll(in [ConvertUndefinedOrNullToNullString] DOMString selectors)
             raises(DOMException);
 
         // ElementTraversal API