Bug 821850 - Remove unused arguments from InstallMember and simplify calling convention. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Fri, 08 Feb 2013 14:24:21 +0000
changeset 131189 583ed5f34e84e39530b6297e50765bb54a576204
parent 131188 a1ddf64db133ef81006afb800287f4294d16dbc8
child 131190 05df50b4e43e260aa9c3eaf22df1b168631407c8
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs821850
milestone21.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 821850 - Remove unused arguments from InstallMember and simplify calling convention. r=bz Let's just pass a JSContext and do Requests/Compartments in the caller.
content/xbl/src/nsXBLProtoImpl.cpp
content/xbl/src/nsXBLProtoImplMember.h
content/xbl/src/nsXBLProtoImplMethod.cpp
content/xbl/src/nsXBLProtoImplMethod.h
content/xbl/src/nsXBLProtoImplProperty.cpp
content/xbl/src/nsXBLProtoImplProperty.h
--- a/content/xbl/src/nsXBLProtoImpl.cpp
+++ b/content/xbl/src/nsXBLProtoImpl.cpp
@@ -82,25 +82,25 @@ nsXBLProtoImpl::InstallImplementation(ns
   // If the prototype already existed, we don't need to install anything. return early.
   if (!targetObjectIsNew)
     return NS_OK;
 
   JSObject * targetScriptObject;
   holder->GetJSObject(&targetScriptObject);
 
   JSContext *cx = context->GetNativeContext();
-
+  JSAutoRequest ar(cx);
+  JSAutoCompartment ac(cx, targetClassObject);
   AutoVersionChecker avc(cx);
-  
+
   // Walk our member list and install each one in turn.
   for (nsXBLProtoImplMember* curr = mMembers;
        curr;
        curr = curr->GetNext())
-    curr->InstallMember(context, aBinding->GetBoundElement(), targetScriptObject,
-                        targetClassObject, mClassName);
+    curr->InstallMember(cx, targetClassObject);
 
   return NS_OK;
 }
 
 nsresult 
 nsXBLProtoImpl::InitTargetObjects(nsXBLPrototypeBinding* aBinding,
                                   nsIScriptContext* aContext, 
                                   nsIContent* aBoundElement, 
--- a/content/xbl/src/nsXBLProtoImplMember.h
+++ b/content/xbl/src/nsXBLProtoImplMember.h
@@ -66,21 +66,18 @@ public:
   virtual ~nsXBLProtoImplMember() {
     nsMemory::Free(mName);
     NS_CONTENT_DELETE_LIST_MEMBER(nsXBLProtoImplMember, this, mNext);
   }
 
   nsXBLProtoImplMember* GetNext() { return mNext; }
   void SetNext(nsXBLProtoImplMember* aNext) { mNext = aNext; }
 
-  virtual nsresult InstallMember(nsIScriptContext* aContext,
-                                 nsIContent* aBoundElement, 
-                                 JSObject* aScriptObject, // Unused
-                                 JSObject* aTargetClassObject,
-                                 const nsCString& aClassStr) = 0;
+  virtual nsresult InstallMember(JSContext* aCx,
+                                 JSObject* aTargetClassObject) = 0;
   virtual nsresult CompileMember(nsIScriptContext* aContext,
                                  const nsCString& aClassStr,
                                  JSObject* aClassObject) = 0;
 
   virtual void Trace(TraceCallback aCallback, void *aClosure) const = 0;
 
   virtual nsresult Write(nsIScriptContext* aContext,
                          nsIObjectOutputStream* aStream)
--- a/content/xbl/src/nsXBLProtoImplMethod.cpp
+++ b/content/xbl/src/nsXBLProtoImplMethod.cpp
@@ -87,50 +87,35 @@ nsXBLProtoImplMethod::SetLineNumber(uint
       return;
     SetUncompiledMethod(uncompiledMethod);
   }
 
   uncompiledMethod->SetLineNumber(aLineNumber);
 }
 
 nsresult
