From 6b342c5c13b71215acfc33f5fc2d395ea055cd38 Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Wed, 12 Sep 2018 20:04:14 +0000 Subject: [PATCH] Bug 1490632 - Always use braces for if/for/while statements in js/ipc. r=evilpie Differential Revision: https://phabricator.services.mozilla.com/D5661 --HG-- extra : moz-landing-system : lando --- js/ipc/CPOWTimer.cpp | 3 +- js/ipc/JavaScriptLogging.h | 3 +- js/ipc/JavaScriptParent.cpp | 12 +- js/ipc/JavaScriptShared.cpp | 149 +++++++++++------ js/ipc/JavaScriptShared.h | 3 +- js/ipc/WrapperAnswer.cpp | 321 ++++++++++++++++++++++++------------ js/ipc/WrapperOwner.cpp | 251 ++++++++++++++++++---------- 7 files changed, 494 insertions(+), 248 deletions(-) diff --git a/js/ipc/CPOWTimer.cpp b/js/ipc/CPOWTimer.cpp index 4f2add7f5015..2e4d0195df59 100644 --- a/js/ipc/CPOWTimer.cpp +++ b/js/ipc/CPOWTimer.cpp @@ -16,8 +16,9 @@ CPOWTimer::CPOWTimer(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL) , startInterval_(0) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; - if (!js::GetStopwatchIsMonitoringCPOW(cx)) + if (!js::GetStopwatchIsMonitoringCPOW(cx)) { return; + } cx_ = cx; startInterval_ = JS_Now(); } diff --git a/js/ipc/JavaScriptLogging.h b/js/ipc/JavaScriptLogging.h index 344307a18e88..e1dbe74b58a7 100644 --- a/js/ipc/JavaScriptLogging.h +++ b/js/ipc/JavaScriptLogging.h @@ -128,8 +128,9 @@ class Logging nsAutoCString tmp; out.Truncate(); for (size_t i = 0; i < values.Length(); i++) { - if (i) + if (i) { out.AppendLiteral(", "); + } if (values[i].type() == JSParam::Tvoid_t) { out.AppendLiteral(""); } else { diff --git a/js/ipc/JavaScriptParent.cpp b/js/ipc/JavaScriptParent.cpp index e8e6205fd5a3..bdd8221be50a 100644 --- a/js/ipc/JavaScriptParent.cpp +++ b/js/ipc/JavaScriptParent.cpp @@ -75,8 +75,9 @@ JavaScriptParent::allowMessage(JSContext* cx) MessageChannel* channel = GetIPCChannel(); bool isSafe = channel->IsInTransaction(); - if (isSafe) + if (isSafe) { return true; + } nsIGlobalObject* global = dom::GetIncumbentGlobal(); JS::Rooted jsGlobal(cx, global ? global->GetGlobalJSObject() : nullptr); @@ -134,14 +135,16 @@ JavaScriptParent::scopeForTargetObjects() void JavaScriptParent::afterProcessTask() { - if (savedNextCPOWNumber_ == nextCPOWNumber_) + if (savedNextCPOWNumber_ == nextCPOWNumber_) { return; + } savedNextCPOWNumber_ = nextCPOWNumber_; MOZ_ASSERT(nextCPOWNumber_ > 0); - if (active()) + if (active()) { Unused << SendDropTemporaryStrongReferences(nextCPOWNumber_ - 1); + } } PJavaScriptParent* @@ -160,7 +163,8 @@ void mozilla::jsipc::AfterProcessTask() { for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) { - if (PJavaScriptParent* p = LoneManagedOrNullAsserts(cp->ManagedPJavaScriptParent())) + if (PJavaScriptParent* p = LoneManagedOrNullAsserts(cp->ManagedPJavaScriptParent())) { static_cast(p)->afterProcessTask(); + } } } diff --git a/js/ipc/JavaScriptShared.cpp b/js/ipc/JavaScriptShared.cpp index 2335751907fd..7aa0d3820977 100644 --- a/js/ipc/JavaScriptShared.cpp +++ b/js/ipc/JavaScriptShared.cpp @@ -28,8 +28,9 @@ void IdToObjectMap::trace(JSTracer* trc, uint64_t minimumId) { for (Table::Range r(table_.all()); !r.empty(); r.popFront()) { - if (r.front().key().serialNumber() >= minimumId) + if (r.front().key().serialNumber() >= minimumId) { JS::TraceEdge(trc, &r.front().value(), "ipc-object"); + } } } @@ -39,8 +40,9 @@ IdToObjectMap::sweep() for (Table::Enum e(table_); !e.empty(); e.popFront()) { JS::Heap* objp = &e.front().value(); JS_UpdateWeakPointerAfterGC(objp); - if (!*objp) + if (!*objp) { e.removeFront(); + } } } @@ -48,8 +50,9 @@ JSObject* IdToObjectMap::find(ObjectId id) { Table::Ptr p = table_.lookup(id); - if (!p) + if (!p) { return nullptr; + } return p->value(); } @@ -57,8 +60,9 @@ JSObject* IdToObjectMap::findPreserveColor(ObjectId id) { Table::Ptr p = table_.lookup(id); - if (!p) + if (!p) { return nullptr; + } return p->value().unbarrieredGet(); } @@ -91,8 +95,9 @@ bool IdToObjectMap::has(const ObjectId& id, const JSObject* obj) const { auto p = table_.lookup(id); - if (!p) + if (!p) { return false; + } return p->value() == obj; } #endif @@ -118,8 +123,9 @@ ObjectId ObjectToIdMap::find(JSObject* obj) { Table::Ptr p = table_.lookup(obj); - if (!p) + if (!p) { return ObjectId::nullId(); + } return p->value(); } @@ -174,8 +180,9 @@ void JavaScriptShared::decref() { refcount_--; - if (!refcount_) + if (!refcount_) { delete this; + } } void @@ -188,12 +195,14 @@ bool JavaScriptShared::convertIdToGeckoString(JSContext* cx, JS::HandleId id, nsString* to) { RootedValue idval(cx); - if (!JS_IdToValue(cx, id, &idval)) + if (!JS_IdToValue(cx, id, &idval)) { return false; + } RootedString str(cx, ToString(cx, idval)); - if (!str) + if (!str) { return false; + } return AssignJSString(cx, *to, str); } @@ -202,8 +211,9 @@ bool JavaScriptShared::convertGeckoStringToId(JSContext* cx, const nsString& from, JS::MutableHandleId to) { RootedString str(cx, JS_NewUCStringCopyN(cx, from.BeginReading(), from.Length())); - if (!str) + if (!str) { return false; + } return JS_StringToId(cx, str, to); } @@ -235,8 +245,9 @@ JavaScriptShared::toVariant(JSContext* cx, JS::HandleValue from, JSVariant* to) } ObjectVariant objVar; - if (!toObjectVariant(cx, obj, &objVar)) + if (!toObjectVariant(cx, obj, &objVar)) { return false; + } *to = objVar; return true; } @@ -246,8 +257,9 @@ JavaScriptShared::toVariant(JSContext* cx, JS::HandleValue from, JSVariant* to) RootedSymbol sym(cx, from.toSymbol()); SymbolVariant symVar; - if (!toSymbolVariant(cx, sym, &symVar)) + if (!toSymbolVariant(cx, sym, &symVar)) { return false; + } *to = symVar; return true; } @@ -255,17 +267,19 @@ JavaScriptShared::toVariant(JSContext* cx, JS::HandleValue from, JSVariant* to) case JSTYPE_STRING: { nsAutoJSString autoStr; - if (!autoStr.init(cx, from)) + if (!autoStr.init(cx, from)) { return false; + } *to = autoStr; return true; } case JSTYPE_NUMBER: - if (from.isInt32()) + if (from.isInt32()) { *to = double(from.toInt32()); - else + } else { *to = from.toDouble(); + } return true; case JSTYPE_BOOLEAN: @@ -293,8 +307,9 @@ JavaScriptShared::fromVariant(JSContext* cx, const JSVariant& from, MutableHandl case JSVariant::TObjectVariant: { JSObject* obj = fromObjectVariant(cx, from.get_ObjectVariant()); - if (!obj) + if (!obj) { return false; + } to.set(ObjectValue(*obj)); return true; } @@ -302,8 +317,9 @@ JavaScriptShared::fromVariant(JSContext* cx, const JSVariant& from, MutableHandl case JSVariant::TSymbolVariant: { Symbol* sym = fromSymbolVariant(cx, from.get_SymbolVariant()); - if (!sym) + if (!sym) { return false; + } to.setSymbol(sym); return true; } @@ -320,8 +336,9 @@ JavaScriptShared::fromVariant(JSContext* cx, const JSVariant& from, MutableHandl { const nsString& old = from.get_nsString(); JSString* str = JS_NewUCStringCopyN(cx, old.BeginReading(), old.Length()); - if (!str) + if (!str) { return false; + } to.set(StringValue(str)); return true; } @@ -334,8 +351,9 @@ JavaScriptShared::fromVariant(JSContext* cx, const JSVariant& from, MutableHandl RootedObject global(cx, JS::CurrentGlobalOrNull(cx)); JSObject* obj = xpc_NewIDObject(cx, global, iid); - if (!obj) + if (!obj) { return false; + } to.set(ObjectValue(*obj)); return true; } @@ -351,8 +369,9 @@ JavaScriptShared::toJSIDVariant(JSContext* cx, HandleId from, JSIDVariant* to) { if (JSID_IS_STRING(from)) { nsAutoJSString autoStr; - if (!autoStr.init(cx, JSID_TO_STRING(from))) + if (!autoStr.init(cx, JSID_TO_STRING(from))) { return false; + } *to = autoStr; return true; } @@ -362,8 +381,9 @@ JavaScriptShared::toJSIDVariant(JSContext* cx, HandleId from, JSIDVariant* to) } if (JSID_IS_SYMBOL(from)) { SymbolVariant symVar; - if (!toSymbolVariant(cx, JSID_TO_SYMBOL(from), &symVar)) + if (!toSymbolVariant(cx, JSID_TO_SYMBOL(from), &symVar)) { return false; + } *to = symVar; return true; } @@ -377,8 +397,9 @@ JavaScriptShared::fromJSIDVariant(JSContext* cx, const JSIDVariant& from, Mutabl switch (from.type()) { case JSIDVariant::TSymbolVariant: { Symbol* sym = fromSymbolVariant(cx, from.get_SymbolVariant()); - if (!sym) + if (!sym) { return false; + } to.set(SYMBOL_TO_JSID(sym)); return true; } @@ -408,8 +429,9 @@ JavaScriptShared::toSymbolVariant(JSContext* cx, JS::Symbol* symArg, SymbolVaria } if (code == SymbolCode::InSymbolRegistry) { nsAutoJSString autoStr; - if (!autoStr.init(cx, GetSymbolDescription(sym))) + if (!autoStr.init(cx, GetSymbolDescription(sym))) { return false; + } *symVarp = RegisteredSymbol(autoStr); return true; } @@ -424,8 +446,9 @@ JavaScriptShared::fromSymbolVariant(JSContext* cx, const SymbolVariant& symVar) switch (symVar.type()) { case SymbolVariant::TWellKnownSymbol: { uint32_t which = symVar.get_WellKnownSymbol().which(); - if (which < WellKnownSymbolLimit) + if (which < WellKnownSymbolLimit) { return GetWellKnownSymbol(cx, static_cast(which)); + } MOZ_ASSERT(false, "bad child data"); return nullptr; } @@ -433,8 +456,9 @@ JavaScriptShared::fromSymbolVariant(JSContext* cx, const SymbolVariant& symVar) case SymbolVariant::TRegisteredSymbol: { nsString key = symVar.get_RegisteredSymbol().key(); RootedString str(cx, JS_NewUCStringCopyN(cx, key.get(), key.Length())); - if (!str) + if (!str) { return nullptr; + } return GetSymbolFor(cx, str); } @@ -479,8 +503,9 @@ JSObject* JavaScriptShared::findCPOWById(const ObjectId& objId) { JSObject* obj = findCPOWByIdPreserveColor(objId); - if (obj) + if (obj) { JS::ExposeObjectToActiveJS(obj); + } return obj; } @@ -488,8 +513,9 @@ JSObject* JavaScriptShared::findCPOWByIdPreserveColor(const ObjectId& objId) { JSObject* obj = cpows_.findPreserveColor(objId); - if (!obj) + if (!obj) { return nullptr; + } if (js::gc::EdgeNeedsSweepUnbarriered(&obj)) { cpows_.remove(objId); @@ -516,11 +542,13 @@ JavaScriptShared::findObjectById(JSContext* cx, const ObjectId& objId) if (objId.hasXrayWaiver()) { obj = js::ToWindowProxyIfWindow(obj); MOZ_ASSERT(obj); - if (!xpc::WrapperFactory::WaiveXrayAndWrap(cx, &obj)) + if (!xpc::WrapperFactory::WaiveXrayAndWrap(cx, &obj)) { return nullptr; + } } else { - if (!JS_WrapObject(cx, &obj)) + if (!JS_WrapObject(cx, &obj)) { return nullptr; + } } return obj; } @@ -532,19 +560,22 @@ JavaScriptShared::fromDescriptor(JSContext* cx, Handle desc, PPropertyDescriptor* out) { out->attrs() = desc.attributes(); - if (!toVariant(cx, desc.value(), &out->value())) + if (!toVariant(cx, desc.value(), &out->value())) { return false; + } - if (!toObjectOrNullVariant(cx, desc.object(), &out->obj())) + if (!toObjectOrNullVariant(cx, desc.object(), &out->obj())) { return false; + } if (!desc.getter()) { out->getter() = 0; } else if (desc.hasGetterObject()) { JSObject* getter = desc.getterObject(); ObjectVariant objVar; - if (!toObjectVariant(cx, getter, &objVar)) + if (!toObjectVariant(cx, getter, &objVar)) { return false; + } out->getter() = objVar; } else { out->getter() = UnknownPropertyOp; @@ -555,8 +586,9 @@ JavaScriptShared::fromDescriptor(JSContext* cx, Handle desc, } else if (desc.hasSetterObject()) { JSObject* setter = desc.setterObject(); ObjectVariant objVar; - if (!toObjectVariant(cx, setter, &objVar)) + if (!toObjectVariant(cx, setter, &objVar)) { return false; + } out->setter() = objVar; } else { out->setter() = UnknownPropertyOp; @@ -585,8 +617,9 @@ JavaScriptShared::toDescriptor(JSContext* cx, const PPropertyDescriptor& in, MutableHandle out) { out.setAttributes(in.attrs()); - if (!fromVariant(cx, in.value(), out.value())) + if (!fromVariant(cx, in.value(), out.value())) { return false; + } out.object().set(fromObjectOrNullVariant(cx, in.obj())); if (in.getter().type() == GetterSetter::Tuint64_t && !in.getter().get_uint64_t()) { @@ -594,8 +627,9 @@ JavaScriptShared::toDescriptor(JSContext* cx, const PPropertyDescriptor& in, } else if (in.attrs() & JSPROP_GETTER) { Rooted getter(cx); getter = fromObjectVariant(cx, in.getter().get_ObjectVariant()); - if (!getter) + if (!getter) { return false; + } out.setGetter(JS_DATA_TO_FUNC_PTR(JSGetterOp, getter.get())); } else { out.setGetter(UnknownPropertyStub); @@ -606,8 +640,9 @@ JavaScriptShared::toDescriptor(JSContext* cx, const PPropertyDescriptor& in, } else if (in.attrs() & JSPROP_SETTER) { Rooted setter(cx); setter = fromObjectVariant(cx, in.setter().get_ObjectVariant()); - if (!setter) + if (!setter) { return false; + } out.setSetter(JS_DATA_TO_FUNC_PTR(JSSetterOp, setter.get())); } else { out.setSetter(UnknownStrictPropertyStub); @@ -625,8 +660,9 @@ JavaScriptShared::toObjectOrNullVariant(JSContext* cx, JSObject* obj, ObjectOrNu } ObjectVariant objVar; - if (!toObjectVariant(cx, obj, &objVar)) + if (!toObjectVariant(cx, obj, &objVar)) { return false; + } *objVarp = objVar; return true; @@ -635,8 +671,9 @@ JavaScriptShared::toObjectOrNullVariant(JSContext* cx, JSObject* obj, ObjectOrNu JSObject* JavaScriptShared::fromObjectOrNullVariant(JSContext* cx, const ObjectOrNullVariant& objVar) { - if (objVar.type() == ObjectOrNullVariant::TNullVariant) + if (objVar.type() == ObjectOrNullVariant::TNullVariant) { return nullptr; + } return fromObjectVariant(cx, objVar.get_ObjectVariant()); } @@ -648,8 +685,9 @@ CrossProcessCpowHolder::CrossProcessCpowHolder(dom::CPOWManagerGetter* managerGe unwrapped_(false) { // Only instantiate the CPOW manager if we might need it later. - if (cpows.Length()) + if (cpows.Length()) { js_ = managerGetter->GetCPOWManager(); + } } CrossProcessCpowHolder::~CrossProcessCpowHolder() @@ -665,11 +703,13 @@ CrossProcessCpowHolder::~CrossProcessCpowHolder() // recording or replaying, as they do not have a CPOW manager // and the message will also be received in the recording // process. - if (recordreplay::IsMiddleman()) + if (recordreplay::IsMiddleman()) { return; + } AutoJSAPI jsapi; - if (!jsapi.Init(xpc::PrivilegedJunkScope())) + if (!jsapi.Init(xpc::PrivilegedJunkScope())) { return; + } JSContext* cx = jsapi.cx(); JS::Rooted cpows(cx); js_->Unwrap(cx, cpows_, &cpows); @@ -681,8 +721,9 @@ CrossProcessCpowHolder::ToObject(JSContext* cx, JS::MutableHandleObject objp) { unwrapped_ = true; - if (!cpows_.Length()) + if (!cpows_.Length()) { return true; + } return js_->Unwrap(cx, cpows_, objp); } @@ -696,20 +737,23 @@ JavaScriptShared::Unwrap(JSContext* cx, const InfallibleTArray& aCpow objp.set(nullptr); - if (!aCpows.Length()) + if (!aCpows.Length()) { return true; + } RootedObject obj(cx, JS_NewPlainObject(cx)); - if (!obj) + if (!obj) { return false; + } RootedValue v(cx); RootedString str(cx); for (size_t i = 0; i < aCpows.Length(); i++) { const nsString& name = aCpows[i].name(); - if (!fromVariant(cx, aCpows[i].value(), &v)) + if (!fromVariant(cx, aCpows[i].value(), &v)) { return false; + } if (!JS_DefineUCProperty(cx, obj, @@ -729,12 +773,14 @@ JavaScriptShared::Unwrap(JSContext* cx, const InfallibleTArray& aCpow bool JavaScriptShared::Wrap(JSContext* cx, HandleObject aObj, InfallibleTArray* outCpows) { - if (!aObj) + if (!aObj) { return true; + } Rooted ids(cx, IdVector(cx)); - if (!JS_Enumerate(cx, aObj, &ids)) + if (!JS_Enumerate(cx, aObj, &ids)) { return false; + } RootedId id(cx); RootedValue v(cx); @@ -742,15 +788,18 @@ JavaScriptShared::Wrap(JSContext* cx, HandleObject aObj, InfallibleTArrayAppendElement(CpowEntry(str, var)); } diff --git a/js/ipc/JavaScriptShared.h b/js/ipc/JavaScriptShared.h index 20a43aca00df..8482a20a4aa9 100644 --- a/js/ipc/JavaScriptShared.h +++ b/js/ipc/JavaScriptShared.h @@ -29,8 +29,9 @@ class ObjectId { explicit ObjectId(uint64_t serialNumber, bool hasXrayWaiver) : serialNumber_(serialNumber), hasXrayWaiver_(hasXrayWaiver) { - if (isInvalidSerialNumber(serialNumber)) + if (isInvalidSerialNumber(serialNumber)) { MOZ_CRASH("Bad CPOW Id"); + } } bool operator==(const ObjectId& other) const { diff --git a/js/ipc/WrapperAnswer.cpp b/js/ipc/WrapperAnswer.cpp index 682f045d3cd9..2005bda4174c 100644 --- a/js/ipc/WrapperAnswer.cpp +++ b/js/ipc/WrapperAnswer.cpp @@ -35,8 +35,9 @@ MaybeForceDebugGC() static bool sEnvVarInitialized = false; static bool sDebugGCs = false; - if (!sEnvVarInitialized) + if (!sEnvVarInitialized) { sDebugGCs = !!PR_GetEnv("MOZ_DEBUG_DEAD_CPOWS"); + } if (sDebugGCs) { JSContext* cx = XPCJSContext::Get()->Context(); @@ -58,11 +59,13 @@ WrapperAnswer::fail(AutoJSAPI& jsapi, ReturnStatus* rs) JSContext* cx = jsapi.cx(); RootedValue exn(cx); - if (!jsapi.HasException()) + if (!jsapi.HasException()) { return true; + } - if (!jsapi.StealException(&exn)) + if (!jsapi.StealException(&exn)) { return true; + } // If this fails, we still don't want to exit. Just return an invalid // exception. @@ -98,23 +101,27 @@ WrapperAnswer::deadCPOW(AutoJSAPI& jsapi, ReturnStatus* rs) bool WrapperAnswer::RecvPreventExtensions(const ObjectId& objId, ReturnStatus* rs) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } ObjectOpResult success; - if (!JS_PreventExtensions(cx, obj, success)) + if (!JS_PreventExtensions(cx, obj, success)) { return fail(jsapi, rs); + } LOG("%s.preventExtensions()", ReceiverObj(objId)); return ok(rs, success); @@ -134,33 +141,39 @@ bool WrapperAnswer::RecvGetOwnPropertyDescriptor(const ObjectId& objId, const JSIDVariant& idVar, ReturnStatus* rs, PPropertyDescriptor* out) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); EmptyDesc(out); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("%s.getOwnPropertyDescriptor(%s)", ReceiverObj(objId), Identifier(idVar)); RootedId id(cx); - if (!fromJSIDVariant(cx, idVar, &id)) + if (!fromJSIDVariant(cx, idVar, &id)) { return fail(jsapi, rs); + } Rooted desc(cx); - if (!JS_GetOwnPropertyDescriptorById(cx, obj, id, &desc)) + if (!JS_GetOwnPropertyDescriptorById(cx, obj, id, &desc)) { return fail(jsapi, rs); + } - if (!fromDescriptor(cx, desc, out)) + if (!fromDescriptor(cx, desc, out)) { return fail(jsapi, rs); + } return ok(rs); } @@ -169,62 +182,73 @@ bool WrapperAnswer::RecvDefineProperty(const ObjectId& objId, const JSIDVariant& idVar, const PPropertyDescriptor& descriptor, ReturnStatus* rs) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("define %s[%s]", ReceiverObj(objId), Identifier(idVar)); RootedId id(cx); - if (!fromJSIDVariant(cx, idVar, &id)) + if (!fromJSIDVariant(cx, idVar, &id)) { return fail(jsapi, rs); + } Rooted desc(cx); - if (!toDescriptor(cx, descriptor, &desc)) + if (!toDescriptor(cx, descriptor, &desc)) { return fail(jsapi, rs); + } ObjectOpResult success; - if (!JS_DefinePropertyById(cx, obj, id, desc, success)) + if (!JS_DefinePropertyById(cx, obj, id, desc, success)) { return fail(jsapi, rs); + } return ok(rs, success); } bool WrapperAnswer::RecvDelete(const ObjectId& objId, const JSIDVariant& idVar, ReturnStatus* rs) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("delete %s[%s]", ReceiverObj(objId), Identifier(idVar)); RootedId id(cx); - if (!fromJSIDVariant(cx, idVar, &id)) + if (!fromJSIDVariant(cx, idVar, &id)) { return fail(jsapi, rs); + } ObjectOpResult success; - if (!JS_DeletePropertyById(cx, obj, id, success)) + if (!JS_DeletePropertyById(cx, obj, id, success)) { return fail(jsapi, rs); + } return ok(rs, success); } @@ -232,29 +256,34 @@ bool WrapperAnswer::RecvHas(const ObjectId& objId, const JSIDVariant& idVar, ReturnStatus* rs, bool* foundp) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); *foundp = false; RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("%s.has(%s)", ReceiverObj(objId), Identifier(idVar)); RootedId id(cx); - if (!fromJSIDVariant(cx, idVar, &id)) + if (!fromJSIDVariant(cx, idVar, &id)) { return fail(jsapi, rs); + } - if (!JS_HasPropertyById(cx, obj, id, foundp)) + if (!JS_HasPropertyById(cx, obj, id, foundp)) { return fail(jsapi, rs); + } return ok(rs); } @@ -262,29 +291,34 @@ bool WrapperAnswer::RecvHasOwn(const ObjectId& objId, const JSIDVariant& idVar, ReturnStatus* rs, bool* foundp) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); *foundp = false; RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("%s.hasOwn(%s)", ReceiverObj(objId), Identifier(idVar)); RootedId id(cx); - if (!fromJSIDVariant(cx, idVar, &id)) + if (!fromJSIDVariant(cx, idVar, &id)) { return fail(jsapi, rs); + } - if (!JS_HasOwnPropertyById(cx, obj, id, foundp)) + if (!JS_HasOwnPropertyById(cx, obj, id, foundp)) { return fail(jsapi, rs); + } return ok(rs); } @@ -292,8 +326,9 @@ bool WrapperAnswer::RecvGet(const ObjectId& objId, const JSVariant& receiverVar, const JSIDVariant& idVar, ReturnStatus* rs, JSVariant* result) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); @@ -307,23 +342,28 @@ WrapperAnswer::RecvGet(const ObjectId& objId, const JSVariant& receiverVar, *result = UndefinedVariant(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(aes, rs); + } RootedValue receiver(cx); - if (!fromVariant(cx, receiverVar, &receiver)) + if (!fromVariant(cx, receiverVar, &receiver)) { return fail(aes, rs); + } RootedId id(cx); - if (!fromJSIDVariant(cx, idVar, &id)) + if (!fromJSIDVariant(cx, idVar, &id)) { return fail(aes, rs); + } JS::RootedValue val(cx); - if (!JS_ForwardGetPropertyTo(cx, obj, id, receiver, &val)) + if (!JS_ForwardGetPropertyTo(cx, obj, id, receiver, &val)) { return fail(aes, rs); + } - if (!toVariant(cx, val, result)) + if (!toVariant(cx, val, result)) { return fail(aes, rs); + } LOG("get %s.%s = %s", ReceiverObj(objId), Identifier(idVar), OutVariant(*result)); @@ -334,8 +374,9 @@ bool WrapperAnswer::RecvSet(const ObjectId& objId, const JSIDVariant& idVar, const JSVariant& value, const JSVariant& receiverVar, ReturnStatus* rs) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); @@ -345,26 +386,31 @@ WrapperAnswer::RecvSet(const ObjectId& objId, const JSIDVariant& idVar, const JS JSContext* cx = aes.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(aes, rs); + } LOG("set %s[%s] = %s", ReceiverObj(objId), Identifier(idVar), InVariant(value)); RootedId id(cx); - if (!fromJSIDVariant(cx, idVar, &id)) + if (!fromJSIDVariant(cx, idVar, &id)) { return fail(aes, rs); + } RootedValue val(cx); - if (!fromVariant(cx, value, &val)) + if (!fromVariant(cx, value, &val)) { return fail(aes, rs); + } RootedValue receiver(cx); - if (!fromVariant(cx, receiverVar, &receiver)) + if (!fromVariant(cx, receiverVar, &receiver)) { return fail(aes, rs); + } ObjectOpResult result; - if (!JS_ForwardSetPropertyTo(cx, obj, id, val, receiver, result)) + if (!JS_ForwardSetPropertyTo(cx, obj, id, val, receiver, result)) { return fail(aes, rs); + } return ok(rs, result); } @@ -372,26 +418,30 @@ WrapperAnswer::RecvSet(const ObjectId& objId, const JSIDVariant& idVar, const JS bool WrapperAnswer::RecvIsExtensible(const ObjectId& objId, ReturnStatus* rs, bool* result) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); *result = false; RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("%s.isExtensible()", ReceiverObj(objId)); bool extensible; - if (!JS_IsExtensible(cx, obj, &extensible)) + if (!JS_IsExtensible(cx, obj, &extensible)) { return fail(jsapi, rs); + } *result = !!extensible; return ok(rs); @@ -405,8 +455,9 @@ WrapperAnswer::RecvCallOrConstruct(const ObjectId& objId, JSVariant* result, nsTArray* outparams) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); @@ -419,14 +470,16 @@ WrapperAnswer::RecvCallOrConstruct(const ObjectId& objId, *result = UndefinedVariant(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(aes, rs); + } MOZ_ASSERT(argv.Length() >= 2); RootedValue objv(cx); - if (!fromVariant(cx, argv[0], &objv)) + if (!fromVariant(cx, argv[0], &objv)) { return fail(aes, rs); + } *result = JSVariant(UndefinedVariant()); @@ -436,18 +489,23 @@ WrapperAnswer::RecvCallOrConstruct(const ObjectId& objId, if (argv[i].type() == JSParam::Tvoid_t) { // This is an outparam. RootedObject obj(cx, xpc::NewOutObject(cx)); - if (!obj) + if (!obj) { return fail(aes, rs); - if (!outobjects.append(ObjectValue(*obj))) + } + if (!outobjects.append(ObjectValue(*obj))) { return fail(aes, rs); - if (!vals.append(ObjectValue(*obj))) + } + if (!vals.append(ObjectValue(*obj))) { return fail(aes, rs); + } } else { RootedValue v(cx); - if (!fromVariant(cx, argv[i].get_JSVariant(), &v)) + if (!fromVariant(cx, argv[i].get_JSVariant(), &v)) { return fail(aes, rs); - if (!vals.append(v)) + } + if (!vals.append(v)) { return fail(aes, rs); + } } } @@ -456,8 +514,9 @@ WrapperAnswer::RecvCallOrConstruct(const ObjectId& objId, HandleValueArray args = HandleValueArray::subarray(vals, 2, vals.length() - 2); if (construct) { RootedObject obj(cx); - if (!JS::Construct(cx, vals[0], args, &obj)) + if (!JS::Construct(cx, vals[0], args, &obj)) { return fail(aes, rs); + } rval.setObject(*obj); } else { if(!JS::Call(cx, vals[1], vals[0], args, &rval)) @@ -465,12 +524,14 @@ WrapperAnswer::RecvCallOrConstruct(const ObjectId& objId, } } - if (!toVariant(cx, rval, result)) + if (!toVariant(cx, rval, result)) { return fail(aes, rs); + } // Prefill everything with a dummy jsval. - for (size_t i = 0; i < outobjects.length(); i++) + for (size_t i = 0; i < outobjects.length(); i++) { outparams->AppendElement(JSParam(void_t())); + } // Go through each argument that was an outparam, retrieve the "value" // field, and add it to a temporary list. We need to do this separately @@ -482,21 +543,24 @@ WrapperAnswer::RecvCallOrConstruct(const ObjectId& objId, RootedValue v(cx); bool found; if (JS_HasProperty(cx, obj, "value", &found)) { - if (!JS_GetProperty(cx, obj, "value", &v)) + if (!JS_GetProperty(cx, obj, "value", &v)) { return fail(aes, rs); + } } else { v = UndefinedValue(); } - if (!vals.append(v)) + if (!vals.append(v)) { return fail(aes, rs); + } } // Copy the outparams. If any outparam is already set to a void_t, we // treat this as the outparam never having been set. for (size_t i = 0; i < vals.length(); i++) { JSVariant variant; - if (!toVariant(cx, vals[i], &variant)) + if (!toVariant(cx, vals[i], &variant)) { return fail(aes, rs); + } outparams->ReplaceElementAt(i, JSParam(variant)); } @@ -508,28 +572,33 @@ WrapperAnswer::RecvCallOrConstruct(const ObjectId& objId, bool WrapperAnswer::RecvHasInstance(const ObjectId& objId, const JSVariant& vVar, ReturnStatus* rs, bool* bp) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("%s.hasInstance(%s)", ReceiverObj(objId), InVariant(vVar)); RootedValue val(cx); - if (!fromVariant(cx, vVar, &val)) + if (!fromVariant(cx, vVar, &val)) { return fail(jsapi, rs); + } - if (!JS_HasInstance(cx, obj, val, bp)) + if (!JS_HasInstance(cx, obj, val, bp)) { return fail(jsapi, rs); + } return ok(rs); } @@ -538,27 +607,31 @@ bool WrapperAnswer::RecvGetBuiltinClass(const ObjectId& objId, ReturnStatus* rs, uint32_t* classValue) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); *classValue = uint32_t(js::ESClass::Other); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("%s.getBuiltinClass()", ReceiverObj(objId)); js::ESClass cls; - if (!js::GetBuiltinClass(cx, obj, &cls)) + if (!js::GetBuiltinClass(cx, obj, &cls)) { return fail(jsapi, rs); + } *classValue = uint32_t(cls); return ok(rs); @@ -568,27 +641,31 @@ bool WrapperAnswer::RecvIsArray(const ObjectId& objId, ReturnStatus* rs, uint32_t* ans) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); *ans = uint32_t(IsArrayAnswer::NotArray); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("%s.isArray()", ReceiverObj(objId)); IsArrayAnswer answer; - if (!JS::IsArray(cx, obj, &answer)) + if (!JS::IsArray(cx, obj, &answer)) { return fail(jsapi, rs); + } *ans = uint32_t(answer); return ok(rs); @@ -597,14 +674,16 @@ WrapperAnswer::RecvIsArray(const ObjectId& objId, ReturnStatus* rs, bool WrapperAnswer::RecvClassName(const ObjectId& objId, nsCString* name) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); @@ -623,28 +702,33 @@ WrapperAnswer::RecvClassName(const ObjectId& objId, nsCString* name) bool WrapperAnswer::RecvGetPrototype(const ObjectId& objId, ReturnStatus* rs, ObjectOrNullVariant* result) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); *result = NullVariant(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } JS::RootedObject proto(cx); - if (!JS_GetPrototype(cx, obj, &proto)) + if (!JS_GetPrototype(cx, obj, &proto)) { return fail(jsapi, rs); + } - if (!toObjectOrNullVariant(cx, proto, result)) + if (!toObjectOrNullVariant(cx, proto, result)) { return fail(jsapi, rs); + } LOG("getPrototype(%s)", ReceiverObj(objId)); @@ -655,8 +739,9 @@ bool WrapperAnswer::RecvGetPrototypeIfOrdinary(const ObjectId& objId, ReturnStatus* rs, bool* isOrdinary, ObjectOrNullVariant* result) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); @@ -664,20 +749,24 @@ WrapperAnswer::RecvGetPrototypeIfOrdinary(const ObjectId& objId, ReturnStatus* r *isOrdinary = false; AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } JS::RootedObject proto(cx); - if (!JS_GetPrototypeIfOrdinary(cx, obj, isOrdinary, &proto)) + if (!JS_GetPrototypeIfOrdinary(cx, obj, isOrdinary, &proto)) { return fail(jsapi, rs); + } - if (!toObjectOrNullVariant(cx, proto, result)) + if (!toObjectOrNullVariant(cx, proto, result)) { return fail(jsapi, rs); + } LOG("getPrototypeIfOrdinary(%s)", ReceiverObj(objId)); @@ -688,26 +777,31 @@ bool WrapperAnswer::RecvRegExpToShared(const ObjectId& objId, ReturnStatus* rs, nsString* source, uint32_t* flags) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } RootedString sourceJSStr(cx, JS_GetRegExpSource(cx, obj)); - if (!sourceJSStr) + if (!sourceJSStr) { return fail(jsapi, rs); + } nsAutoJSString sourceStr; - if (!sourceStr.init(cx, sourceJSStr)) + if (!sourceStr.init(cx, sourceJSStr)) { return fail(jsapi, rs); + } source->Assign(sourceStr); *flags = JS_GetRegExpFlags(cx, obj); @@ -719,30 +813,35 @@ bool WrapperAnswer::RecvGetPropertyKeys(const ObjectId& objId, const uint32_t& flags, ReturnStatus* rs, nsTArray* ids) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("%s.getPropertyKeys()", ReceiverObj(objId)); AutoIdVector props(cx); - if (!js::GetPropertyKeys(cx, obj, flags, &props)) + if (!js::GetPropertyKeys(cx, obj, flags, &props)) { return fail(jsapi, rs); + } for (size_t i = 0; i < props.length(); i++) { JSIDVariant id; - if (!toJSIDVariant(cx, props[i], &id)) + if (!toJSIDVariant(cx, props[i], &id)) { return fail(jsapi, rs); + } ids->AppendElement(id); } @@ -754,21 +853,24 @@ bool WrapperAnswer::RecvInstanceOf(const ObjectId& objId, const JSIID& iid, ReturnStatus* rs, bool* instanceof) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); *instanceof = false; RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("%s.instanceOf()", ReceiverObj(objId)); @@ -776,8 +878,9 @@ WrapperAnswer::RecvInstanceOf(const ObjectId& objId, const JSIID& iid, ReturnSta ConvertID(iid, &nsiid); nsresult rv = xpc::HasInstance(cx, obj, &nsiid, instanceof); - if (rv != NS_OK) + if (rv != NS_OK) { return fail(jsapi, rs); + } return ok(rs); } @@ -786,26 +889,30 @@ bool WrapperAnswer::RecvDOMInstanceOf(const ObjectId& objId, const int& prototypeID, const int& depth, ReturnStatus* rs, bool* instanceof) { - if (!IsInAutomation()) + if (!IsInAutomation()) { return false; + } MaybeForceDebugGC(); AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) + if (NS_WARN_IF(!jsapi.Init(scopeForTargetObjects()))) { return false; + } JSContext* cx = jsapi.cx(); *instanceof = false; RootedObject obj(cx, findObjectById(cx, objId)); - if (!obj) + if (!obj) { return deadCPOW(jsapi, rs); + } LOG("%s.domInstanceOf()", ReceiverObj(objId)); bool tmp; - if (!mozilla::dom::InterfaceHasInstance(cx, prototypeID, depth, obj, &tmp)) + if (!mozilla::dom::InterfaceHasInstance(cx, prototypeID, depth, obj, &tmp)) { return fail(jsapi, rs); + } *instanceof = tmp; return ok(rs); diff --git a/js/ipc/WrapperOwner.cpp b/js/ipc/WrapperOwner.cpp index 82bfffd3a0bd..d3d6fc55eb0d 100644 --- a/js/ipc/WrapperOwner.cpp +++ b/js/ipc/WrapperOwner.cpp @@ -172,18 +172,21 @@ WrapperOwner::getOwnPropertyDescriptor(JSContext* cx, HandleObject proxy, Handle ObjectId objId = idOf(proxy); JSIDVariant idVar; - if (!toJSIDVariant(cx, id, &idVar)) + if (!toJSIDVariant(cx, id, &idVar)) { return false; + } ReturnStatus status; PPropertyDescriptor result; - if (!SendGetOwnPropertyDescriptor(objId, idVar, &status, &result)) + if (!SendGetOwnPropertyDescriptor(objId, idVar, &status, &result)) { return ipcfail(cx); + } LOG_STACK(); - if (!ok(cx, status)) + if (!ok(cx, status)) { return false; + } return toDescriptor(cx, result, desc); } @@ -204,16 +207,19 @@ WrapperOwner::defineProperty(JSContext* cx, HandleObject proxy, HandleId id, ObjectId objId = idOf(proxy); JSIDVariant idVar; - if (!toJSIDVariant(cx, id, &idVar)) + if (!toJSIDVariant(cx, id, &idVar)) { return false; + } PPropertyDescriptor descriptor; - if (!fromDescriptor(cx, desc, &descriptor)) + if (!fromDescriptor(cx, desc, &descriptor)) { return false; + } ReturnStatus status; - if (!SendDefineProperty(objId, idVar, descriptor, &status)) + if (!SendDefineProperty(objId, idVar, descriptor, &status)) { return ipcfail(cx); + } LOG_STACK(); @@ -246,12 +252,14 @@ WrapperOwner::delete_(JSContext* cx, HandleObject proxy, HandleId id, ObjectOpRe ObjectId objId = idOf(proxy); JSIDVariant idVar; - if (!toJSIDVariant(cx, id, &idVar)) + if (!toJSIDVariant(cx, id, &idVar)) { return false; + } ReturnStatus status; - if (!SendDelete(objId, idVar, &status)) + if (!SendDelete(objId, idVar, &status)) { return ipcfail(cx); + } LOG_STACK(); @@ -279,12 +287,14 @@ WrapperOwner::has(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) ObjectId objId = idOf(proxy); JSIDVariant idVar; - if (!toJSIDVariant(cx, id, &idVar)) + if (!toJSIDVariant(cx, id, &idVar)) { return false; + } ReturnStatus status; - if (!SendHas(objId, idVar, &status, bp)) + if (!SendHas(objId, idVar, &status, bp)) { return ipcfail(cx); + } LOG_STACK(); @@ -303,12 +313,14 @@ WrapperOwner::hasOwn(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) ObjectId objId = idOf(proxy); JSIDVariant idVar; - if (!toJSIDVariant(cx, id, &idVar)) + if (!toJSIDVariant(cx, id, &idVar)) { return false; + } ReturnStatus status; - if (!SendHasOwn(objId, idVar, &status, bp)) + if (!SendHasOwn(objId, idVar, &status, bp)) { return ipcfail(cx); + } LOG_STACK(); @@ -341,8 +353,9 @@ CPOWToString(JSContext* cx, unsigned argc, Value* vp) CallArgs args = CallArgsFromVp(argc, vp); RootedObject callee(cx, &args.callee()); RootedValue cpowValue(cx); - if (!JS_GetProperty(cx, callee, "__cpow__", &cpowValue)) + if (!JS_GetProperty(cx, callee, "__cpow__", &cpowValue)) { return false; + } if (!cpowValue.isObject() || !IsCPOW(&cpowValue.toObject())) { JS_ReportErrorASCII(cx, "CPOWToString called on an incompatible object"); @@ -359,16 +372,19 @@ WrapperOwner::toString(JSContext* cx, HandleObject cpow, JS::CallArgs& args) // Ask the other side to call its toString method. Update the callee so that // it points to the CPOW and not to the synthesized CPOWToString function. args.setCallee(ObjectValue(*cpow)); - if (!callOrConstruct(cx, cpow, args, false)) + if (!callOrConstruct(cx, cpow, args, false)) { return false; + } - if (!args.rval().isString()) + if (!args.rval().isString()) { return true; + } RootedString cpowResult(cx, args.rval().toString()); nsAutoJSString toStringResult; - if (!toStringResult.init(cx, cpowResult)) + if (!toStringResult.init(cx, cpowResult)) { return false; + } // We don't want to wrap toString() results for things like the location // object, where toString() is supposed to return a URL and nothing else. @@ -382,8 +398,9 @@ WrapperOwner::toString(JSContext* cx, HandleObject cpow, JS::CallArgs& args) } JSString* str = JS_NewUCStringCopyN(cx, result.get(), result.Length()); - if (!str) + if (!str) { return false; + } args.rval().setString(str); return true; @@ -409,8 +426,9 @@ WrapperOwner::DOMQI(JSContext* cx, JS::HandleObject proxy, JS::CallArgs& args) } // Webidl-implemented DOM objects never have nsIClassInfo. - if (idptr->Equals(NS_GET_IID(nsIClassInfo))) + if (idptr->Equals(NS_GET_IID(nsIClassInfo))) { return Throw(cx, NS_ERROR_NO_INTERFACE); + } } } @@ -422,8 +440,9 @@ WrapperOwner::DOMQI(JSContext* cx, JS::HandleObject proxy, JS::CallArgs& args) // if we're called multiple times, but since we're transient, there's no // point right now. JS::Rooted propDesc(cx); - if (!JS_GetPropertyDescriptor(cx, proxy, "QueryInterface", &propDesc)) + if (!JS_GetPropertyDescriptor(cx, proxy, "QueryInterface", &propDesc)) { return false; + } if (!propDesc.value().isObject()) { MOZ_ASSERT_UNREACHABLE("We didn't get QueryInterface off a node"); @@ -439,12 +458,14 @@ WrapperOwner::get(JSContext* cx, HandleObject proxy, HandleValue receiver, ObjectId objId = idOf(proxy); JSVariant receiverVar; - if (!toVariant(cx, receiver, &receiverVar)) + if (!toVariant(cx, receiver, &receiverVar)) { return false; + } JSIDVariant idVar; - if (!toJSIDVariant(cx, id, &idVar)) + if (!toJSIDVariant(cx, id, &idVar)) { return false; + } AuxCPOWData* data = AuxCPOWDataOf(proxy); if (data->isDOMObject && @@ -455,8 +476,9 @@ WrapperOwner::get(JSContext* cx, HandleObject proxy, HandleValue receiver, // certain things about their implementation. RootedFunction qi(cx, JS_NewFunction(cx, CPOWDOMQI, 1, 0, "QueryInterface")); - if (!qi) + if (!qi) { return false; + } vp.set(ObjectValue(*JS_GetFunctionObject(qi))); return true; @@ -464,28 +486,33 @@ WrapperOwner::get(JSContext* cx, HandleObject proxy, HandleValue receiver, JSVariant val; ReturnStatus status; - if (!SendGet(objId, receiverVar, idVar, &status, &val)) + if (!SendGet(objId, receiverVar, idVar, &status, &val)) { return ipcfail(cx); + } LOG_STACK(); - if (!ok(cx, status)) + if (!ok(cx, status)) { return false; + } - if (!fromVariant(cx, val, vp)) + if (!fromVariant(cx, val, vp)) { return false; + } if (idVar.type() == JSIDVariant::TnsString && idVar.get_nsString().EqualsLiteral("toString")) { RootedFunction toString(cx, JS_NewFunction(cx, CPOWToString, 0, 0, "toString")); - if (!toString) + if (!toString) { return false; + } RootedObject toStringObj(cx, JS_GetFunctionObject(toString)); - if (!JS_DefineProperty(cx, toStringObj, "__cpow__", vp, JSPROP_PERMANENT | JSPROP_READONLY)) + if (!JS_DefineProperty(cx, toStringObj, "__cpow__", vp, JSPROP_PERMANENT | JSPROP_READONLY)) { return false; + } vp.set(ObjectValue(*toStringObj)); } @@ -507,20 +534,24 @@ WrapperOwner::set(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::Ha ObjectId objId = idOf(proxy); JSIDVariant idVar; - if (!toJSIDVariant(cx, id, &idVar)) + if (!toJSIDVariant(cx, id, &idVar)) { return false; + } JSVariant val; - if (!toVariant(cx, v, &val)) + if (!toVariant(cx, v, &val)) { return false; + } JSVariant receiverVar; - if (!toVariant(cx, receiver, &receiverVar)) + if (!toVariant(cx, receiver, &receiverVar)) { return false; + } ReturnStatus status; - if (!SendSet(objId, idVar, val, receiverVar, &status)) + if (!SendSet(objId, idVar, val, receiverVar, &status)) { return ipcfail(cx); + } LOG_STACK(); @@ -552,8 +583,9 @@ WrapperOwner::preventExtensions(JSContext* cx, HandleObject proxy, ObjectOpResul ObjectId objId = idOf(proxy); ReturnStatus status; - if (!SendPreventExtensions(objId, &status)) + if (!SendPreventExtensions(objId, &status)) { return ipcfail(cx); + } LOG_STACK(); @@ -572,8 +604,9 @@ WrapperOwner::isExtensible(JSContext* cx, HandleObject proxy, bool* extensible) ObjectId objId = idOf(proxy); ReturnStatus status; - if (!SendIsExtensible(objId, &status, extensible)) + if (!SendIsExtensible(objId, &status, extensible)) { return ipcfail(cx); + } LOG_STACK(); @@ -605,66 +638,77 @@ WrapperOwner::callOrConstruct(JSContext* cx, HandleObject proxy, const CallArgs& for (size_t i = 0; i < args.length() + 2; i++) { // The |this| value for constructors is a magic value that we won't be // able to convert, so skip it. - if (i == 1 && construct) + if (i == 1 && construct) { v = UndefinedValue(); - else + } else { v = args.base()[i]; + } if (v.isObject()) { RootedObject obj(cx, &v.toObject()); if (xpc::IsOutObject(cx, obj)) { // Make sure it is not an in-out object. bool found; - if (!JS_HasProperty(cx, obj, "value", &found)) + if (!JS_HasProperty(cx, obj, "value", &found)) { return false; + } if (found) { JS_ReportErrorASCII(cx, "in-out objects cannot be sent via CPOWs yet"); return false; } vals.AppendElement(JSParam(void_t())); - if (!outobjects.append(ObjectValue(*obj))) + if (!outobjects.append(ObjectValue(*obj))) { return false; + } continue; } } JSVariant val; - if (!toVariant(cx, v, &val)) + if (!toVariant(cx, v, &val)) { return false; + } vals.AppendElement(JSParam(val)); } JSVariant result; ReturnStatus status; InfallibleTArray outparams; - if (!SendCallOrConstruct(objId, vals, construct, &status, &result, &outparams)) + if (!SendCallOrConstruct(objId, vals, construct, &status, &result, &outparams)) { return ipcfail(cx); + } LOG_STACK(); - if (!ok(cx, status)) + if (!ok(cx, status)) { return false; + } - if (outparams.Length() != outobjects.length()) + if (outparams.Length() != outobjects.length()) { return ipcfail(cx); + } RootedObject obj(cx); for (size_t i = 0; i < outparams.Length(); i++) { // Don't bother doing anything for outparams that weren't set. - if (outparams[i].type() == JSParam::Tvoid_t) + if (outparams[i].type() == JSParam::Tvoid_t) { continue; + } // Take the value the child process returned, and set it on the XPC // object. - if (!fromVariant(cx, outparams[i], &v)) + if (!fromVariant(cx, outparams[i], &v)) { return false; + } obj = &outobjects[i].toObject(); - if (!JS_SetProperty(cx, obj, "value", v)) + if (!JS_SetProperty(cx, obj, "value", v)) { return false; + } } - if (!fromVariant(cx, result, args.rval())) + if (!fromVariant(cx, result, args.rval())) { return false; + } return true; } @@ -681,12 +725,14 @@ WrapperOwner::hasInstance(JSContext* cx, HandleObject proxy, MutableHandleValue ObjectId objId = idOf(proxy); JSVariant vVar; - if (!toVariant(cx, v, &vVar)) + if (!toVariant(cx, v, &vVar)) { return false; + } ReturnStatus status; - if (!SendHasInstance(objId, vVar, &status, bp)) + if (!SendHasInstance(objId, vVar, &status, bp)) { return ipcfail(cx); + } LOG_STACK(); @@ -706,8 +752,9 @@ WrapperOwner::getBuiltinClass(JSContext* cx, HandleObject proxy, ESClass* cls) uint32_t classValue = uint32_t(ESClass::Other); ReturnStatus status; - if (!SendGetBuiltinClass(objId, &status, &classValue)) + if (!SendGetBuiltinClass(objId, &status, &classValue)) { return ipcfail(cx); + } *cls = ESClass(classValue); LOG_STACK(); @@ -729,8 +776,9 @@ WrapperOwner::isArray(JSContext* cx, HandleObject proxy, IsArrayAnswer* answer) uint32_t ans; ReturnStatus status; - if (!SendIsArray(objId, &status, &ans)) + if (!SendIsArray(objId, &status, &ans)) { return ipcfail(cx); + } LOG_STACK(); @@ -746,8 +794,9 @@ const char* CPOWProxyHandler::className(JSContext* cx, HandleObject proxy) const { WrapperOwner* parent = OwnerOf(proxy); - if (!parent->active()) + if (!parent->active()) { return ""; + } return parent->className(cx, proxy); } @@ -758,8 +807,9 @@ WrapperOwner::className(JSContext* cx, HandleObject proxy) if (data->className.IsEmpty()) { ObjectId objId = idOf(proxy); - if (!SendClassName(objId, &data->className)) + if (!SendClassName(objId, &data->className)) { return ""; + } LOG_STACK(); } @@ -780,13 +830,15 @@ WrapperOwner::getPrototype(JSContext* cx, HandleObject proxy, MutableHandleObjec ObjectOrNullVariant val; ReturnStatus status; - if (!SendGetPrototype(objId, &status, &val)) + if (!SendGetPrototype(objId, &status, &val)) { return ipcfail(cx); + } LOG_STACK(); - if (!ok(cx, status)) + if (!ok(cx, status)) { return false; + } objp.set(fromObjectOrNullVariant(cx, val)); @@ -808,13 +860,15 @@ WrapperOwner::getPrototypeIfOrdinary(JSContext* cx, HandleObject proxy, bool* is ObjectOrNullVariant val; ReturnStatus status; - if (!SendGetPrototypeIfOrdinary(objId, &status, isOrdinary, &val)) + if (!SendGetPrototypeIfOrdinary(objId, &status, isOrdinary, &val)) { return ipcfail(cx); + } LOG_STACK(); - if (!ok(cx, status)) + if (!ok(cx, status)) { return false; + } objp.set(fromObjectOrNullVariant(cx, val)); @@ -841,13 +895,15 @@ WrapperOwner::regexp_toShared(JSContext* cx, HandleObject proxy) } LOG_STACK(); - if (!ok(cx, status)) + if (!ok(cx, status)) { return nullptr; + } RootedObject regexp(cx); regexp = JS_NewUCRegExpObject(cx, source.get(), source.Length(), flags); - if (!regexp) + if (!regexp) { return nullptr; + } return js::RegExpToSharedNonInline(cx, regexp); } @@ -859,8 +915,9 @@ CPOWProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const OwnerOf(proxy)->drop(proxy); - if (aux) + if (aux) { delete aux; + } } size_t @@ -890,11 +947,13 @@ WrapperOwner::drop(JSObject* obj) // The association may have already been swept from the table but if it's // there then remove it. ObjectId objId = idOfUnchecked(obj); - if (cpows_.findPreserveColor(objId) == obj) + if (cpows_.findPreserveColor(objId) == obj) { cpows_.remove(objId); + } - if (active()) + if (active()) { Unused << SendDropObject(objId); + } decref(); } @@ -913,20 +972,24 @@ WrapperOwner::getPropertyKeys(JSContext* cx, HandleObject proxy, uint32_t flags, ReturnStatus status; InfallibleTArray ids; - if (!SendGetPropertyKeys(objId, flags, &status, &ids)) + if (!SendGetPropertyKeys(objId, flags, &status, &ids)) { return ipcfail(cx); + } LOG_STACK(); - if (!ok(cx, status)) + if (!ok(cx, status)) { return false; + } for (size_t i = 0; i < ids.Length(); i++) { RootedId id(cx); - if (!fromJSIDVariant(cx, ids[i], &id)) + if (!fromJSIDVariant(cx, ids[i], &id)) { return false; - if (!props.append(id)) + } + if (!props.append(id)) { return false; + } } return true; @@ -945,8 +1008,9 @@ bool IsWrappedCPOW(JSObject* obj) { JSObject* unwrapped = js::UncheckedUnwrap(obj, true); - if (!unwrapped) + if (!unwrapped) { return false; + } return IsCPOW(unwrapped); } @@ -957,16 +1021,18 @@ GetWrappedCPOWTag(JSObject* obj, nsACString& out) MOZ_ASSERT(IsCPOW(unwrapped)); AuxCPOWData* aux = AuxCPOWDataOf(unwrapped); - if (aux) + if (aux) { out = aux->objectTag; + } } nsresult InstanceOf(JSObject* proxy, const nsID* id, bool* bp) { WrapperOwner* parent = OwnerOf(proxy); - if (!parent->active()) + if (!parent->active()) { return NS_ERROR_UNEXPECTED; + } return parent->instanceOf(proxy, id, bp); } @@ -989,11 +1055,13 @@ WrapperOwner::instanceOf(JSObject* obj, const nsID* id, bool* bp) ConvertID(*id, &iid); ReturnStatus status; - if (!SendInstanceOf(objId, iid, &status, bp)) + if (!SendInstanceOf(objId, iid, &status, bp)) { return NS_ERROR_UNEXPECTED; + } - if (status.type() != ReturnStatus::TReturnSuccess) + if (status.type() != ReturnStatus::TReturnSuccess) { return NS_ERROR_UNEXPECTED; + } return NS_OK; } @@ -1004,8 +1072,9 @@ WrapperOwner::domInstanceOf(JSContext* cx, JSObject* obj, int prototypeID, int d ObjectId objId = idOf(obj); ReturnStatus status; - if (!SendDOMInstanceOf(objId, prototypeID, depth, &status, bp)) + if (!SendDOMInstanceOf(objId, prototypeID, depth, &status, bp)) { return ipcfail(cx); + } LOG_STACK(); @@ -1032,8 +1101,9 @@ WrapperOwner::ipcfail(JSContext* cx) bool WrapperOwner::ok(JSContext* cx, const ReturnStatus& status) { - if (status.type() == ReturnStatus::TReturnSuccess) + if (status.type() == ReturnStatus::TReturnSuccess) { return true; + } if (status.type() == ReturnStatus::TReturnDeadCPOW) { JS_ReportErrorASCII(cx, "operation not possible on dead CPOW"); @@ -1041,8 +1111,9 @@ WrapperOwner::ok(JSContext* cx, const ReturnStatus& status) } RootedValue exn(cx); - if (!fromVariant(cx, status.get_ReturnException().exn(), &exn)) + if (!fromVariant(cx, status.get_ReturnException().exn(), &exn)) { return false; + } JS_SetPendingException(cx, exn); return false; @@ -1051,10 +1122,12 @@ WrapperOwner::ok(JSContext* cx, const ReturnStatus& status) bool WrapperOwner::ok(JSContext* cx, const ReturnStatus& status, ObjectOpResult& result) { - if (status.type() == ReturnStatus::TReturnObjectOpResult) + if (status.type() == ReturnStatus::TReturnObjectOpResult) { return result.fail(status.get_ReturnObjectOpResult().code()); - if (!ok(cx, status)) + } + if (!ok(cx, status)) { return false; + } return result.succeed(); } @@ -1066,12 +1139,14 @@ GetRemoteObjectTag(JS::Handle obj) { if (nsCOMPtr supports = xpc::UnwrapReflectorToISupports(obj)) { nsCOMPtr treeItem(do_QueryInterface(supports)); - if (treeItem) + if (treeItem) { return NS_LITERAL_CSTRING("ContentDocShellTreeItem"); + } nsCOMPtr doc(do_QueryInterface(supports)); - if (doc) + if (doc) { return NS_LITERAL_CSTRING("ContentDocument"); + } } return NS_LITERAL_CSTRING("generic"); @@ -1114,14 +1189,17 @@ WrapperOwner::toObjectVariant(JSContext* cx, JSObject* objArg, ObjectVariant* ob // Need to call PreserveWrapper on |obj| in case it's a reflector. // FIXME: What if it's an XPCWrappedNative? - if (mozilla::dom::IsDOMObject(obj)) + if (mozilla::dom::IsDOMObject(obj)) { mozilla::dom::TryPreserveWrapper(obj); + } id = ObjectId(nextSerialNumber_++, waiveXray); - if (!objects_.add(id, obj)) + if (!objects_.add(id, obj)) { return false; - if (!objectIdMap(waiveXray).add(cx, obj, id)) + } + if (!objectIdMap(waiveXray).add(cx, obj, id)) { return false; + } *objVarp = MakeRemoteObject(cx, id, obj); return true; @@ -1162,11 +1240,13 @@ WrapperOwner::fromRemoteObjectVariant(JSContext* cx, const RemoteObject& objVar) v, nullptr, options); - if (!obj) + if (!obj) { return nullptr; + } - if (!cpows_.add(objId, obj)) + if (!cpows_.add(objId, obj)) { return nullptr; + } nextCPOWNumber_ = objId.serialNumber() + 1; @@ -1183,8 +1263,9 @@ WrapperOwner::fromRemoteObjectVariant(JSContext* cx, const RemoteObject& objVar) SetProxyReservedSlot(obj, 1, PrivateValue(aux)); } - if (!JS_WrapObject(cx, &obj)) + if (!JS_WrapObject(cx, &obj)) { return nullptr; + } return obj; } @@ -1196,9 +1277,11 @@ WrapperOwner::fromLocalObjectVariant(JSContext* cx, const LocalObject& objVar) return nullptr; } Rooted obj(cx, findObjectById(cx, id.value())); - if (!obj) + if (!obj) { return nullptr; - if (!JS_WrapObject(cx, &obj)) + } + if (!JS_WrapObject(cx, &obj)) { return nullptr; + } return obj; }