From eec11c26a07144bee3e56ea85986fee61c7a46dc Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Tue, 7 Oct 2014 11:29:02 +0200 Subject: [PATCH] Bug 1071177 - Introduce JSIDVariant type for CPOWs. r=billm --- js/ipc/JavaScriptBase.h | 32 +++++------ js/ipc/JavaScriptLogging.h | 25 +++++++++ js/ipc/JavaScriptShared.cpp | 35 ++++++++++++ js/ipc/JavaScriptShared.h | 3 + js/ipc/JavaScriptTypes.ipdlh | 6 ++ js/ipc/PJavaScript.ipdl | 16 +++--- js/ipc/WrapperAnswer.cpp | 106 +++++++++++++++++------------------ js/ipc/WrapperAnswer.h | 16 +++--- js/ipc/WrapperOwner.cpp | 55 +++++++++--------- js/ipc/WrapperOwner.h | 16 +++--- 10 files changed, 190 insertions(+), 120 deletions(-) diff --git a/js/ipc/JavaScriptBase.h b/js/ipc/JavaScriptBase.h index 6754d5bb088e..cc91cd91ddc8 100644 --- a/js/ipc/JavaScriptBase.h +++ b/js/ipc/JavaScriptBase.h @@ -38,42 +38,42 @@ class JavaScriptBase : public WrapperOwner, public WrapperAnswer, public Base bool AnswerPreventExtensions(const uint64_t &objId, ReturnStatus *rs) { return Answer::AnswerPreventExtensions(ObjectId::deserialize(objId), rs); } - bool AnswerGetPropertyDescriptor(const uint64_t &objId, const nsString &id, + bool AnswerGetPropertyDescriptor(const uint64_t &objId, const JSIDVariant &id, ReturnStatus *rs, PPropertyDescriptor *out) { return Answer::AnswerGetPropertyDescriptor(ObjectId::deserialize(objId), id, rs, out); } bool AnswerGetOwnPropertyDescriptor(const uint64_t &objId, - const nsString &id, + const JSIDVariant &id, ReturnStatus *rs, PPropertyDescriptor *out) { return Answer::AnswerGetOwnPropertyDescriptor(ObjectId::deserialize(objId), id, rs, out); } - bool AnswerDefineProperty(const uint64_t &objId, const nsString &id, + bool AnswerDefineProperty(const uint64_t &objId, const JSIDVariant &id, const PPropertyDescriptor &flags, ReturnStatus *rs) { return Answer::AnswerDefineProperty(ObjectId::deserialize(objId), id, flags, rs); } - bool AnswerDelete(const uint64_t &objId, const nsString &id, + bool AnswerDelete(const uint64_t &objId, const JSIDVariant &id, ReturnStatus *rs, bool *success) { return Answer::AnswerDelete(ObjectId::deserialize(objId), id, rs, success); } - bool AnswerHas(const uint64_t &objId, const nsString &id, + bool AnswerHas(const uint64_t &objId, const JSIDVariant &id, ReturnStatus *rs, bool *bp) { return Answer::AnswerHas(ObjectId::deserialize(objId), id, rs, bp); } - bool AnswerHasOwn(const uint64_t &objId, const nsString &id, + bool AnswerHasOwn(const uint64_t &objId, const JSIDVariant &id, ReturnStatus *rs, bool *bp) { return Answer::AnswerHasOwn(ObjectId::deserialize(objId), id, rs, bp); } bool AnswerGet(const uint64_t &objId, const ObjectVariant &receiverVar, - const nsString &id, + const JSIDVariant &id, ReturnStatus *rs, JSVariant *result) { return Answer::AnswerGet(ObjectId::deserialize(objId), receiverVar, id, rs, result); } bool AnswerSet(const uint64_t &objId, const ObjectVariant &receiverVar, - const nsString &id, const bool &strict, + const JSIDVariant &id, const bool &strict, const JSVariant &value, ReturnStatus *rs, JSVariant *result) { return Answer::AnswerSet(ObjectId::deserialize(objId), receiverVar, id, strict, value, rs, result); } @@ -134,42 +134,42 @@ class JavaScriptBase : public WrapperOwner, public WrapperAnswer, public Base bool CallPreventExtensions(const ObjectId &objId, ReturnStatus *rs) { return Base::CallPreventExtensions(objId.serialize(), rs); } - bool CallGetPropertyDescriptor(const ObjectId &objId, const nsString &id, + bool CallGetPropertyDescriptor(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, PPropertyDescriptor *out) { return Base::CallGetPropertyDescriptor(objId.serialize(), id, rs, out); } bool CallGetOwnPropertyDescriptor(const ObjectId &objId, - const nsString &id, + const JSIDVariant &id, ReturnStatus *rs, PPropertyDescriptor *out) { return Base::CallGetOwnPropertyDescriptor(objId.serialize(), id, rs, out); } - bool CallDefineProperty(const ObjectId &objId, const nsString &id, + bool CallDefineProperty(const ObjectId &objId, const JSIDVariant &id, const PPropertyDescriptor &flags, ReturnStatus *rs) { return Base::CallDefineProperty(objId.serialize(), id, flags, rs); } - bool CallDelete(const ObjectId &objId, const nsString &id, + bool CallDelete(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, bool *success) { return Base::CallDelete(objId.serialize(), id, rs, success); } - bool CallHas(const ObjectId &objId, const nsString &id, + bool CallHas(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, bool *bp) { return Base::CallHas(objId.serialize(), id, rs, bp); } - bool CallHasOwn(const ObjectId &objId, const nsString &id, + bool CallHasOwn(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, bool *bp) { return Base::CallHasOwn(objId.serialize(), id, rs, bp); } bool CallGet(const ObjectId &objId, const ObjectVariant &receiverVar, - const nsString &id, + const JSIDVariant &id, ReturnStatus *rs, JSVariant *result) { return Base::CallGet(objId.serialize(), receiverVar, id, rs, result); } bool CallSet(const ObjectId &objId, const ObjectVariant &receiverVar, - const nsString &id, const bool &strict, + const JSIDVariant &id, const bool &strict, const JSVariant &value, ReturnStatus *rs, JSVariant *result) { return Base::CallSet(objId.serialize(), receiverVar, id, strict, value, rs, result); } diff --git a/js/ipc/JavaScriptLogging.h b/js/ipc/JavaScriptLogging.h index eeb47a1a9d33..fe34812d3db8 100644 --- a/js/ipc/JavaScriptLogging.h +++ b/js/ipc/JavaScriptLogging.h @@ -49,6 +49,12 @@ struct OutVariant explicit OutVariant(const JSVariant &variant) : variant(variant) {} }; +struct Identifier +{ + JSIDVariant variant; + explicit Identifier(const JSIDVariant &variant) : variant(variant) {} +}; + class Logging { public: @@ -184,6 +190,25 @@ class Logging } } + void format(const Identifier &id, nsCString &out) { + switch (id.variant.type()) { + case JSIDVariant::TnsString: { + nsAutoCString tmp; + format(id.variant.get_nsString(), tmp); + out = nsPrintfCString("\"%s\"", tmp.get()); + break; + } + case JSIDVariant::Tint32_t: { + out = nsPrintfCString("%d", id.variant.get_int32_t()); + break; + } + default: { + out = "Unknown"; + break; + } + } + } + private: JavaScriptShared *shared; JSContext *cx; diff --git a/js/ipc/JavaScriptShared.cpp b/js/ipc/JavaScriptShared.cpp index 882be465929d..41bf4e436362 100644 --- a/js/ipc/JavaScriptShared.cpp +++ b/js/ipc/JavaScriptShared.cpp @@ -348,10 +348,45 @@ JavaScriptShared::fromVariant(JSContext *cx, const JSVariant &from, MutableHandl } default: + MOZ_CRASH("NYI"); return false; } } +bool +JavaScriptShared::toJSIDVariant(JSContext *cx, HandleId from, JSIDVariant *to) +{ + if (JSID_IS_STRING(from)) { + nsAutoJSString autoStr; + if (!autoStr.init(cx, JSID_TO_STRING(from))) + return false; + *to = autoStr; + return true; + } + if (JSID_IS_INT(from)) { + *to = JSID_TO_INT(from); + return true; + } + MOZ_CRASH("NYI"); + return false; +} + +bool +JavaScriptShared::fromJSIDVariant(JSContext *cx, const JSIDVariant &from, MutableHandleId to) +{ + switch (from.type()) { + case JSIDVariant::TnsString: + return convertGeckoStringToId(cx, from.get_nsString(), to); + + case JSIDVariant::Tint32_t: + to.set(INT_TO_JSID(from.get_int32_t())); + return true; + + default: + return false; + } +} + /* static */ void JavaScriptShared::ConvertID(const nsID &from, JSIID *to) { diff --git a/js/ipc/JavaScriptShared.h b/js/ipc/JavaScriptShared.h index 3c0cd766105f..ca8674478d34 100644 --- a/js/ipc/JavaScriptShared.h +++ b/js/ipc/JavaScriptShared.h @@ -158,6 +158,9 @@ class JavaScriptShared 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 fromDescriptor(JSContext *cx, JS::Handle desc, PPropertyDescriptor *out); bool toDescriptor(JSContext *cx, const PPropertyDescriptor &in, diff --git a/js/ipc/JavaScriptTypes.ipdlh b/js/ipc/JavaScriptTypes.ipdlh index 07b359f29c14..cea0280a25eb 100644 --- a/js/ipc/JavaScriptTypes.ipdlh +++ b/js/ipc/JavaScriptTypes.ipdlh @@ -57,6 +57,12 @@ union JSVariant JSIID; /* XPC nsIID */ }; +union JSIDVariant +{ + nsString; + int32_t; +}; + struct ReturnSuccess { }; diff --git a/js/ipc/PJavaScript.ipdl b/js/ipc/PJavaScript.ipdl index 6efb0a8b06a4..f4c29e074577 100644 --- a/js/ipc/PJavaScript.ipdl +++ b/js/ipc/PJavaScript.ipdl @@ -25,15 +25,15 @@ both: // These roughly map to the ProxyHandler hooks that CPOWs need. 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 GetPropertyDescriptor(uint64_t objId, JSIDVariant id) returns (ReturnStatus rs, PPropertyDescriptor result); + rpc GetOwnPropertyDescriptor(uint64_t objId, JSIDVariant id) returns (ReturnStatus rs, PPropertyDescriptor result); + rpc DefineProperty(uint64_t objId, JSIDVariant id, PPropertyDescriptor descriptor) returns (ReturnStatus rs); + rpc Delete(uint64_t objId, JSIDVariant 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, 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 Has(uint64_t objId, JSIDVariant id) returns (ReturnStatus rs, bool has); + rpc HasOwn(uint64_t objId, JSIDVariant id) returns (ReturnStatus rs, bool has); + rpc Get(uint64_t objId, ObjectVariant receiver, JSIDVariant id) returns (ReturnStatus rs, JSVariant result); + rpc Set(uint64_t objId, ObjectVariant receiver, JSIDVariant id, bool strict, JSVariant value) returns (ReturnStatus rs, JSVariant result); rpc IsExtensible(uint64_t objId) returns (ReturnStatus rs, bool result); rpc CallOrConstruct(uint64_t objId, JSParam[] argv, bool construct) returns (ReturnStatus rs, JSVariant result, JSParam[] outparams); diff --git a/js/ipc/WrapperAnswer.cpp b/js/ipc/WrapperAnswer.cpp index 5fb3e45040d1..9fb1fa3bbbc3 100644 --- a/js/ipc/WrapperAnswer.cpp +++ b/js/ipc/WrapperAnswer.cpp @@ -87,8 +87,8 @@ EmptyDesc(PPropertyDescriptor *desc) } bool -WrapperAnswer::AnswerGetPropertyDescriptor(const ObjectId &objId, const nsString &id, - ReturnStatus *rs, PPropertyDescriptor *out) +WrapperAnswer::AnswerGetPropertyDescriptor(const ObjectId &objId, const JSIDVariant &idVar, + ReturnStatus *rs, PPropertyDescriptor *out) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -101,14 +101,14 @@ WrapperAnswer::AnswerGetPropertyDescriptor(const ObjectId &objId, const nsString JSAutoCompartment comp(cx, obj); - LOG("%s.getPropertyDescriptor(%s)", ReceiverObj(objId), id); + LOG("%s.getPropertyDescriptor(%s)", ReceiverObj(objId), Identifier(idVar)); - RootedId internedId(cx); - if (!convertGeckoStringToId(cx, id, &internedId)) + RootedId id(cx); + if (!fromJSIDVariant(cx, idVar, &id)) return fail(cx, rs); Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, obj, internedId, &desc)) + if (!JS_GetPropertyDescriptorById(cx, obj, id, &desc)) return fail(cx, rs); if (!desc.object()) @@ -121,8 +121,8 @@ WrapperAnswer::AnswerGetPropertyDescriptor(const ObjectId &objId, const nsString } bool -WrapperAnswer::AnswerGetOwnPropertyDescriptor(const ObjectId &objId, const nsString &id, - ReturnStatus *rs, PPropertyDescriptor *out) +WrapperAnswer::AnswerGetOwnPropertyDescriptor(const ObjectId &objId, const JSIDVariant &idVar, + ReturnStatus *rs, PPropertyDescriptor *out) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -135,14 +135,14 @@ WrapperAnswer::AnswerGetOwnPropertyDescriptor(const ObjectId &objId, const nsStr JSAutoCompartment comp(cx, obj); - LOG("%s.getOwnPropertyDescriptor(%s)", ReceiverObj(objId), id); + LOG("%s.getOwnPropertyDescriptor(%s)", ReceiverObj(objId), Identifier(idVar)); - RootedId internedId(cx); - if (!convertGeckoStringToId(cx, id, &internedId)) + RootedId id(cx); + if (!fromJSIDVariant(cx, idVar, &id)) return fail(cx, rs); Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, obj, internedId, &desc)) + if (!JS_GetPropertyDescriptorById(cx, obj, id, &desc)) return fail(cx, rs); if (desc.object() != obj) @@ -155,8 +155,8 @@ WrapperAnswer::AnswerGetOwnPropertyDescriptor(const ObjectId &objId, const nsStr } bool -WrapperAnswer::AnswerDefineProperty(const ObjectId &objId, const nsString &id, - const PPropertyDescriptor &descriptor, ReturnStatus *rs) +WrapperAnswer::AnswerDefineProperty(const ObjectId &objId, const JSIDVariant &idVar, + const PPropertyDescriptor &descriptor, ReturnStatus *rs) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -167,23 +167,23 @@ WrapperAnswer::AnswerDefineProperty(const ObjectId &objId, const nsString &id, JSAutoCompartment comp(cx, obj); - LOG("define %s[%s]", ReceiverObj(objId), id); + LOG("define %s[%s]", ReceiverObj(objId), Identifier(idVar)); - RootedId internedId(cx); - if (!convertGeckoStringToId(cx, id, &internedId)) + RootedId id(cx); + if (!fromJSIDVariant(cx, idVar, &id)) return fail(cx, rs); Rooted desc(cx); if (!toDescriptor(cx, descriptor, &desc)) return fail(cx, rs); - if (!js::CheckDefineProperty(cx, obj, internedId, desc.value(), desc.attributes(), + if (!js::CheckDefineProperty(cx, obj, id, desc.value(), desc.attributes(), desc.getter(), desc.setter())) { return fail(cx, rs); } - if (!JS_DefinePropertyById(cx, obj, internedId, desc.value(), desc.attributes(), + if (!JS_DefinePropertyById(cx, obj, id, desc.value(), desc.attributes(), desc.getter(), desc.setter())) { return fail(cx, rs); @@ -193,8 +193,8 @@ WrapperAnswer::AnswerDefineProperty(const ObjectId &objId, const nsString &id, } bool -WrapperAnswer::AnswerDelete(const ObjectId &objId, const nsString &id, ReturnStatus *rs, - bool *success) +WrapperAnswer::AnswerDelete(const ObjectId &objId, const JSIDVariant &idVar, ReturnStatus *rs, + bool *success) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -207,20 +207,20 @@ WrapperAnswer::AnswerDelete(const ObjectId &objId, const nsString &id, ReturnSta JSAutoCompartment comp(cx, obj); - LOG("delete %s[%s]", ReceiverObj(objId), id); + LOG("delete %s[%s]", ReceiverObj(objId), Identifier(idVar)); - RootedId internedId(cx); - if (!convertGeckoStringToId(cx, id, &internedId)) + RootedId id(cx); + if (!fromJSIDVariant(cx, idVar, &id)) return fail(cx, rs); - if (!JS_DeletePropertyById2(cx, obj, internedId, success)) + if (!JS_DeletePropertyById2(cx, obj, id, success)) return fail(cx, rs); return ok(rs); } bool -WrapperAnswer::AnswerHas(const ObjectId &objId, const nsString &id, ReturnStatus *rs, bool *bp) +WrapperAnswer::AnswerHas(const ObjectId &objId, const JSIDVariant &idVar, ReturnStatus *rs, bool *bp) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -233,14 +233,14 @@ WrapperAnswer::AnswerHas(const ObjectId &objId, const nsString &id, ReturnStatus JSAutoCompartment comp(cx, obj); - LOG("%s.has(%s)", ReceiverObj(objId), id); + LOG("%s.has(%s)", ReceiverObj(objId), Identifier(idVar)); - RootedId internedId(cx); - if (!convertGeckoStringToId(cx, id, &internedId)) + RootedId id(cx); + if (!fromJSIDVariant(cx, idVar, &id)) return fail(cx, rs); bool found; - if (!JS_HasPropertyById(cx, obj, internedId, &found)) + if (!JS_HasPropertyById(cx, obj, id, &found)) return fail(cx, rs); *bp = !!found; @@ -248,7 +248,8 @@ WrapperAnswer::AnswerHas(const ObjectId &objId, const nsString &id, ReturnStatus } bool -WrapperAnswer::AnswerHasOwn(const ObjectId &objId, const nsString &id, ReturnStatus *rs, bool *bp) +WrapperAnswer::AnswerHasOwn(const ObjectId &objId, const JSIDVariant &idVar, ReturnStatus *rs, + bool *bp) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -261,14 +262,14 @@ WrapperAnswer::AnswerHasOwn(const ObjectId &objId, const nsString &id, ReturnSta JSAutoCompartment comp(cx, obj); - LOG("%s.hasOwn(%s)", ReceiverObj(objId), id); + LOG("%s.hasOwn(%s)", ReceiverObj(objId), Identifier(idVar)); - RootedId internedId(cx); - if (!convertGeckoStringToId(cx, id, &internedId)) + RootedId id(cx); + if (!fromJSIDVariant(cx, idVar, &id)) return fail(cx, rs); Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, obj, internedId, &desc)) + if (!JS_GetPropertyDescriptorById(cx, obj, id, &desc)) return fail(cx, rs); *bp = (desc.object() == obj); @@ -276,8 +277,8 @@ WrapperAnswer::AnswerHasOwn(const ObjectId &objId, const nsString &id, ReturnSta } bool -WrapperAnswer::AnswerGet(const ObjectId &objId, const ObjectVariant &receiverVar, const nsString &id, - ReturnStatus *rs, JSVariant *result) +WrapperAnswer::AnswerGet(const ObjectId &objId, const ObjectVariant &receiverVar, + const JSIDVariant &idVar, ReturnStatus *rs, JSVariant *result) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -296,26 +297,26 @@ WrapperAnswer::AnswerGet(const ObjectId &objId, const ObjectVariant &receiverVar if (!receiver) return fail(cx, rs); - RootedId internedId(cx); - if (!convertGeckoStringToId(cx, id, &internedId)) + RootedId id(cx); + if (!fromJSIDVariant(cx, idVar, &id)) return fail(cx, rs); JS::RootedValue val(cx); - if (!JS_ForwardGetPropertyTo(cx, obj, internedId, receiver, &val)) + if (!JS_ForwardGetPropertyTo(cx, obj, id, receiver, &val)) return fail(cx, rs); if (!toVariant(cx, val, result)) return fail(cx, rs); - LOG("get %s.%s = %s", ReceiverObj(objId), id, OutVariant(*result)); + LOG("get %s.%s = %s", ReceiverObj(objId), Identifier(idVar), OutVariant(*result)); return ok(rs); } bool -WrapperAnswer::AnswerSet(const ObjectId &objId, const ObjectVariant &receiverVar, const nsString &id, - const bool &strict, const JSVariant &value, ReturnStatus *rs, - JSVariant *result) +WrapperAnswer::AnswerSet(const ObjectId &objId, const ObjectVariant &receiverVar, + const JSIDVariant &idVar, const bool &strict, const JSVariant &value, + ReturnStatus *rs, JSVariant *result) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -334,10 +335,10 @@ WrapperAnswer::AnswerSet(const ObjectId &objId, const ObjectVariant &receiverVar if (!receiver) return fail(cx, rs); - LOG("set %s[%s] = %s", ReceiverObj(objId), id, InVariant(value)); + LOG("set %s[%s] = %s", ReceiverObj(objId), Identifier(idVar), InVariant(value)); - RootedId internedId(cx); - if (!convertGeckoStringToId(cx, id, &internedId)) + RootedId id(cx); + if (!fromJSIDVariant(cx, idVar, &id)) return fail(cx, rs); MOZ_ASSERT(obj == receiver); @@ -346,7 +347,7 @@ WrapperAnswer::AnswerSet(const ObjectId &objId, const ObjectVariant &receiverVar if (!fromVariant(cx, value, &val)) return fail(cx, rs); - if (!JS_SetPropertyById(cx, obj, internedId, val)) + if (!JS_SetPropertyById(cx, obj, id, val)) return fail(cx, rs); if (!toVariant(cx, val, result)) @@ -512,7 +513,7 @@ WrapperAnswer::AnswerHasInstance(const ObjectId &objId, const JSVariant &vVar, R bool WrapperAnswer::AnswerObjectClassIs(const ObjectId &objId, const uint32_t &classValue, - bool *result) + bool *result) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -579,7 +580,7 @@ WrapperAnswer::AnswerRegExpToShared(const ObjectId &objId, ReturnStatus *rs, bool WrapperAnswer::AnswerGetPropertyNames(const ObjectId &objId, const uint32_t &flags, - ReturnStatus *rs, nsTArray *names) + ReturnStatus *rs, nsTArray *names) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -609,7 +610,7 @@ WrapperAnswer::AnswerGetPropertyNames(const ObjectId &objId, const uint32_t &fla bool WrapperAnswer::AnswerInstanceOf(const ObjectId &objId, const JSIID &iid, ReturnStatus *rs, - bool *instanceof) + bool *instanceof) { AutoSafeJSContext cx; JSAutoRequest request(cx); @@ -636,8 +637,7 @@ WrapperAnswer::AnswerInstanceOf(const ObjectId &objId, const JSIID &iid, ReturnS bool WrapperAnswer::AnswerDOMInstanceOf(const ObjectId &objId, const int &prototypeID, - const int &depth, - ReturnStatus *rs, bool *instanceof) + const int &depth, ReturnStatus *rs, bool *instanceof) { AutoSafeJSContext cx; JSAutoRequest request(cx); diff --git a/js/ipc/WrapperAnswer.h b/js/ipc/WrapperAnswer.h index 9bc998c078d6..330c5d662d17 100644 --- a/js/ipc/WrapperAnswer.h +++ b/js/ipc/WrapperAnswer.h @@ -19,28 +19,28 @@ class WrapperAnswer : public virtual JavaScriptShared explicit WrapperAnswer(JSRuntime *rt) : JavaScriptShared(rt) {} bool AnswerPreventExtensions(const ObjectId &objId, ReturnStatus *rs); - bool AnswerGetPropertyDescriptor(const ObjectId &objId, const nsString &id, + bool AnswerGetPropertyDescriptor(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, PPropertyDescriptor *out); bool AnswerGetOwnPropertyDescriptor(const ObjectId &objId, - const nsString &id, + const JSIDVariant &id, ReturnStatus *rs, PPropertyDescriptor *out); - bool AnswerDefineProperty(const ObjectId &objId, const nsString &id, + bool AnswerDefineProperty(const ObjectId &objId, const JSIDVariant &id, const PPropertyDescriptor &flags, ReturnStatus *rs); - bool AnswerDelete(const ObjectId &objId, const nsString &id, + bool AnswerDelete(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, bool *success); - bool AnswerHas(const ObjectId &objId, const nsString &id, + bool AnswerHas(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, bool *bp); - bool AnswerHasOwn(const ObjectId &objId, const nsString &id, + bool AnswerHasOwn(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, bool *bp); bool AnswerGet(const ObjectId &objId, const ObjectVariant &receiverVar, - const nsString &id, + const JSIDVariant &id, ReturnStatus *rs, JSVariant *result); bool AnswerSet(const ObjectId &objId, const ObjectVariant &receiverVar, - const nsString &id, const bool &strict, + const JSIDVariant &id, const bool &strict, const JSVariant &value, ReturnStatus *rs, JSVariant *result); bool AnswerIsExtensible(const ObjectId &objId, ReturnStatus *rs, diff --git a/js/ipc/WrapperOwner.cpp b/js/ipc/WrapperOwner.cpp index 906f7a55a9da..33e48cc89ea0 100644 --- a/js/ipc/WrapperOwner.cpp +++ b/js/ipc/WrapperOwner.cpp @@ -145,13 +145,13 @@ WrapperOwner::getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId { ObjectId objId = idOf(proxy); - nsString idstr; - if (!convertIdToGeckoString(cx, id, &idstr)) + JSIDVariant idVar; + if (!toJSIDVariant(cx, id, &idVar)) return false; ReturnStatus status; PPropertyDescriptor result; - if (!CallGetPropertyDescriptor(objId, idstr, &status, &result)) + if (!CallGetPropertyDescriptor(objId, idVar, &status, &result)) return ipcfail(cx); LOG_STACK(); @@ -175,13 +175,13 @@ WrapperOwner::getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, Handle { ObjectId objId = idOf(proxy); - nsString idstr; - if (!convertIdToGeckoString(cx, id, &idstr)) + JSIDVariant idVar; + if (!toJSIDVariant(cx, id, &idVar)) return false; ReturnStatus status; PPropertyDescriptor result; - if (!CallGetOwnPropertyDescriptor(objId, idstr, &status, &result)) + if (!CallGetOwnPropertyDescriptor(objId, idVar, &status, &result)) return ipcfail(cx); LOG_STACK(); @@ -205,8 +205,8 @@ WrapperOwner::defineProperty(JSContext *cx, HandleObject proxy, HandleId id, { ObjectId objId = idOf(proxy); - nsString idstr; - if (!convertIdToGeckoString(cx, id, &idstr)) + JSIDVariant idVar; + if (!toJSIDVariant(cx, id, &idVar)) return false; PPropertyDescriptor descriptor; @@ -214,7 +214,7 @@ WrapperOwner::defineProperty(JSContext *cx, HandleObject proxy, HandleId id, return false; ReturnStatus status; - if (!CallDefineProperty(objId, idstr, descriptor, &status)) + if (!CallDefineProperty(objId, idVar, descriptor, &status)) return ipcfail(cx); LOG_STACK(); @@ -246,12 +246,12 @@ WrapperOwner::delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) { ObjectId objId = idOf(proxy); - nsString idstr; - if (!convertIdToGeckoString(cx, id, &idstr)) + JSIDVariant idVar; + if (!toJSIDVariant(cx, id, &idVar)) return false; ReturnStatus status; - if (!CallDelete(objId, idstr, &status, bp)) + if (!CallDelete(objId, idVar, &status, bp)) return ipcfail(cx); LOG_STACK(); @@ -282,12 +282,12 @@ WrapperOwner::has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) { ObjectId objId = idOf(proxy); - nsString idstr; - if (!convertIdToGeckoString(cx, id, &idstr)) + JSIDVariant idVar; + if (!toJSIDVariant(cx, id, &idVar)) return false; ReturnStatus status; - if (!CallHas(objId, idstr, &status, bp)) + if (!CallHas(objId, idVar, &status, bp)) return ipcfail(cx); LOG_STACK(); @@ -306,12 +306,12 @@ WrapperOwner::hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) { ObjectId objId = idOf(proxy); - nsString idstr; - if (!convertIdToGeckoString(cx, id, &idstr)) + JSIDVariant idVar; + if (!toJSIDVariant(cx, id, &idVar)) return false; ReturnStatus status; - if (!CallHasOwn(objId, idstr, &status, bp)) + if (!CallHasOwn(objId, idVar, &status, bp)) return ipcfail(cx); LOG_STACK(); @@ -382,7 +382,7 @@ WrapperOwner::toString(JSContext *cx, HandleObject cpow, JS::CallArgs &args) bool WrapperOwner::get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp) + HandleId id, MutableHandleValue vp) { ObjectId objId = idOf(proxy); @@ -390,13 +390,13 @@ WrapperOwner::get(JSContext *cx, HandleObject proxy, HandleObject receiver, if (!toObjectVariant(cx, receiver, &receiverVar)) return false; - nsString idstr; - if (!convertIdToGeckoString(cx, id, &idstr)) + JSIDVariant idVar; + if (!toJSIDVariant(cx, id, &idVar)) return false; JSVariant val; ReturnStatus status; - if (!CallGet(objId, receiverVar, idstr, &status, &val)) + if (!CallGet(objId, receiverVar, idVar, &status, &val)) return ipcfail(cx); LOG_STACK(); @@ -407,7 +407,8 @@ WrapperOwner::get(JSContext *cx, HandleObject proxy, HandleObject receiver, if (!fromVariant(cx, val, vp)) return false; - if (idstr.EqualsLiteral("toString")) { + if (idVar.type() == JSIDVariant::TnsString && + idVar.get_nsString().EqualsLiteral("toString")) { RootedFunction toString(cx, JS_NewFunction(cx, CPOWToString, 0, 0, proxy, "toString")); if (!toString) return false; @@ -432,7 +433,7 @@ CPOWProxyHandler::set(JSContext *cx, JS::HandleObject proxy, JS::HandleObject re bool WrapperOwner::set(JSContext *cx, JS::HandleObject proxy, JS::HandleObject receiver, - JS::HandleId id, bool strict, JS::MutableHandleValue vp) + JS::HandleId id, bool strict, JS::MutableHandleValue vp) { ObjectId objId = idOf(proxy); @@ -440,8 +441,8 @@ WrapperOwner::set(JSContext *cx, JS::HandleObject proxy, JS::HandleObject receiv if (!toObjectVariant(cx, receiver, &receiverVar)) return false; - nsString idstr; - if (!convertIdToGeckoString(cx, id, &idstr)) + JSIDVariant idVar; + if (!toJSIDVariant(cx, id, &idVar)) return false; JSVariant val; @@ -450,7 +451,7 @@ WrapperOwner::set(JSContext *cx, JS::HandleObject proxy, JS::HandleObject receiv ReturnStatus status; JSVariant result; - if (!CallSet(objId, receiverVar, idstr, strict, val, &status, &result)) + if (!CallSet(objId, receiverVar, idVar, strict, val, &status, &result)) return ipcfail(cx); LOG_STACK(); diff --git a/js/ipc/WrapperOwner.h b/js/ipc/WrapperOwner.h index 98e55355d02c..5e6060f7e63f 100644 --- a/js/ipc/WrapperOwner.h +++ b/js/ipc/WrapperOwner.h @@ -108,28 +108,28 @@ class WrapperOwner : public virtual JavaScriptShared public: virtual bool SendDropObject(const ObjectId &objId) = 0; virtual bool CallPreventExtensions(const ObjectId &objId, ReturnStatus *rs) = 0; - virtual bool CallGetPropertyDescriptor(const ObjectId &objId, const nsString &id, + virtual bool CallGetPropertyDescriptor(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, PPropertyDescriptor *out) = 0; virtual bool CallGetOwnPropertyDescriptor(const ObjectId &objId, - const nsString &id, + const JSIDVariant &id, ReturnStatus *rs, PPropertyDescriptor *out) = 0; - virtual bool CallDefineProperty(const ObjectId &objId, const nsString &id, + virtual bool CallDefineProperty(const ObjectId &objId, const JSIDVariant &id, const PPropertyDescriptor &flags, ReturnStatus *rs) = 0; - virtual bool CallDelete(const ObjectId &objId, const nsString &id, + virtual bool CallDelete(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, bool *success) = 0; - virtual bool CallHas(const ObjectId &objId, const nsString &id, + virtual bool CallHas(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, bool *bp) = 0; - virtual bool CallHasOwn(const ObjectId &objId, const nsString &id, + virtual bool CallHasOwn(const ObjectId &objId, const JSIDVariant &id, ReturnStatus *rs, bool *bp) = 0; virtual bool CallGet(const ObjectId &objId, const ObjectVariant &receiverVar, - const nsString &id, + const JSIDVariant &id, ReturnStatus *rs, JSVariant *result) = 0; virtual bool CallSet(const ObjectId &objId, const ObjectVariant &receiverVar, - const nsString &id, const bool &strict, + const JSIDVariant &id, const bool &strict, const JSVariant &value, ReturnStatus *rs, JSVariant *result) = 0; virtual bool CallIsExtensible(const ObjectId &objId, ReturnStatus *rs,