Bug 816380. Convert XPathEvaluator to WebIDL. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 14 Dec 2012 14:10:49 -0500
changeset 125205 3e0b4ce62d6dd8c24c23b531ffb7ac8974ba2c3e
parent 125204 7b9ffa4e1e64753b5ca65dbcd967815ae15cfac8
child 125206 c833cab38b083cdca0521eb057ed5bd5a19d6014
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs816380
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 816380. Convert XPathEvaluator to WebIDL. r=peterv
content/xslt/src/xpath/nsXPathEvaluator.cpp
content/xslt/src/xpath/nsXPathEvaluator.h
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/bindings/Bindings.conf
dom/bindings/Makefile.in
dom/webidl/WebIDL.mk
dom/webidl/XPathEvaluator.webidl
--- a/content/xslt/src/xpath/nsXPathEvaluator.cpp
+++ b/content/xslt/src/xpath/nsXPathEvaluator.cpp
@@ -1,30 +1,32 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsXPathEvaluator.h"
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
-#include "nsDOMClassInfoID.h"
 #include "nsXPathExpression.h"
 #include "nsXPathNSResolver.h"
 #include "nsXPathResult.h"
 #include "nsContentCID.h"
 #include "txExpr.h"
 #include "txExprParser.h"
 #include "nsError.h"
 #include "txURIUtils.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsDOMString.h"
 #include "nsINameSpaceManager.h"
 #include "nsContentUtils.h"
+#include "mozilla/dom/XPathEvaluatorBinding.h"
+
+using namespace mozilla;
 
 // txIParseContext implementation
 class nsXPathEvaluatorParseContext : public txIParseContext
 {
 public:
     nsXPathEvaluatorParseContext(nsIDOMXPathNSResolver* aResolver,
                                  nsTArray<int32_t> *aNamespaceIDs,
                                  nsTArray<nsCString> *aContractIDs,
@@ -57,23 +59,20 @@ private:
     nsIDOMXPathNSResolver* mResolver;
     nsTArray<int32_t> *mNamespaceIDs;
     nsTArray<nsCString> *mContractIDs;
     nsCOMArray<nsISupports> *mState;
     nsresult mLastError;
     bool mIsCaseSensitive;
 };
 
-DOMCI_DATA(XPathEvaluator, nsXPathEvaluator)
-
 NS_IMPL_AGGREGATED(nsXPathEvaluator)
 NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsXPathEvaluator)
     NS_INTERFACE_MAP_ENTRY(nsIDOMXPathEvaluator)
     NS_INTERFACE_MAP_ENTRY(nsIXPathEvaluatorInternal)
-    NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(XPathEvaluator)
 NS_INTERFACE_MAP_END
 
 nsXPathEvaluator::nsXPathEvaluator(nsISupports *aOuter)
 {
     NS_INIT_AGGREGATED(aOuter);
 }
 
 nsresult
@@ -208,16 +207,64 @@ nsXPathEvaluator::CreateExpression(const
     if (!*aResult) {
         return NS_ERROR_OUT_OF_MEMORY;
     }
 
     NS_ADDREF(*aResult);
     return NS_OK;
 }
 
