Fix for bug 814821 (Dromaeo dom-traverse regression from bug 812333) - part 1: use qsObjectHelper instead of xpcObjectHelper in HandleNewBindingWrappingFailure. r=bz.
authorPeter Van der Beken <peterv@propagandism.org>
Tue, 27 Nov 2012 10:20:04 +0100
changeset 114341 3db4085a10b2fcb585cbc19f15012e69bf218e2d
parent 114340 7be28e2ce121d880e1bd8c5c7912191a46cf2cf7
child 114342 2997ef8891c41006b1ce5dc19762fd109c4ecda3
push id18708
push userpvanderbeken@mozilla.com
push dateWed, 28 Nov 2012 09:02:49 +0000
treeherdermozilla-inbound@7d678d658159 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs814821, 812333
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
Fix for bug 814821 (Dromaeo dom-traverse regression from bug 812333) - part 1: use qsObjectHelper instead of xpcObjectHelper in HandleNewBindingWrappingFailure. r=bz.
dom/bindings/BindingUtils.cpp
dom/bindings/BindingUtils.h
dom/bindings/Bindings.conf
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -448,57 +448,39 @@ CreateInterfaceObjects(JSContext* cx, JS
         *protoCache = nullptr;
       }
       return;
     }
     *constructorCache = interface;
   }
 }
 