-nsXBLProtoImplMethod::InstallMember(nsIScriptContext* aContext,
-                                    nsIContent* aBoundElement, 
-                                    JSObject* aScriptObject,
-                                    JSObject* aTargetClassObject,
-                                    const nsCString& aClassStr)
+nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
+                                    JSObject* aTargetClassObject)
 {
   NS_PRECONDITION(IsCompiled(),
                   "Should not be installing an uncompiled method");
-  JSContext* cx = aContext->GetNativeContext();
-
-  nsIScriptGlobalObject* sgo = aBoundElement->OwnerDoc()->GetScopeObject();
+  MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
 
-  if (!sgo) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  NS_ASSERTION(aScriptObject, "uh-oh, script Object should NOT be null or bad things will happen");
-  if (!aScriptObject)
-    return NS_ERROR_FAILURE;
-
-  JSObject* globalObject = sgo->GetGlobalJSObject();
+  JSObject* globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
 
   // now we want to reevaluate our property using aContext and the script object for this window...
   if (mJSMethodObject) {
     nsDependentString name(mName);
-    JSAutoRequest ar(cx);
-    JSAutoCompartment ac(cx, globalObject);
 
-    JSObject * method = ::JS_CloneFunctionObject(cx, mJSMethodObject, globalObject);
+    JSObject * method = ::JS_CloneFunctionObject(aCx, mJSMethodObject, globalObject);
     if (!method) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
-    if (!::JS_DefineUCProperty(cx, aTargetClassObject,
+    if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
                                static_cast<const jschar*>(mName),
                                name.Length(), OBJECT_TO_JSVAL(method),
                                NULL, NULL, JSPROP_ENUMERATE)) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
   return NS_OK;
 }
--- a/content/xbl/src/nsXBLProtoImplMethod.h
+++ b/content/xbl/src/nsXBLProtoImplMethod.h
@@ -82,21 +82,18 @@ public:
   nsXBLProtoImplMethod(const PRUnichar* aName);
   virtual ~nsXBLProtoImplMethod();
 
   void AppendBodyText(const nsAString& aBody);
   void AddParameter(const nsAString& aName);
 
   void SetLineNumber(uint32_t aLineNumber);
   
-  virtual nsresult InstallMember(nsIScriptContext* aContext,
-                                 nsIContent* aBoundElement, 
-                                 JSObject* aScriptObject,
-                                 JSObject* aTargetClassObject,
-                                 const nsCString& aClassStr);
+  virtual nsresult InstallMember(JSContext* aCx,
+                                 JSObject* aTargetClassObject);
   virtual nsresult CompileMember(nsIScriptContext* aContext,
                                  const nsCString& aClassStr,
                                  JSObject* aClassObject);
 
   virtual void Trace(TraceCallback aCallback, void *aClosure) const;
 
   nsresult Read(nsIScriptContext* aContext, nsIObjectInputStream* aStream);
   virtual nsresult Write(nsIScriptContext* aContext, nsIObjectOutputStream* aStream);
@@ -134,21 +131,18 @@ public:
     nsXBLProtoImplMethod(EmptyString().get())
   {}
   
   nsresult Execute(nsIContent* aBoundElement);
 
   // Override InstallMember; these methods never get installed as members on
   // binding instantiations (though they may hang out in mMembers on the
   // prototype implementation).
-  virtual nsresult InstallMember(nsIScriptContext* aContext,
-                                 nsIContent* aBoundElement, 
-                                 JSObject* aScriptObject,
-                                 JSObject* aTargetClassObject,
-                                 const nsCString& aClassStr) {
+  virtual nsresult InstallMember(JSContext* aCx,
+                                 JSObject* aTargetClassObject) {
     return NS_OK;
   }
 
   using nsXBLProtoImplMethod::Write;
   nsresult Write(nsIScriptContext* aContext,
                  nsIObjectOutputStream* aStream,
                  XBLBindingSerializeDetails aType);
 };
--- a/content/xbl/src/nsXBLProtoImplProperty.cpp
+++ b/content/xbl/src/nsXBLProtoImplProperty.cpp
@@ -130,55 +130,39 @@ nsXBLProtoImplProperty::SetSetterLineNum
   }
 
   mSetterText->SetLineNumber(aLineNumber);
 }
 
 const char* gPropertyArgs[] = { "val" };
 
 nsresult
