Bug 1029202 - Allow CPOW receivers to be non-CPOWs (r=mrbkap)
authorBill McCloskey <wmccloskey@mozilla.com>
Mon, 30 Jun 2014 17:48:09 -0700
changeset 191544 ba6b27e2b92a4c64262bcbb20c83814534e5e01e
parent 191543 9b8852d38b14c72dbca56b3efaf35b03aabe38b8
child 191545 032a08766a8c0ad779acf95d241d70de4fd1a14c
push id45617
push userwmccloskey@mozilla.com
push dateTue, 01 Jul 2014 00:51:58 +0000
treeherdermozilla-inbound@032a08766a8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1029202
milestone33.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 1029202 - Allow CPOW receivers to be non-CPOWs (r=mrbkap)
js/ipc/JavaScriptBase.h
js/ipc/PJavaScript.ipdl
js/ipc/WrapperAnswer.cpp
js/ipc/WrapperAnswer.h
js/ipc/WrapperOwner.cpp
js/ipc/WrapperOwner.h
--- a/js/ipc/JavaScriptBase.h
+++ b/js/ipc/JavaScriptBase.h
@@ -62,25 +62,25 @@ class JavaScriptBase : public WrapperOwn
     bool AnswerHas(const ObjectId &objId, const nsString &id,
                    ReturnStatus *rs, bool *bp) {
         return Answer::AnswerHas(objId, id, rs, bp);
     }
     bool AnswerHasOwn(const ObjectId &objId, const nsString &id,
                       ReturnStatus *rs, bool *bp) {
         return Answer::AnswerHasOwn(objId, id, rs, bp);
     }
