Three XSLTProcessor functions don't need to be [Custom]
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Sep 2012 09:17:10 +0000 (09:17 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Sep 2012 09:17:10 +0000 (09:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=95899

Patch by Adam Barth <abarth@chromium.org> on 2012-09-06
Reviewed by Kentaro Hara.

Source/WebCore:

These functions are marked [Custom] because they predate our
improvements to [Optional]. Now that we have
[Optional=DefaultIsUndefined], we can autogenerate these functions.

There is a (slight!) difference in behavior. Now, in the case of a type
error, we return null instead of undefined. This change is unlikely to
cause compatibility problems because the vast majority of folks will
pass the correct arguments, and, in the few cases where folks pass the
wrong argument types, null and undefined will likely work similarly
(e.g., they're both falsy and throw when you try to access properties).

* bindings/js/JSXSLTProcessorCustom.cpp:
* bindings/v8/custom/V8XSLTProcessorCustom.cpp:
* xml/XSLTProcessor.cpp:
(WebCore::XSLTProcessor::transformToDocument):
(WebCore::XSLTProcessor::transformToFragment):
* xml/XSLTProcessor.h:
(WebCore::XSLTProcessor::importStylesheet):
* xml/XSLTProcessor.idl:

LayoutTests:

Update results to show that we return null rather than undefined on a
type error.

* fast/xsl/transform-xhr-doc-expected.txt:
* fast/xsl/xslt-processor-expected.txt:
* platform/chromium/fast/xsl/transform-xhr-doc-expected.txt:

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

LayoutTests/ChangeLog
LayoutTests/fast/xsl/transform-xhr-doc-expected.txt
LayoutTests/fast/xsl/xslt-processor-expected.txt
LayoutTests/platform/chromium/fast/xsl/transform-xhr-doc-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSXSLTProcessorCustom.cpp
Source/WebCore/bindings/v8/custom/V8XSLTProcessorCustom.cpp
Source/WebCore/xml/XSLTProcessor.cpp
Source/WebCore/xml/XSLTProcessor.h
Source/WebCore/xml/XSLTProcessor.idl

index 0f5e2a6..df3cd5f 100644 (file)
@@ -1,3 +1,17 @@
+2012-09-06  Adam Barth  <abarth@chromium.org>
+
+        Three XSLTProcessor functions don't need to be [Custom]
+        https://bugs.webkit.org/show_bug.cgi?id=95899
+
+        Reviewed by Kentaro Hara.
+
+        Update results to show that we return null rather than undefined on a
+        type error.
+
+        * fast/xsl/transform-xhr-doc-expected.txt:
+        * fast/xsl/xslt-processor-expected.txt:
+        * platform/chromium/fast/xsl/transform-xhr-doc-expected.txt:
+
 2012-09-06  Krist√≥f Koszty√≥  <kkristof@inf.u-szeged.hu>
 
         [Qt] Unreviewed gardening. Skip the failing tests.
index 5bb0ad6..77eb850 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 20: TypeError: 'undefined' is not an object (evaluating 'doc.documentElement')
+CONSOLE MESSAGE: line 20: TypeError: 'null' is not an object (evaluating 'doc.documentElement')
 Test for bug 10313: xsl:import doesn't work in stylesheets loaded via XMLHttpRequest.
 
 It's nice that this hasn't crashed, but the XSL transformation has failed.
index d944d11..8517f99 100644 (file)
@@ -56,11 +56,11 @@ Success
 2.0 DOMDocumentFragment transformToFragment(in DOMNode source, in DOMDocument output):
 
 2.1 fragment with undefined source:
-****Failure**** (expected exception, instead got result: "undefined")
+****Failure**** (expected exception, instead got result: "null")
 2.2 fragment with undefined output document:
 Success
 2.3 use non-DOMDocument output parameter:
-****Failure**** (expected exception, instead got result: "undefined")
+****Failure**** (expected exception, instead got result: "null")
 2.4 transform to same fragment twice:
 Success
 2.5 transformed fragment containing only text:
@@ -71,7 +71,7 @@ Success
 3.0 DOMDocument transformToDocument(in DOMNode source):
 
 3.1 use non-DOMDocument output parameter:
-****Failure**** (expected exception, instead got result: "undefined")
+****Failure**** (expected exception, instead got result: "null")
 3.2 transform twice:
 Success
 
index 8ae2362..065c12e 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 20: Uncaught TypeError: Cannot read property 'documentElement' of undefined
+CONSOLE MESSAGE: line 20: Uncaught TypeError: Cannot read property 'documentElement' of null
 Test for bug 10313: xsl:import doesn't work in stylesheets loaded via XMLHttpRequest.
 
 It's nice that this hasn't crashed, but the XSL transformation has failed.
index 1aaefaf..0942e6f 100644 (file)
@@ -1,3 +1,30 @@
+2012-09-06  Adam Barth  <abarth@chromium.org>
+
+        Three XSLTProcessor functions don't need to be [Custom]
+        https://bugs.webkit.org/show_bug.cgi?id=95899
+
+        Reviewed by Kentaro Hara.
+
+        These functions are marked [Custom] because they predate our
+        improvements to [Optional]. Now that we have
+        [Optional=DefaultIsUndefined], we can autogenerate these functions.
+
+        There is a (slight!) difference in behavior. Now, in the case of a type
+        error, we return null instead of undefined. This change is unlikely to
+        cause compatibility problems because the vast majority of folks will
+        pass the correct arguments, and, in the few cases where folks pass the
+        wrong argument types, null and undefined will likely work similarly
+        (e.g., they're both falsy and throw when you try to access properties).
+
+        * bindings/js/JSXSLTProcessorCustom.cpp:
+        * bindings/v8/custom/V8XSLTProcessorCustom.cpp:
+        * xml/XSLTProcessor.cpp:
+        (WebCore::XSLTProcessor::transformToDocument):
+        (WebCore::XSLTProcessor::transformToFragment):
+        * xml/XSLTProcessor.h:
+        (WebCore::XSLTProcessor::importStylesheet):
+        * xml/XSLTProcessor.idl:
+
 2012-09-06  Patrick Gansterer  <paroga@webkit.org>
 
         Remove String::operator+=() from plugin code
index d83ff38..d0f36a7 100644 (file)
@@ -46,45 +46,6 @@ using namespace JSC;
 
 namespace WebCore {
 
-JSValue JSXSLTProcessor::importStylesheet(ExecState* exec)
-{
-    JSValue nodeVal = exec->argument(0);
-    if (nodeVal.inherits(&JSNode::s_info)) {
-        JSNode* node = jsCast<JSNode*>(asObject(nodeVal));
-        impl()->importStylesheet(node->impl());
-        return jsUndefined();
-    }
-    // Throw exception?
-    return jsUndefined();
-}
-
-JSValue JSXSLTProcessor::transformToFragment(ExecState* exec)
-{
-    JSValue nodeVal = exec->argument(0);
-    JSValue docVal = exec->argument(1);
-    if (nodeVal.inherits(&JSNode::s_info) && docVal.inherits(&JSDocument::s_info)) {
-        WebCore::Node* node = jsCast<JSNode*>(asObject(nodeVal))->impl();
-        Document* doc = static_cast<Document*>(jsCast<JSDocument*>(asObject(docVal))->impl());
-        return toJS(exec, globalObject(), impl()->transformToFragment(node, doc).get());
-    }
-    // Throw exception?
-    return jsUndefined();
-}
-
-JSValue JSXSLTProcessor::transformToDocument(ExecState* exec)
-{
-    JSValue nodeVal = exec->argument(0);
-    if (nodeVal.inherits(&JSNode::s_info)) {
-        JSNode* node = jsCast<JSNode*>(asObject(nodeVal));
-        RefPtr<Document> resultDocument = impl()->transformToDocument(node->impl());
-        if (resultDocument)
-            return toJS(exec, globalObject(), resultDocument.get());
-        return jsUndefined();
-    }
-    // Throw exception?
-    return jsUndefined();
-}
-
 JSValue JSXSLTProcessor::setParameter(ExecState* exec)
 {
     if (exec->argument(1).isUndefinedOrNull() || exec->argument(2).isUndefinedOrNull())
index 87228c9..29013f1 100644 (file)
 
 namespace WebCore {
 
-v8::Handle<v8::Value> V8XSLTProcessor::importStylesheetCallback(const v8::Arguments& args)
-{
-    INC_STATS("DOM.XSLTProcessor.importStylesheet");
-    if (!V8Node::HasInstance(args[0]))
-        return v8::Undefined();
-
-    XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder());
-
-    Node* node = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0]));
-    imp->importStylesheet(node);
-    return v8::Undefined();
-}
-
-
-v8::Handle<v8::Value> V8XSLTProcessor::transformToFragmentCallback(const v8::Arguments& args)
-{
-    INC_STATS("DOM.XSLTProcessor.transformToFragment");
-    if (!V8Node::HasInstance(args[0]) || !V8Document::HasInstance(args[1]))
-        return v8::Undefined();
-
-    XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder());
-
-    Node* source = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0]));
-    Document* owner = V8Document::toNative(v8::Handle<v8::Object>::Cast(args[1]));
-    RefPtr<DocumentFragment> result = imp->transformToFragment(source, owner);
-    return toV8(result.release(), args.GetIsolate());
-}
-
-
-v8::Handle<v8::Value> V8XSLTProcessor::transformToDocumentCallback(const v8::Arguments& args)
-{
-    INC_STATS("DOM.XSLTProcessor.transformToDocument");
-
-    if (!V8Node::HasInstance(args[0]))
-        return v8::Undefined();
-
-    XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder());
-
-    Node* source = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0]));
-    if (!source)
-        return v8::Undefined();
-
-    RefPtr<Document> result = imp->transformToDocument(source);
-    if (!result)
-        return v8::Undefined();
-
-    return toV8(result.release(), args.GetIsolate());
-}
-
-
 v8::Handle<v8::Value> V8XSLTProcessor::setParameterCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.XSLTProcessor.setParameter");