-static bool
-NativeInterface2JSObjectAndThrowIfFailed(XPCLazyCallContext& aLccx,
-                                         JSContext* aCx,
+bool
+NativeInterface2JSObjectAndThrowIfFailed(JSContext* aCx,
+                                         JSObject* aScope,
                                          JS::Value* aRetval,
                                          xpcObjectHelper& aHelper,
                                          const nsIID* aIID,
                                          bool aAllowNativeWrapper)
 {
   nsresult rv;
-  if (!XPCConvert::NativeInterface2JSObject(aLccx, aRetval, NULL, aHelper, aIID,
+  XPCLazyCallContext lccx(JS_CALLER, aCx, aScope);
+  if (!XPCConvert::NativeInterface2JSObject(lccx, aRetval, NULL, aHelper, aIID,
                                             NULL, aAllowNativeWrapper, &rv)) {
     // I can't tell if NativeInterface2JSObject throws JS exceptions
     // or not.  This is a sloppy stab at the right semantics; the
     // method really ought to be fixed to behave consistently.
     if (!JS_IsExceptionPending(aCx)) {
       Throw<true>(aCx, NS_FAILED(rv) ? rv : NS_ERROR_UNEXPECTED);
     }
     return false;
   }
   return true;
 }
 
-bool
-DoHandleNewBindingWrappingFailure(JSContext* cx, JSObject* scope,
-                                  nsISupports* value, JS::Value* vp)
-{
-  if (JS_IsExceptionPending(cx)) {
-    return false;
-  }
-
-  XPCLazyCallContext lccx(JS_CALLER, cx, scope);
-
-  if (value) {
-    xpcObjectHelper helper(value);
-    return NativeInterface2JSObjectAndThrowIfFailed(lccx, cx, vp, helper, NULL,
-                                                    true);
-  }
-
-  return Throw<true>(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
-}
-
 // Can only be called with the immediate prototype of the instance object. Can
 // only be called on the prototype of an object known to be a DOM instance.
 JSBool
 InstanceClassHasProtoAtDepth(JSHandleObject protoObject, uint32_t protoID,
                              uint32_t depth)
 {
   const DOMClass* domClass = static_cast<DOMClass*>(
     js::GetReservedSlot(protoObject, DOM_PROTO_INSTANCE_CLASS_SLOT).toPrivate());
@@ -506,19 +488,17 @@ InstanceClassHasProtoAtDepth(JSHandleObj
 }
 
 // Only set allowNativeWrapper to false if you really know you need it, if in
 // doubt use true. Setting it to false disables security wrappers.
 bool
 XPCOMObjectToJsval(JSContext* cx, JSObject* scope, xpcObjectHelper &helper,
                    const nsIID* iid, bool allowNativeWrapper, JS::Value* rval)
 {
-  XPCLazyCallContext lccx(JS_CALLER, cx, scope);
-
-  if (!NativeInterface2JSObjectAndThrowIfFailed(lccx, cx, rval, helper, iid,
+  if (!NativeInterface2JSObjectAndThrowIfFailed(cx, scope, rval, helper, iid,
                                                 allowNativeWrapper)) {
     return false;
   }
 
 #ifdef DEBUG
   JSObject* jsobj = JSVAL_TO_OBJECT(*rval);
   if (jsobj && !js::GetObjectParent(jsobj))
     NS_ASSERTION(js::GetObjectClass(jsobj)->flags & JSCLASS_IS_GLOBAL,
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -589,36 +589,57 @@ WrapNewBindingNonWrapperCachedObject(JSC
 template <template <typename> class SmartPtr, typename T>
 inline bool
 WrapNewBindingNonWrapperCachedObject(JSContext* cx, JSObject* scope,
                                      const SmartPtr<T>& value, JS::Value* vp)
 {
   return WrapNewBindingNonWrapperCachedObject(cx, scope, value.get(), vp);
 }
 
+// Only set allowNativeWrapper to false if you really know you need it, if in
+// doubt use true. Setting it to false disables security wrappers.
+bool
+NativeInterface2JSObjectAndThrowIfFailed(JSContext* aCx,
+                                         JSObject* aScope,
+                                         JS::Value* aRetval,
+                                         xpcObjectHelper& aHelper,
+                                         const nsIID* aIID,
+                                         bool aAllowNativeWrapper);
+
+inline nsWrapperCache*
+GetWrapperCache(nsWrapperCache* cache)
+{
+  return cache;
+}
+
+inline nsWrapperCache*
+GetWrapperCache(nsGlobalWindow* not_allowed);
+
+inline nsWrapperCache*
+GetWrapperCache(void* p)
+{
+  return NULL;
+}
+
 /**
  * A method to handle new-binding wrap failure, by possibly falling back to
  * wrapping as a non-new-binding object.
  */
-bool
-DoHandleNewBindingWrappingFailure(JSContext* cx, JSObject* scope,
-                                  nsISupports* value, JS::Value* vp);
-
-/**
- * An easy way to call the above when you have a value which
- * multiply-inherits from nsISupports.
- */
 template <class T>
-bool
+MOZ_ALWAYS_INLINE bool
 HandleNewBindingWrappingFailure(JSContext* cx, JSObject* scope, T* value,
                                 JS::Value* vp)
 {
-  nsCOMPtr<nsISupports> val;
-  CallQueryInterface(value, getter_AddRefs(val));
-  return DoHandleNewBindingWrappingFailure(cx, scope, val, vp);
+  if (JS_IsExceptionPending(cx)) {
+    return false;
+  }
+
+  qsObjectHelper helper(value, GetWrapperCache(value));
+  return NativeInterface2JSObjectAndThrowIfFailed(cx, scope, vp, helper,
+                                                  nullptr, true);
 }
 
 // Helper for smart pointers (nsAutoPtr/nsRefPtr/nsCOMPtr).
 template <template <typename> class SmartPtr, class T>
 MOZ_ALWAYS_INLINE bool
 HandleNewBindingWrappingFailure(JSContext* cx, JSObject* scope,
                                 const SmartPtr<T>& value, JS::Value* vp)
 {
@@ -696,31 +717,16 @@ FindEnumStringIndex(JSContext* cx, JS::V
       return i;
     }
   }
 
   *ok = EnumValueNotFound<InvalidValueFatal>(cx, chars, length, type);
   return -1;
 }
 
-inline nsWrapperCache*
-GetWrapperCache(nsWrapperCache* cache)
-{
-  return cache;
-}
-
-inline nsWrapperCache*
-GetWrapperCache(nsGlobalWindow* not_allowed);
-
-inline nsWrapperCache*
-GetWrapperCache(void* p)
-{
-  return NULL;
-}
-
 struct ParentObject {
   template<class T>
   ParentObject(T* aObject) :
     mObject(aObject),
     mWrapperCache(GetWrapperCache(aObject))
   {}
 
   template<class T, template<typename> class SmartPtr>
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -506,29 +506,27 @@ DOMInterfaces = {
 {
     'workers': True,
 }],
 
 'XMLHttpRequestEventTarget': [
 {
     'nativeType': 'nsXHREventTarget',
     'headerFile': 'nsXMLHttpRequest.h',
-    'concrete': False,
-    'prefable': True,
+    'concrete': False
 },
 {
     'workers': True,
     'concrete': False,
 }],
 
 'XMLHttpRequestUpload': [
 {
     'nativeType': 'nsXMLHttpRequestUpload',
-    'headerFile': 'nsXMLHttpRequest.h',
-    'prefable': True
+    'headerFile': 'nsXMLHttpRequest.h'
 },
 {
     'workers': True,
 }],
 
 ####################################
 # Test Interfaces of various sorts #
 ####################################