Bug 1311825: Pass by reference in fromObjectVariant and related methods. r?billm draft
authorDavid Major <dmajor@mozilla.com>
Thu, 20 Oct 2016 15:37:26 -0500
changeset 427731 ac181fd282b9307f6a1f4c58bb4f8b57c3d36745
parent 427717 c1559b3712f202267981d82a70fb25299e776e84
child 534545 1d33ce49637a5ee2e1e80c32af63a60f78ee7e63
push id33102
push userdmajor@mozilla.com
push dateThu, 20 Oct 2016 20:38:24 +0000
reviewersbillm
bugs1311825
milestone52.0a1
Bug 1311825: Pass by reference in fromObjectVariant and related methods. r?billm MozReview-Commit-ID: GIhK1zRMsYb
js/ipc/JavaScriptBase.h
js/ipc/JavaScriptShared.cpp
js/ipc/JavaScriptShared.h
js/ipc/WrapperOwner.cpp
js/ipc/WrapperOwner.h
--- a/js/ipc/JavaScriptBase.h
+++ b/js/ipc/JavaScriptBase.h
@@ -214,17 +214,17 @@ class JavaScriptBase : public WrapperOwn
         return Base::SendDOMInstanceOf(objId.serialize(), prototypeID, depth, rs, instanceof);
     }
 
     /* The following code is needed to suppress a bogus MSVC warning (C4250). */
 
     virtual bool toObjectVariant(JSContext* cx, JSObject* obj, ObjectVariant* objVarp) {
         return WrapperOwner::toObjectVariant(cx, obj, objVarp);
     }
-    virtual JSObject* fromObjectVariant(JSContext* cx, ObjectVariant objVar) {
+    virtual JSObject* fromObjectVariant(JSContext* cx, const ObjectVariant& objVar) {
         return WrapperOwner::fromObjectVariant(cx, objVar);
     }
 };
 
 } // namespace jsipc
 } // namespace mozilla
 
 #endif
--- a/js/ipc/JavaScriptShared.cpp
+++ b/js/ipc/JavaScriptShared.cpp
@@ -430,17 +430,17 @@ JavaScriptShared::toSymbolVariant(JSCont
         return true;
     }
 
     JS_ReportErrorASCII(cx, "unique symbol can't be used with CPOW");
     return false;
 }
 
 JS::Symbol*