@@ -114,7 +64,6 @@ v8::Handle<v8::Value> V8XSLTProcessor::setParameterCallback(const v8::Arguments&
     return v8::Undefined();
 }
 
-
 v8::Handle<v8::Value> V8XSLTProcessor::getParameterCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.XSLTProcessor.getParameter");
index 0e23235..6cf7937 100644 (file)
@@ -110,6 +110,9 @@ PassRefPtr<Document> XSLTProcessor::createDocumentFromSource(const String& sourc
 
 PassRefPtr<Document> XSLTProcessor::transformToDocument(Node* sourceNode)
 {
+    if (!sourceNode)
+        return 0;
+
     String resultMIMEType;
     String resultString;
     String resultEncoding;
@@ -120,6 +123,9 @@ PassRefPtr<Document> XSLTProcessor::transformToDocument(Node* sourceNode)
 
 PassRefPtr<DocumentFragment> XSLTProcessor::transformToFragment(Node* sourceNode, Document* outputDoc)
 {
+    if (!sourceNode || !outputDoc)
+        return 0;
+
     String resultMIMEType;
     String resultString;
     String resultEncoding;
index 451e12c..81f4a6a 100644 (file)
@@ -51,7 +51,11 @@ public:
     PassRefPtr<Document> createDocumentFromSource(const String& source, const String& sourceEncoding, const String& sourceMIMEType, Node* sourceNode, Frame* frame);
     
     // DOM methods
-    void importStylesheet(PassRefPtr<Node> style) { m_stylesheetRootNode = style; }
+    void importStylesheet(PassRefPtr<Node> style)
+    {
+        if (style)
+            m_stylesheetRootNode = style;
+    }
     PassRefPtr<DocumentFragment> transformToFragment(Node* source, Document* ouputDoc);
     PassRefPtr<Document> transformToDocument(Node* source);
     
index 48ec6c2..c739b01 100644 (file)
@@ -37,9 +37,9 @@ module xml {
         Constructor
     ] XSLTProcessor {
         
-        [Custom] void importStylesheet(in Node stylesheet);
-        [Custom] DocumentFragment transformToFragment(in Node source, in Document docVal);
-        [Custom] Document transformToDocument(in Node source);
+        void importStylesheet(in [Optional=DefaultIsUndefined] Node stylesheet);
+        DocumentFragment transformToFragment(in [Optional=DefaultIsUndefined] Node source, in [Optional=DefaultIsUndefined] Document docVal);
+        Document transformToDocument(in [Optional=DefaultIsUndefined] Node source);
 
         [Custom] void setParameter(in DOMString namespaceURI, in DOMString localName, in DOMString value);
         [Custom, TreatReturnedNullStringAs=Undefined] DOMString getParameter(in DOMString namespaceURI, in DOMString localName);