-nsXBLProtoImplProperty::InstallMember(nsIScriptContext* aContext,
-                                      nsIContent* aBoundElement, 
-                                      JSObject* aScriptObject,
-                                      JSObject* aTargetClassObject,
-                                      const nsCString& aClassStr)
+nsXBLProtoImplProperty::InstallMember(JSContext *aCx,
+                                      JSObject* aTargetClassObject)
 {
   NS_PRECONDITION(mIsCompiled,
                   "Should not be installing an uncompiled property");
-  JSContext* cx = aContext->GetNativeContext();
-
-  nsIScriptGlobalObject* sgo = aBoundElement->OwnerDoc()->GetScopeObject();
-
-  if (!sgo) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  NS_ASSERTION(aScriptObject, "uh-oh, script Object should NOT be null or bad things will happen");
-  if (!aScriptObject)
-    return NS_ERROR_FAILURE;
-
-  JSObject * globalObject = sgo->GetGlobalJSObject();
+  MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
+  JSObject * globalObject = JS_GetGlobalForObject(aCx, aTargetClassObject);
 
   // now we want to reevaluate our property using aContext and the script object for this window...
   if (mJSGetterObject || mJSSetterObject) {
     JSObject * getter = nullptr;
-    JSAutoRequest ar(cx);
-    JSAutoCompartment ac(cx, globalObject);
 
     if (mJSGetterObject)
-      if (!(getter = ::JS_CloneFunctionObject(cx, mJSGetterObject, globalObject)))
+      if (!(getter = ::JS_CloneFunctionObject(aCx, mJSGetterObject, globalObject)))
         return NS_ERROR_OUT_OF_MEMORY;
 
     JSObject * setter = nullptr;
     if (mJSSetterObject)
-      if (!(setter = ::JS_CloneFunctionObject(cx, mJSSetterObject, globalObject)))
+      if (!(setter = ::JS_CloneFunctionObject(aCx, mJSSetterObject, globalObject)))
         return NS_ERROR_OUT_OF_MEMORY;
 
     nsDependentString name(mName);
-    if (!::JS_DefineUCProperty(cx, aTargetClassObject,
+    if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
                                static_cast<const jschar*>(mName),
                                name.Length(), JSVAL_VOID,
                                JS_DATA_TO_FUNC_PTR(JSPropertyOp, getter),
                                JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, setter),
                                mJSAttributes))
       return NS_ERROR_OUT_OF_MEMORY;
   }
   return NS_OK;
--- a/content/xbl/src/nsXBLProtoImplProperty.h
+++ b/content/xbl/src/nsXBLProtoImplProperty.h
@@ -28,21 +28,18 @@ public:
   virtual ~nsXBLProtoImplProperty();
 
   void AppendGetterText(const nsAString& aGetter);
   void AppendSetterText(const nsAString& aSetter);
 
   void SetGetterLineNumber(uint32_t aLineNumber);
   void SetSetterLineNumber(uint32_t aLineNumber);
 
-  virtual nsresult InstallMember(nsIScriptContext* aContext,
-                                 nsIContent* aBoundElement, 
-                                 JSObject* aScriptObject,
-                                 JSObject* aTargetClassObject,
-                                 const nsCString& aClassStr);
+  virtual nsresult InstallMember(JSContext* aCx,
+                                 JSObject* aTargetClassObject);
   virtual nsresult CompileMember(nsIScriptContext* aContext,
                                  const nsCString& aClassStr,
                                  JSObject* aClassObject);
 
   virtual void Trace(TraceCallback aCallback, void *aClosure) const;
 
   nsresult Read(nsIScriptContext* aContext,
                 nsIObjectInputStream* aStream,