Bug 1850865: Add helpers for stringifying protocol sides. r=ipc-reviewers,nika

Depends on D187167

Differential Revision: https://phabricator.services.mozilla.com/D187213
This commit is contained in:
Jim Blandy 2023-09-05 18:09:30 +00:00
Родитель 7262779e1f
Коммит ead739b02b
6 изменённых файлов: 29 добавлений и 31 удалений

Просмотреть файл

@ -54,8 +54,9 @@ already_AddRefed<JSActor> JSActorManager::GetActor(JSContext* aCx,
return nullptr;
}
bool isParent = nativeActor->GetSide() == mozilla::ipc::ParentSide;
auto& side = isParent ? protocol->Parent() : protocol->Child();
auto& side = nativeActor->GetSide() == mozilla::ipc::ParentSide
? protocol->Parent()
: protocol->Child();
// We're about to construct the actor, so make sure we're in the JSM realm
// while importing etc.
@ -86,7 +87,7 @@ already_AddRefed<JSActor> JSActorManager::GetActor(JSContext* aCx,
// Load the specific property from our module.
JS::Rooted<JS::Value> ctor(aCx);
nsAutoCString ctorName(aName);
ctorName.Append(isParent ? "Parent"_ns : "Child"_ns);
ctorName.Append(StringFromIPCSide(nativeActor->GetSide()));
if (!JS_GetProperty(aCx, exports, ctorName.get(), &ctor)) {
aRv.NoteJSContextException(aCx);
return nullptr;

Просмотреть файл

@ -561,17 +561,6 @@ int MessageChannel::DispatchingSyncMessageNestedLevel() const {
: 0;
}
static const char* StringFromIPCSide(Side side) {
switch (side) {
case ChildSide:
return "Child";
case ParentSide:
return "Parent";
default:
return "Unknown";
}
}
static void PrintErrorMessage(Side side, const char* channelName,
const char* msg) {
printf_stderr("\n###!!! [%s][%s] Error: %s\n\n", StringFromIPCSide(side),
@ -947,8 +936,7 @@ bool MessageChannel::MaybeInterceptSpecialIOMessage(const Message& aMsg) {
"channel.\n",
XRE_GeckoProcessTypeToString(XRE_GetProcessType()),
static_cast<uint32_t>(base::GetCurrentProcId()),
mListener->GetProtocolName(),
(mSide == ChildSide) ? "Child" : "Parent");
mListener->GetProtocolName(), StringFromIPCSide(mSide));
}
// Notify the worker thread that the connection has been closed, as we
@ -2217,8 +2205,7 @@ void MessageChannel::DebugAbort(const char* file, int line, const char* cond,
printf_stderr(
"###!!! [MessageChannel][%s][%s:%d] "
"Assertion (%s) failed. %s %s\n",
mSide == ChildSide ? "Child" : "Parent", file, line, cond, why,
reply ? "(reply)" : "");
StringFromIPCSide(mSide), file, line, cond, why, reply ? "(reply)" : "");
MessageQueue pending = std::move(mPending);
while (!pending.isEmpty()) {

Просмотреть файл

@ -28,6 +28,17 @@ using namespace mozilla;
namespace mozilla {
namespace ipc {
const char* StringFromIPCSide(Side side) {
switch (side) {
case ChildSide:
return "Child";
case ParentSide:
return "Parent";
default:
return "Unknown";
}
}
MessageLink::MessageLink(MessageChannel* aChan) : mChan(aChan) {}
MessageLink::~MessageLink() {

Просмотреть файл

@ -43,6 +43,8 @@ struct HasResultCodes {
enum Side : uint8_t { ParentSide, ChildSide, UnknownSide };
const char* StringFromIPCSide(Side side);
class MessageLink {
public:
typedef IPC::Message Message;

Просмотреть файл

@ -331,8 +331,7 @@ IProtocol::~IProtocol() {
nsPrintfCString("Actor destructor for '%s%s' called before IPC "
"lifecycle complete!\n"
"References to this actor may unexpectedly dangle!",
GetProtocolName(),
GetSide() == ChildSide ? "Child" : "Parent")
GetProtocolName(), StringFromIPCSide(GetSide()))
.get());
mLifecycleProxy->mActor = nullptr;

Просмотреть файл

@ -355,6 +355,13 @@ def _cxxLifecycleProxyType(ptr=False):
return Type("mozilla::ipc::ActorLifecycleProxy", ptr=ptr)
def _cxxSide(side):
if side == "child":
return ExprVar("mozilla::ipc::ChildSide")
if side == "parent":
return ExprVar("mozilla::ipc::ParentSide")
assert 0
def _otherSide(side):
if side == "child":
return "parent"
@ -1915,13 +1922,9 @@ class _ParamTraits:
@classmethod
def ifsideis(cls, rdrwtr, side, then, els=None):
cxxside = ExprVar("mozilla::ipc::ChildSide")
if side == "parent":
cxxside = ExprVar("mozilla::ipc::ParentSide")
ifstmt = StmtIf(
ExprBinary(
cxxside,
_cxxSide(side),
"==",
ExprCode("${rdrwtr}->GetActor()->GetSide()", rdrwtr=rdrwtr),
)
@ -5570,11 +5573,6 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
def logMessage(self, md, msgptr, pfx, actor=None, receiving=False):
actorname = _actorName(self.protocol.name, self.side)
if self.side == "parent":
side = ExprVar("mozilla::ipc::ParentSide")
else:
side = ExprVar("mozilla::ipc::ChildSide")
return StmtCode(
"""
if (mozilla::ipc::LoggingEnabledFor(${protocolname}, ${side})) {
@ -5587,7 +5585,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
}
""",
protocolname=ExprLiteral.String(self.protocol.name),
side=side,
side=_cxxSide(self.side),
actorname=ExprLiteral.String(actorname),
actor=actor or ExprVar.THIS,
pfx=ExprLiteral.String(pfx),