Bug 1019191 part 12. Eliminate some unused UnwrapArg specializations. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 22 Oct 2014 11:40:48 -0400
changeset 211768 28abe750b8ef6a3d2f5f1643554045ecd8a18a01
parent 211767 649e33dfabd6f8fb975e0766515761c28a739542
child 211769 63d3d488d188de36a4e66cf8db8c8c5b502b0f02
push id2
push usergszorc@mozilla.com
push dateWed, 29 Oct 2014 00:55:10 +0000
reviewerspeterv
bugs1019191
milestone36.0a1
Bug 1019191 part 12. Eliminate some unused UnwrapArg specializations. r=peterv The following command: grep -Ir "UnwrapArg<" $srcdir/* $objdir/dom/bindings/ | sed 's/^[^<]*<//' | sed 's/>.*//' | sort -u (with $srcdir and $objdir replaced by the relevant paths) produces this list: ${type} _clazz _interface imgINotificationObserver imgIRequest mozilla::dom::EventTarget mozilla::dom::IndirectlyImplementedInterface mozilla::dom::TestExternalInterface nsGenericHTMLElement nsIBrowserDOMWindow nsIChannel nsIDOMCSSRule nsIDOMDataChannel nsIDOMMozMmsMessage nsIDOMMozSmsMessage nsIDOMMozWakeLockListener nsIDOMWindow nsIDOMXPathNSResolver nsIFile nsIFrameRequestCallback nsIInputStream nsIInputStreamCallback nsIJSID nsIMenuBuilder nsIObserver nsIOutputStream nsIPrincipal nsISelectionListener nsISupports nsITreeView nsIURI The ${type} bit is part of codegen. The _clazz and _interface bits are the macros in js/xpconnect/src/nsDOMQS.h that are defining UnwrapArg methods. The nsGenericHTMLElement is only used in xpc_qsUnwrapArg_HTMLElement. Inspection of the above list indicates that none of the classes used with DEFINE_UNWRAP_CAST_HTML are in it, so all those specializations of UnwrapArg, and the xpc_qsUnwrapArg_HTMLElement method they call, are dead code. Moreover, almost all the specializations set up by DEFINE_UNWRAP_CAST are dead code as well; the only exception is the one for mozilla::dom::EventTarget. But since we no longer use Web IDL quickstubs for EventTarget, that one is only used in a few places for method arguments, and none of those should have our one remaining webidl event target passed to them. So it's safe to remove that specialization as well.
js/xpconnect/src/nsDOMQS.h
--- a/js/xpconnect/src/nsDOMQS.h
+++ b/js/xpconnect/src/nsDOMQS.h
@@ -26,163 +26,16 @@
 #include "mozilla/dom/ElementBinding.h"
 #include "mozilla/dom/HTMLElementBinding.h"
 #include "mozilla/dom/DocumentBinding.h"
 #include "mozilla/dom/SVGElementBinding.h"
 #include "mozilla/dom/HTMLDocumentBinding.h"
 #include "XPCQuickStubs.h"
 #include "nsGlobalWindow.h"
 