-JavaScriptShared::fromSymbolVariant(JSContext* cx, SymbolVariant symVar)
+JavaScriptShared::fromSymbolVariant(JSContext* cx, const SymbolVariant& symVar)
 {
     switch (symVar.type()) {
       case SymbolVariant::TWellKnownSymbol: {
         uint32_t which = symVar.get_WellKnownSymbol().which();
         if (which < WellKnownSymbolLimit)
             return GetWellKnownSymbol(cx, static_cast<SymbolCode>(which));
         MOZ_ASSERT(false, "bad child data");
         return nullptr;
@@ -625,17 +625,17 @@ JavaScriptShared::toObjectOrNullVariant(
     if (!toObjectVariant(cx, obj, &objVar))
         return false;
 
     *objVarp = objVar;
     return true;
 }
 
 JSObject*
-JavaScriptShared::fromObjectOrNullVariant(JSContext* cx, ObjectOrNullVariant objVar)
+JavaScriptShared::fromObjectOrNullVariant(JSContext* cx, const ObjectOrNullVariant& objVar)
 {
     if (objVar.type() == ObjectOrNullVariant::TNullVariant)
         return nullptr;
 
     return fromObjectVariant(cx, objVar.get_ObjectVariant());
 }
 
 CrossProcessCpowHolder::CrossProcessCpowHolder(dom::CPOWManagerGetter* managerGetter,
--- a/js/ipc/JavaScriptShared.h
+++ b/js/ipc/JavaScriptShared.h
@@ -148,31 +148,31 @@ class JavaScriptShared : public CPOWMana
   protected:
     bool toVariant(JSContext* cx, JS::HandleValue from, JSVariant* to);
     bool fromVariant(JSContext* cx, const JSVariant& from, JS::MutableHandleValue to);
 
     bool toJSIDVariant(JSContext* cx, JS::HandleId from, JSIDVariant* to);
     bool fromJSIDVariant(JSContext* cx, const JSIDVariant& from, JS::MutableHandleId to);
 
     bool toSymbolVariant(JSContext* cx, JS::Symbol* sym, SymbolVariant* symVarp);
-    JS::Symbol* fromSymbolVariant(JSContext* cx, SymbolVariant symVar);
+    JS::Symbol* fromSymbolVariant(JSContext* cx, const SymbolVariant& symVar);
 
     bool fromDescriptor(JSContext* cx, JS::Handle<JS::PropertyDescriptor> desc,
                         PPropertyDescriptor* out);
     bool toDescriptor(JSContext* cx, const PPropertyDescriptor& in,
                       JS::MutableHandle<JS::PropertyDescriptor> out);
 
     bool toObjectOrNullVariant(JSContext* cx, JSObject* obj, ObjectOrNullVariant* objVarp);
-    JSObject* fromObjectOrNullVariant(JSContext* cx, ObjectOrNullVariant objVar);
+    JSObject* fromObjectOrNullVariant(JSContext* cx, const ObjectOrNullVariant& objVar);
 
     bool convertIdToGeckoString(JSContext* cx, JS::HandleId id, nsString* to);
     bool convertGeckoStringToId(JSContext* cx, const nsString& from, JS::MutableHandleId id);
 
     virtual bool toObjectVariant(JSContext* cx, JSObject* obj, ObjectVariant* objVarp) = 0;
-    virtual JSObject* fromObjectVariant(JSContext* cx, ObjectVariant objVar) = 0;
+    virtual JSObject* fromObjectVariant(JSContext* cx, const ObjectVariant& objVar) = 0;
 
     static void ConvertID(const nsID& from, JSIID* to);
     static void ConvertID(const JSIID& from, nsID* to);
 
     JSObject* findCPOWById(const ObjectId& objId) {
         return cpows_.find(objId);
     }
     JSObject* findObjectById(JSContext* cx, const ObjectId& objId);
--- a/js/ipc/WrapperOwner.cpp
+++ b/js/ipc/WrapperOwner.cpp
@@ -1163,27 +1163,27 @@ WrapperOwner::toObjectVariant(JSContext*
     if (!objectIdMap(waiveXray).add(cx, obj, id))
         return false;
 
     *objVarp = MakeRemoteObject(cx, id, obj);
     return true;
 }
 
 JSObject*
-WrapperOwner::fromObjectVariant(JSContext* cx, ObjectVariant objVar)
+WrapperOwner::fromObjectVariant(JSContext* cx, const ObjectVariant& objVar)
 {
     if (objVar.type() == ObjectVariant::TRemoteObject) {
         return fromRemoteObjectVariant(cx, objVar.get_RemoteObject());
     } else {
         return fromLocalObjectVariant(cx, objVar.get_LocalObject());
     }
 }
 
 JSObject*
-WrapperOwner::fromRemoteObjectVariant(JSContext* cx, RemoteObject objVar)
+WrapperOwner::fromRemoteObjectVariant(JSContext* cx, const RemoteObject& objVar)
 {
     ObjectId objId = ObjectId::deserialize(objVar.serializedId());
     RootedObject obj(cx, findCPOWById(objId));
     if (!obj) {
 
         // All CPOWs live in the privileged junk scope.
         RootedObject junkScope(cx, xpc::PrivilegedJunkScope());
         JSAutoCompartment ac(cx, junkScope);
@@ -1219,17 +1219,17 @@ WrapperOwner::fromRemoteObjectVariant(JS
     }
 
     if (!JS_WrapObject(cx, &obj))
         return nullptr;
     return obj;
 }
 
 JSObject*
-WrapperOwner::fromLocalObjectVariant(JSContext* cx, LocalObject objVar)
+WrapperOwner::fromLocalObjectVariant(JSContext* cx, const LocalObject& objVar)
 {
     ObjectId id = ObjectId::deserialize(objVar.serializedId());
     Rooted<JSObject*> obj(cx, findObjectById(cx, id));
     if (!obj)
         return nullptr;
     if (!JS_WrapObject(cx, &obj))
         return nullptr;
     return obj;
--- a/js/ipc/WrapperOwner.h
+++ b/js/ipc/WrapperOwner.h
@@ -79,19 +79,19 @@ class WrapperOwner : public virtual Java
     virtual bool allowMessage(JSContext* cx) = 0;
 
     void drop(JSObject* obj);
     void updatePointer(JSObject* obj, const JSObject* old);
 
     virtual void ActorDestroy(ActorDestroyReason why);
 
     virtual bool toObjectVariant(JSContext* cx, JSObject* obj, ObjectVariant* objVarp);
-    virtual JSObject* fromObjectVariant(JSContext* cx, ObjectVariant objVar);
-    JSObject* fromRemoteObjectVariant(JSContext* cx, RemoteObject objVar);
-    JSObject* fromLocalObjectVariant(JSContext* cx, LocalObject objVar);
+    virtual JSObject* fromObjectVariant(JSContext* cx, const ObjectVariant& objVar);
+    JSObject* fromRemoteObjectVariant(JSContext* cx, const RemoteObject& objVar);
+    JSObject* fromLocalObjectVariant(JSContext* cx, const LocalObject& objVar);
 
   protected:
     ObjectId idOf(JSObject* obj);
 
   private:
     ObjectId idOfUnchecked(JSObject* obj);
 
     bool getPropertyKeys(JSContext* cx, JS::HandleObject proxy, uint32_t flags,