-    bool AnswerGet(const ObjectId &objId, const ObjectId &receiverId,
+    bool AnswerGet(const ObjectId &objId, const ObjectVariant &receiverVar,
                    const nsString &id,
                    ReturnStatus *rs, JSVariant *result) {
-        return Answer::AnswerGet(objId, receiverId, id, rs, result);
+        return Answer::AnswerGet(objId, receiverVar, id, rs, result);
     }
-    bool AnswerSet(const ObjectId &objId, const ObjectId &receiverId,
+    bool AnswerSet(const ObjectId &objId, const ObjectVariant &receiverVar,
                    const nsString &id, const bool &strict,
                    const JSVariant &value, ReturnStatus *rs, JSVariant *result) {
-        return Answer::AnswerSet(objId, receiverId, id, strict, value, rs, result);
+        return Answer::AnswerSet(objId, receiverVar, id, strict, value, rs, result);
     }
 
     bool AnswerIsExtensible(const ObjectId &objId, ReturnStatus *rs,
                             bool *result) {
         return Answer::AnswerIsExtensible(objId, rs, result);
     }
     bool AnswerCall(const ObjectId &objId, const nsTArray<JSParam> &argv,
                     ReturnStatus *rs, JSVariant *result,
@@ -144,25 +144,25 @@ class JavaScriptBase : public WrapperOwn
     bool CallHas(const ObjectId &objId, const nsString &id,
                    ReturnStatus *rs, bool *bp) {
         return Base::CallHas(objId, id, rs, bp);
     }
     bool CallHasOwn(const ObjectId &objId, const nsString &id,
                     ReturnStatus *rs, bool *bp) {
         return Base::CallHasOwn(objId, id, rs, bp);
     }
-    bool CallGet(const ObjectId &objId, const ObjectId &receiverId,
+    bool CallGet(const ObjectId &objId, const ObjectVariant &receiverVar,
                  const nsString &id,
                  ReturnStatus *rs, JSVariant *result) {
-        return Base::CallGet(objId, receiverId, id, rs, result);
+        return Base::CallGet(objId, receiverVar, id, rs, result);
     }
-    bool CallSet(const ObjectId &objId, const ObjectId &receiverId,
+    bool CallSet(const ObjectId &objId, const ObjectVariant &receiverVar,
                  const nsString &id, const bool &strict,
                  const JSVariant &value, ReturnStatus *rs, JSVariant *result) {
-        return Base::CallSet(objId, receiverId, id, strict, value, rs, result);
+        return Base::CallSet(objId, receiverVar, id, strict, value, rs, result);
     }
 
     bool CallIsExtensible(const ObjectId &objId, ReturnStatus *rs,
                           bool *result) {
         return Base::CallIsExtensible(objId, rs, result);
     }
     bool CallCall(const ObjectId &objId, const nsTArray<JSParam> &argv,
                   ReturnStatus *rs, JSVariant *result,
--- a/js/ipc/PJavaScript.ipdl
+++ b/js/ipc/PJavaScript.ipdl
@@ -27,18 +27,18 @@ both:
     rpc PreventExtensions(uint64_t objId) returns (ReturnStatus rs);
     rpc GetPropertyDescriptor(uint64_t objId, nsString id) returns (ReturnStatus rs, PPropertyDescriptor result);
     rpc GetOwnPropertyDescriptor(uint64_t objId, nsString id) returns (ReturnStatus rs, PPropertyDescriptor result);
     rpc DefineProperty(uint64_t objId, nsString id, PPropertyDescriptor descriptor) returns (ReturnStatus rs);
     rpc Delete(uint64_t objId, nsString id) returns (ReturnStatus rs, bool successful);
 
     rpc Has(uint64_t objId, nsString id) returns (ReturnStatus rs, bool has);
     rpc HasOwn(uint64_t objId, nsString id) returns (ReturnStatus rs, bool has);
-    rpc Get(uint64_t objId, uint64_t receiverId, nsString id) returns (ReturnStatus rs, JSVariant result);
-    rpc Set(uint64_t objId, uint64_t receiverId, nsString id, bool strict, JSVariant value) returns (ReturnStatus rs, JSVariant result);
+    rpc Get(uint64_t objId, ObjectVariant receiver, nsString id) returns (ReturnStatus rs, JSVariant result);
+    rpc Set(uint64_t objId, ObjectVariant receiver, nsString id, bool strict, JSVariant value) returns (ReturnStatus rs, JSVariant result);
 
     rpc IsExtensible(uint64_t objId) returns (ReturnStatus rs, bool result);
     rpc Call(uint64_t objId, JSParam[] argv) returns (ReturnStatus rs, JSVariant result, JSParam[] outparams);
     rpc ObjectClassIs(uint64_t objId, uint32_t classValue) returns (bool result);
     rpc ClassName(uint64_t objId) returns (nsString name);
 
     rpc GetPropertyNames(uint64_t objId, uint32_t flags) returns (ReturnStatus rs, nsString[] names);
     rpc InstanceOf(uint64_t objId, JSIID iid) returns (ReturnStatus rs, bool instanceof);
--- a/js/ipc/WrapperAnswer.cpp
+++ b/js/ipc/WrapperAnswer.cpp
@@ -272,36 +272,36 @@ WrapperAnswer::AnswerHasOwn(const Object
     if (!JS_GetPropertyDescriptorById(cx, obj, internedId, &desc))
         return fail(cx, rs);
     *bp = (desc.object() == obj);
 
     return ok(rs);
 }
 
 bool
-WrapperAnswer::AnswerGet(const ObjectId &objId, const ObjectId &receiverId, const nsString &id,
+WrapperAnswer::AnswerGet(const ObjectId &objId, const ObjectVariant &receiverVar, const nsString &id,
 			 ReturnStatus *rs, JSVariant *result)
 {
     AutoSafeJSContext cx;
     JSAutoRequest request(cx);
 
     // The outparam will be written to the buffer, so it must be set even if
     // the parent won't read it.
     *result = UndefinedVariant();
 
     RootedObject obj(cx, findObjectById(cx, objId));
     if (!obj)
         return fail(cx, rs);
 
-    RootedObject receiver(cx, findObjectById(cx, receiverId));
+    JSAutoCompartment comp(cx, obj);
+
+    RootedObject receiver(cx, fromObjectVariant(cx, receiverVar));
     if (!receiver)
         return fail(cx, rs);
 
-    JSAutoCompartment comp(cx, obj);
-
     RootedId internedId(cx);
     if (!convertGeckoStringToId(cx, id, &internedId))
         return fail(cx, rs);
 
     JS::RootedValue val(cx);
     if (!JS_ForwardGetPropertyTo(cx, obj, internedId, receiver, &val))
         return fail(cx, rs);
 
@@ -309,37 +309,37 @@ WrapperAnswer::AnswerGet(const ObjectId 
         return fail(cx, rs);
 
     LOG("get %s.%s = %s", ReceiverObj(objId), id, OutVariant(*result));
 
     return ok(rs);
 }
 
 bool
-WrapperAnswer::AnswerSet(const ObjectId &objId, const ObjectId &receiverId, const nsString &id,
+WrapperAnswer::AnswerSet(const ObjectId &objId, const ObjectVariant &receiverVar, const nsString &id,
 			 const bool &strict, const JSVariant &value, ReturnStatus *rs,
 			 JSVariant *result)
 {
     AutoSafeJSContext cx;
     JSAutoRequest request(cx);
 
     // The outparam will be written to the buffer, so it must be set even if
     // the parent won't read it.
     *result = UndefinedVariant();
 
     RootedObject obj(cx, findObjectById(cx, objId));
     if (!obj)
         return fail(cx, rs);
 
-    RootedObject receiver(cx, findObjectById(cx, receiverId));
+    JSAutoCompartment comp(cx, obj);
+
+    RootedObject receiver(cx, fromObjectVariant(cx, receiverVar));
     if (!receiver)
         return fail(cx, rs);
 
-    JSAutoCompartment comp(cx, obj);
-
     LOG("set %s[%s] = %s", ReceiverObj(objId), id, InVariant(value));
 
     RootedId internedId(cx);
     if (!convertGeckoStringToId(cx, id, &internedId))
         return fail(cx, rs);
 
     MOZ_ASSERT(obj == receiver);
 
--- a/js/ipc/WrapperAnswer.h
+++ b/js/ipc/WrapperAnswer.h
@@ -31,20 +31,20 @@ class WrapperAnswer : public virtual Jav
                               ReturnStatus *rs);
     bool AnswerDelete(const ObjectId &objId, const nsString &id,
                       ReturnStatus *rs, bool *success);
 
     bool AnswerHas(const ObjectId &objId, const nsString &id,
                        ReturnStatus *rs, bool *bp);
     bool AnswerHasOwn(const ObjectId &objId, const nsString &id,
                           ReturnStatus *rs, bool *bp);
-    bool AnswerGet(const ObjectId &objId, const ObjectId &receiverId,
+    bool AnswerGet(const ObjectId &objId, const ObjectVariant &receiverVar,
                        const nsString &id,
                        ReturnStatus *rs, JSVariant *result);
-    bool AnswerSet(const ObjectId &objId, const ObjectId &receiverId,
+    bool AnswerSet(const ObjectId &objId, const ObjectVariant &receiverVar,
                    const nsString &id, const bool &strict,
                    const JSVariant &value, ReturnStatus *rs, JSVariant *result);
 
     bool AnswerIsExtensible(const ObjectId &objId, ReturnStatus *rs,
                             bool *result);
     bool AnswerCall(const ObjectId &objId, const nsTArray<JSParam> &argv,
                     ReturnStatus *rs, JSVariant *result,
                     nsTArray<JSParam> *outparams);
--- a/js/ipc/WrapperOwner.cpp
+++ b/js/ipc/WrapperOwner.cpp
@@ -366,25 +366,28 @@ WrapperOwner::toString(JSContext *cx, Ha
     return true;
 }
 
 bool
 WrapperOwner::get(JSContext *cx, HandleObject proxy, HandleObject receiver,
 		  HandleId id, MutableHandleValue vp)
 {
     ObjectId objId = idOf(proxy);
-    ObjectId receiverId = idOf(receiver);
+
+    ObjectVariant receiverVar;
+    if (!toObjectVariant(cx, receiver, &receiverVar))
+        return false;
 
     nsString idstr;
     if (!convertIdToGeckoString(cx, id, &idstr))
         return false;
 
     JSVariant val;
     ReturnStatus status;
-    if (!CallGet(objId, receiverId, idstr, &status, &val))
+    if (!CallGet(objId, receiverVar, idstr, &status, &val))
         return ipcfail(cx);
 
     LOG_STACK();
 
     if (!ok(cx, status))
         return false;
 
     if (!fromVariant(cx, val, vp))
@@ -413,29 +416,32 @@ CPOWProxyHandler::set(JSContext *cx, JS:
     FORWARD(set, (cx, proxy, receiver, id, strict, vp));
 }
 
 bool
 WrapperOwner::set(JSContext *cx, JS::HandleObject proxy, JS::HandleObject receiver,
 		  JS::HandleId id, bool strict, JS::MutableHandleValue vp)
 {
     ObjectId objId = idOf(proxy);
-    ObjectId receiverId = idOf(receiver);
+
+    ObjectVariant receiverVar;
+    if (!toObjectVariant(cx, receiver, &receiverVar))
+        return false;
 
     nsString idstr;
     if (!convertIdToGeckoString(cx, id, &idstr))
         return false;
 
     JSVariant val;
     if (!toVariant(cx, vp, &val))
         return false;
 
     ReturnStatus status;
     JSVariant result;
-    if (!CallSet(objId, receiverId, idstr, strict, val, &status, &result))
+    if (!CallSet(objId, receiverVar, idstr, strict, val, &status, &result))
         return ipcfail(cx);
 
     LOG_STACK();
 
     if (!ok(cx, status))
         return false;
 
     return fromVariant(cx, result, vp);
--- a/js/ipc/WrapperOwner.h
+++ b/js/ipc/WrapperOwner.h
@@ -111,20 +111,20 @@ class WrapperOwner : public virtual Java
                                     ReturnStatus *rs) = 0;
     virtual bool CallDelete(const ObjectId &objId, const nsString &id,
                             ReturnStatus *rs, bool *success) = 0;
 
     virtual bool CallHas(const ObjectId &objId, const nsString &id,
                          ReturnStatus *rs, bool *bp) = 0;
     virtual bool CallHasOwn(const ObjectId &objId, const nsString &id,
                             ReturnStatus *rs, bool *bp) = 0;
-    virtual bool CallGet(const ObjectId &objId, const ObjectId &receiverId,
+    virtual bool CallGet(const ObjectId &objId, const ObjectVariant &receiverVar,
                          const nsString &id,
                          ReturnStatus *rs, JSVariant *result) = 0;
-    virtual bool CallSet(const ObjectId &objId, const ObjectId &receiverId,
+    virtual bool CallSet(const ObjectId &objId, const ObjectVariant &receiverVar,
                          const nsString &id, const bool &strict,
                          const JSVariant &value, ReturnStatus *rs, JSVariant *result) = 0;
 
     virtual bool CallIsExtensible(const ObjectId &objId, ReturnStatus *rs,
                                   bool *result) = 0;
     virtual bool CallCall(const ObjectId &objId, const nsTArray<JSParam> &argv,
                           ReturnStatus *rs, JSVariant *result,
                           nsTArray<JSParam> *outparams) = 0;