-template<class T>
-struct ProtoIDAndDepth
-{
-    enum {
-        PrototypeID = mozilla::dom::prototypes::id::_ID_Count,
-        Depth = -1
-    };
-};
-
-#define NEW_BINDING(_native, _id)                                             \
-template<>                                                                    \
-struct ProtoIDAndDepth<_native>                                               \
-{                                                                             \
-    enum {                                                                    \
-        PrototypeID = mozilla::dom::prototypes::id::_id,                      \
-        Depth = mozilla::dom::PrototypeTraits<                                \
-            static_cast<mozilla::dom::prototypes::ID>(PrototypeID)>::Depth    \
-    };                                                                        \
-}
-
-NEW_BINDING(mozilla::dom::EventTarget, EventTarget);
-NEW_BINDING(nsINode, Node);
-NEW_BINDING(mozilla::dom::Element, Element);
-NEW_BINDING(nsGenericHTMLElement, HTMLElement);
-NEW_BINDING(nsIDocument, Document);
-NEW_BINDING(nsDocument, Document);
-NEW_BINDING(nsHTMLDocument, HTMLDocument);
-NEW_BINDING(nsSVGElement, SVGElement);
-NEW_BINDING(mozilla::dom::Event, Event);
-NEW_BINDING(mozilla::dom::UIEvent, UIEvent);
-NEW_BINDING(mozilla::dom::MouseEvent, MouseEvent);
-NEW_BINDING(nsGlobalWindow, Window);
-
-#define DEFINE_UNWRAP_CAST(_interface, _base, _bit)                           \
-namespace mozilla {                                                           \
-namespace dom {                                                               \
-                                                                              \
-template <>                                                                   \
-MOZ_ALWAYS_INLINE nsresult                                                    \
-UnwrapArg<_interface>(JSContext *cx,                                          \
-                      JS::HandleValue v,                                      \
-                      _interface **ppArg,                                     \
-                      nsISupports **ppArgRef,                                 \
-                      JS::MutableHandleValue vp)                              \
-{                                                                             \
-    nsresult rv;                                                              \
-    nsISupports *native =                                                     \
-        castNativeArgFromWrapper(cx, v, _bit,                                 \
-                                 ProtoIDAndDepth<_interface>::PrototypeID,    \
-                                 ProtoIDAndDepth<_interface>::Depth,          \
-                                 ppArgRef, vp, &rv);                          \
-    if (NS_SUCCEEDED(rv))                                                     \
-        *ppArg = static_cast<_interface*>(static_cast<_base*>(native));       \
-    return rv;                                                                \
-}                                                                             \
-                                                                              \
-template <>                                                                   \
-inline nsresult                                                               \
-UnwrapArg<_interface>(JSContext *cx,                                          \
-                      JS::HandleValue v,                                      \
-                      _interface **ppArg,                                     \
-                      _interface **ppArgRef,                                  \
-                      JS::MutableHandleValue vp)                              \
-{                                                                             \
-    nsISupports* argRef = static_cast<_base*>(*ppArgRef);                     \
-    nsresult rv = UnwrapArg<_interface>(cx, v, ppArg, &argRef, vp);           \
-    *ppArgRef = static_cast<_interface*>(static_cast<_base*>(argRef));        \
-    return rv;                                                                \
-}                                                                             \
-                                                                              \
-} /* namespace dom */                                                         \
-} /* namespace mozilla */
-
-#undef DOMCI_CASTABLE_INTERFACE
-
-#undef DOMCI_CASTABLE_INTERFACE
-#define DOMCI_CASTABLE_INTERFACE(_interface, _base, _bit, _extra)             \
-  DEFINE_UNWRAP_CAST(_interface, _base, _bit)
-
-DOMCI_CASTABLE_INTERFACES(unused)
-
-#undef DOMCI_CASTABLE_INTERFACE
-
-inline nsresult
-xpc_qsUnwrapArg_HTMLElement(JSContext *cx,
-                            JS::HandleValue v,
-                            nsIAtom *aTag,
-                            nsIContent **ppArg,
-                            nsISupports **ppArgRef,
-                            JS::MutableHandleValue vp)
-{
-    nsGenericHTMLElement *elem;
-    JS::RootedValue val(cx);
-    nsresult rv =
-        UnwrapArg<nsGenericHTMLElement>(cx, v, &elem, ppArgRef, &val);
-    if (NS_SUCCEEDED(rv)) {
-        if (elem->IsHTML(aTag)) {
-            *ppArg = elem;
-            vp.set(val);
-        } else {
-            rv = NS_ERROR_XPC_BAD_CONVERT_JS;
-        }
-    }
-    return rv;
-}
-
-#define DEFINE_UNWRAP_CAST_HTML(_tag, _clazz)                                 \
-namespace mozilla {                                                           \
-namespace dom {                                                               \
-                                                                              \
-template <>                                                                   \
-inline nsresult                                                               \
-UnwrapArg<_clazz>(JSContext *cx,                                              \
-                  JS::HandleValue v,                                          \
-                  _clazz **ppArg,                                             \
-                  nsISupports **ppArgRef,                                     \
-                  JS::MutableHandleValue vp)                                  \
-{                                                                             \
-    nsIContent *elem;                                                         \
-    nsresult rv = xpc_qsUnwrapArg_HTMLElement(cx, v, nsGkAtoms::_tag, &elem,  \
-                                              ppArgRef, vp);                  \
-    if (NS_SUCCEEDED(rv))                                                     \
-        *ppArg = static_cast<_clazz*>(elem);                                  \
-    return rv;                                                                \
-}                                                                             \
-                                                                              \
-template <>                                                                   \
-inline nsresult                                                               \
-UnwrapArg<_clazz>(JSContext *cx, JS::HandleValue v, _clazz **ppArg,           \
-                  _clazz **ppArgRef, JS::MutableHandleValue vp)               \
-{                                                                             \
-    nsISupports* argRef = static_cast<nsIContent*>(*ppArgRef);                \
-    nsresult rv = UnwrapArg<_clazz>(cx, v, ppArg, &argRef, vp);               \
-    *ppArgRef = static_cast<_clazz*>(static_cast<nsIContent*>(argRef));       \
-    return rv;                                                                \
-}                                                                             \
-                                                                              \
-} /* namespace dom */                                                         \
-} /* namespace mozilla */
-
-DEFINE_UNWRAP_CAST_HTML(canvas, mozilla::dom::HTMLCanvasElement)
-DEFINE_UNWRAP_CAST_HTML(form, mozilla::dom::HTMLFormElement)
-DEFINE_UNWRAP_CAST_HTML(img, mozilla::dom::HTMLImageElement)
-DEFINE_UNWRAP_CAST_HTML(optgroup, mozilla::dom::HTMLOptGroupElement)
-DEFINE_UNWRAP_CAST_HTML(option, mozilla::dom::HTMLOptionElement)
-DEFINE_UNWRAP_CAST_HTML(video, mozilla::dom::HTMLVideoElement)
-
 inline nsISupports*
 ToSupports(nsContentList *p)
 {
     return static_cast<nsINodeList*>(p);
 }
 
 inline nsISupports*
 ToCanonicalSupports(nsContentList *p)