+JSObject*
+nsXPathEvaluator::WrapObject(JSContext* aCx, JSObject* aScope)
+{
+    return dom::XPathEvaluatorBinding::Wrap(aCx, aScope, this);
+}
+
+/* static */
+already_AddRefed<nsXPathEvaluator>
+nsXPathEvaluator::Constructor(nsISupports* aGlobal, ErrorResult& rv)
+{
+    nsRefPtr<nsXPathEvaluator> newObj = new nsXPathEvaluator(nullptr);
+    newObj->Init();
+    return newObj.forget();
+}
+
+already_AddRefed<nsIDOMXPathExpression>
+nsXPathEvaluator::CreateExpression(const nsAString& aExpression,
+                                   nsIDOMXPathNSResolver* aResolver,
+                                   ErrorResult& rv)
+{
+  nsCOMPtr<nsIDOMXPathExpression> expr;
+  rv = CreateExpression(aExpression, aResolver, getter_AddRefs(expr));
+  return expr.forget();
+}
+
+already_AddRefed<nsIDOMXPathNSResolver>
+nsXPathEvaluator::CreateNSResolver(nsINode* aNodeResolver,
+                                   ErrorResult& rv)
+{
+  nsCOMPtr<nsIDOMNode> nodeResolver = do_QueryInterface(aNodeResolver);
+  nsCOMPtr<nsIDOMXPathNSResolver> res;
+  rv = CreateNSResolver(nodeResolver, getter_AddRefs(res));
+  return res.forget();
+}
+
+already_AddRefed<nsISupports>
+nsXPathEvaluator::Evaluate(const nsAString& aExpression, nsINode* aContextNode,
+                           nsIDOMXPathNSResolver* aResolver, uint16_t aType,
+                           nsISupports* aResult, ErrorResult& rv)
+{
+  nsCOMPtr<nsIDOMNode> contextNode = do_QueryInterface(aContextNode);
+  nsCOMPtr<nsISupports> res;
+  rv = Evaluate(aExpression, contextNode, aResolver, aType,
+                aResult, getter_AddRefs(res));
+  return res.forget();
+}
+
+
 /*
  * Implementation of txIParseContext private to nsXPathEvaluator, based on a
  * nsIDOMXPathNSResolver
  */
 
 nsresult nsXPathEvaluatorParseContext::resolveNamespacePrefix
     (nsIAtom* aPrefix, int32_t& aID)
 {
--- a/content/xslt/src/xpath/nsXPathEvaluator.h
+++ b/content/xslt/src/xpath/nsXPathEvaluator.h
@@ -10,16 +10,19 @@
 #include "nsIXPathEvaluatorInternal.h"
 #include "nsIWeakReference.h"
 #include "nsAutoPtr.h"
 #include "nsString.h"
 #include "txResultRecycler.h"
 #include "nsAgg.h"
 #include "nsTArray.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/ErrorResult.h"
+
+class nsINode;
 
 /**
  * A class for evaluating an XPath expression string
  */
 class nsXPathEvaluator MOZ_FINAL : public nsIDOMXPathEvaluator,
                                    public nsIXPathEvaluatorInternal
 {
 public:
@@ -37,16 +40,30 @@ public:
     NS_IMETHOD SetDocument(nsIDOMDocument* aDocument);
     NS_IMETHOD CreateExpression(const nsAString &aExpression, 
                                 nsIDOMXPathNSResolver *aResolver,
                                 nsTArray<nsString> *aNamespaceURIs,
                                 nsTArray<nsCString> *aContractIDs,
                                 nsCOMArray<nsISupports> *aState,
                                 nsIDOMXPathExpression **aResult);
 
+    // WebIDL API
+    JSObject* WrapObject(JSContext* aCx, JSObject* aScope);
+    static already_AddRefed<nsXPathEvaluator>
+        Constructor(nsISupports* aGlobal, mozilla::ErrorResult& rv);
+    already_AddRefed<nsIDOMXPathExpression>
+        CreateExpression(const nsAString& aExpression,
+                         nsIDOMXPathNSResolver* aResolver,
+                         mozilla::ErrorResult& rv);
+    already_AddRefed<nsIDOMXPathNSResolver>
+        CreateNSResolver(nsINode* aNodeResolver, mozilla::ErrorResult& rv);
+    already_AddRefed<nsISupports>
+        Evaluate(const nsAString& aExpression, nsINode* aContextNode,
+                 nsIDOMXPathNSResolver* aResolver, uint16_t aType,
+                 nsISupports* aResult, mozilla::ErrorResult& rv);
 private:
     nsresult CreateExpression(const nsAString & aExpression,
                               nsIDOMXPathNSResolver *aResolver,
                               nsTArray<int32_t> *aNamespaceIDs,
                               nsTArray<nsCString> *aContractIDs,
                               nsCOMArray<nsISupports> *aState,
                               nsIDOMXPathExpression **aResult);
 
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -1348,18 +1348,16 @@ static nsDOMClassInfoData sClassInfoData
   NS_DEFINE_CLASSINFO_DATA(SmartCardEvent, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(WindowUtils, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(XSLTProcessor, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
-  NS_DEFINE_CLASSINFO_DATA(XPathEvaluator, nsDOMGenericSH,
-                           DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(XPathExpression, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(XPathNSResolver, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(XPathResult, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   // WhatWG Storage
@@ -1693,17 +1691,16 @@ static nsDOMClassInfoData sClassInfoData
     nsresult rv = NS_OK;                                                        \
     nsCOMPtr<nsISupports> native = do_CreateInstance(_contract_id, &rv);        \
     native.forget(aInstancePtrResult);                                          \
     return rv;                                                                  \
   }
 
 NS_DEFINE_CONTRACT_CTOR(FileReader, NS_FILEREADER_CONTRACTID)
 NS_DEFINE_CONTRACT_CTOR(ArchiveReader, NS_ARCHIVEREADER_CONTRACTID)
-NS_DEFINE_CONTRACT_CTOR(XPathEvaluator, NS_XPATH_EVALUATOR_CONTRACTID)
 NS_DEFINE_CONTRACT_CTOR(XSLTProcessor,
                         "@mozilla.org/document-transformer;1?type=xslt")
 NS_DEFINE_CONTRACT_CTOR(EventSource, NS_EVENTSOURCE_CONTRACTID)
 NS_DEFINE_CONTRACT_CTOR(MutationObserver, NS_DOMMUTATIONOBSERVER_CONTRACTID)
 #ifdef MOZ_SYS_MSG
 NS_DEFINE_CONTRACT_CTOR(MozActivity, NS_DOMACTIVITY_CONTRACTID)
 #endif
 
@@ -1757,17 +1754,16 @@ static const nsConstructorFuncMapData kC
 #define MOZ_GENERATED_EVENT_LIST
 #define MOZ_GENERATED_EVENT(_event_interface) \
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(_event_interface)
 #include "GeneratedEvents.h"
 #undef MOZ_GENERATED_EVENT_LIST
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozSmsFilter, sms::SmsFilter::NewSmsFilter)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(FileReader, FileReaderCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(ArchiveReader, ArchiveReaderCtor)
-  NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XPathEvaluator, XPathEvaluatorCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XSLTProcessor, XSLTProcessorCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(EventSource, EventSourceCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MutationObserver, MutationObserverCtor)
 #ifdef MOZ_SYS_MSG
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozActivity, MozActivityCtor)
 #endif
 };
 #undef NS_DEFINE_CONSTRUCTOR_FUNC_DATA
@@ -3839,20 +3835,16 @@ nsDOMClassInfo::Init()
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozCanvasPrintState)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(XSLTProcessor, nsIXSLTProcessor)
     DOM_CLASSINFO_MAP_ENTRY(nsIXSLTProcessor)
     DOM_CLASSINFO_MAP_ENTRY(nsIXSLTProcessorPrivate)
   DOM_CLASSINFO_MAP_END
 
-  DOM_CLASSINFO_MAP_BEGIN(XPathEvaluator, nsIDOMXPathEvaluator)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMXPathEvaluator)
-  DOM_CLASSINFO_MAP_END
-
   DOM_CLASSINFO_MAP_BEGIN(XPathExpression, nsIDOMXPathExpression)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMXPathExpression)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSXPathExpression)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(XPathNSResolver, nsIDOMXPathNSResolver)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMXPathNSResolver)
   DOM_CLASSINFO_MAP_END
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -318,17 +318,16 @@ DOMCI_CLASS(SmartCardEvent)
 
 // WindowUtils
 DOMCI_CLASS(WindowUtils)
 
 // XSLTProcessor
 DOMCI_CLASS(XSLTProcessor)
 
 // DOM Level 3 XPath objects
-DOMCI_CLASS(XPathEvaluator)
 DOMCI_CLASS(XPathExpression)
 DOMCI_CLASS(XPathNSResolver)
 DOMCI_CLASS(XPathResult)
 
 // WhatWG WebApps Objects
 DOMCI_CLASS(StorageObsolete)
 DOMCI_CLASS(Storage)
 DOMCI_CLASS(StorageItem)
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -571,16 +571,22 @@ DOMInterfaces = {
 {
     'workers': True,
 }],
 
 'XMLSerializer': {
     'nativeType': 'nsDOMSerializer',
 },
 
+'XPathEvaluator': {
+    'nativeType': 'nsXPathEvaluator',
+    'headerFile': 'nsXPathEvaluator.h',
+    'wrapperCache': False
+},
+
 ####################################
 # Test Interfaces of various sorts #
 ####################################
 
 'TestInterface' : {
         # Keep this in sync with TestExampleInterface
         'headerFile': 'TestBindingHeader.h',
         'register': False,
@@ -776,16 +782,17 @@ addExternalIface('DocumentType', nativeT
 addExternalIface('DOMRequest')
 addExternalIface('DOMStringList', nativeType='nsDOMStringList',
                  headerFile='nsDOMLists.h')
 addExternalIface('File')
 addExternalIface('HitRegionOptions', nativeType='nsISupports')
 addExternalIface('LockedFile')
 addExternalIface('MediaStream')
 addExternalIface('NamedNodeMap')
+addExternalIface('nsISupports', nativeType='nsISupports')
 addExternalIface('OutputStream', nativeType='nsIOutputStream',
                  notflattened=True)
 addExternalIface('PaintRequest')
 addExternalIface('Principal', nativeType='nsIPrincipal',
                  headerFile='nsIPrincipal.h', notflattened=True)
 addExternalIface('SVGLength')
 addExternalIface('SVGMatrix')
 addExternalIface('SVGNumber')
@@ -795,9 +802,10 @@ addExternalIface('SVGTransform')
 addExternalIface("Rect")
 addExternalIface("RGBColor")
 addExternalIface('TextMetrics', headerFile='nsIDOMCanvasRenderingContext2D.h')
 addExternalIface('Touch', headerFile='nsIDOMTouchEvent.h')
 addExternalIface('URI', nativeType='nsIURI', headerFile='nsIURI.h',
                  notflattened=True)
 addExternalIface('UserDataHandler')
 addExternalIface('Window')
+addExternalIface('XPathResult', nativeType='nsISupports')
 addExternalIface('XULElement')
--- a/dom/bindings/Makefile.in
+++ b/dom/bindings/Makefile.in
@@ -74,16 +74,18 @@ EXPORTS_$(binding_include_path) = \
   $(NULL)
 
 LOCAL_INCLUDES += -I$(topsrcdir)/js/xpconnect/src \
   -I$(topsrcdir)/js/xpconnect/wrappers \
   -I$(topsrcdir)/content/canvas/src \
   -I$(topsrcdir)/content/html/content/src \
   -I$(topsrcdir)/media/webrtc/signaling/src/peerconnection \
   -I$(topsrcdir)/dom/base \
+  -I$(topsrcdir)/content/xslt/src/base \
+  -I$(topsrcdir)/content/xslt/src/xpath \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
 # If you change bindinggen_dependencies here, change it in
 # dom/bindings/test/Makefile.in too.
 bindinggen_dependencies := \
   BindingGen.py \
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -64,16 +64,17 @@ webidl_files = \
   TextDecoder.webidl \
   TextEncoder.webidl \
   URL.webidl \
   WebSocket.webidl \
   XMLHttpRequest.webidl \
   XMLHttpRequestEventTarget.webidl \
   XMLHttpRequestUpload.webidl \
   XMLSerializer.webidl \
+  XPathEvaluator.webidl \
   $(NULL)
 
 ifdef MOZ_WEBGL
 webidl_files += \
   WebGLRenderingContext.webidl \
   $(NULL)
 endif
 
new file mode 100644
--- /dev/null
+++ b/dom/webidl/XPathEvaluator.webidl
@@ -0,0 +1,24 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+interface nsISupports;
+interface XPathExpression;
+interface XPathNSResolver;
+interface XPathResult;
+
+[Constructor]
+interface XPathEvaluator {
+  // Based on nsIDOMXPathEvaluator
+  [Creator, Throws]
+  XPathExpression createExpression(DOMString expression,
+                                   XPathNSResolver? resolver);
+  [Creator, Throws]
+  XPathNSResolver createNSResolver(Node? nodeResolver);
+  [Throws]
+  XPathResult evaluate(DOMString expression, Node? contextNode,
+                       XPathNSResolver? resolver, unsigned short type,
+                       XPathResult? result);
+};