Bug 1311825: Pass by reference in fromObjectVariant and related methods. r?billm
MozReview-Commit-ID: GIhK1zRMsYb
--- 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,