From b3473b9c6808cafdbae889af70512e0b7fda79a5 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Wed, 6 Apr 2022 23:40:47 +0000 Subject: [PATCH] Bug 239460 - Specify types for XPIDL consts in C++, r=xpcom-reviewers,mccr8 Before this change, all XPIDL constants were declared using an anonymous `enum` rather than using a static constant. This change makes the generated code more consistent with what is done in languages like Rust. Some small changes were needed due to signed/unsigned comparison warnings which were previously silent. Differential Revision: https://phabricator.services.mozilla.com/D143090 --- netwerk/cookie/nsICookie.idl | 6 +++--- xpcom/idl-parser/xpidl/header.py | 14 ++++---------- xpcom/system/nsIXULRuntime.idl | 2 +- xpfe/appshell/AppWindow.cpp | 4 +++- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/netwerk/cookie/nsICookie.idl b/netwerk/cookie/nsICookie.idl index 0b2e5e97bc9d9..4d3ea2e023add 100644 --- a/netwerk/cookie/nsICookie.idl +++ b/netwerk/cookie/nsICookie.idl @@ -15,9 +15,9 @@ typedef long nsCookiePolicy; [builtinclass, scriptable, uuid(adf0db5e-211e-45a3-be14-4486ac430a58)] interface nsICookie : nsISupports { - const uint32_t SAMESITE_NONE = 0; - const uint32_t SAMESITE_LAX = 1; - const uint32_t SAMESITE_STRICT = 2; + const int32_t SAMESITE_NONE = 0; + const int32_t SAMESITE_LAX = 1; + const int32_t SAMESITE_STRICT = 2; /** * the name of the cookie diff --git a/xpcom/idl-parser/xpidl/header.py b/xpcom/idl-parser/xpidl/header.py index a63ded29e14a5..c957ba845e792 100644 --- a/xpcom/idl-parser/xpidl/header.py +++ b/xpcom/idl-parser/xpidl/header.py @@ -495,22 +495,16 @@ def record_name(name): record_name(methodNativeName(m)) def write_const_decls(g): - fd.write(" enum {\n") - enums = [] for c in g: printComments(fd, c.doccomments, " ") - basetype = c.basetype - value = c.getValue() - enums.append( - " %(name)s = %(value)s%(signed)s" + fd.write( + " static constexpr %(type)s %(name)s = %(value)s;\n" % { + "type": c.realtype.nativeType("in"), "name": c.name, - "value": value, - "signed": (not basetype.signed) and "U" or "", + "value": c.getValue(), } ) - fd.write(",\n".join(enums)) - fd.write("\n };\n\n") def write_cenum_decl(b): fd.write(" enum %s : uint%d_t {\n" % (b.basename, b.width)) diff --git a/xpcom/system/nsIXULRuntime.idl b/xpcom/system/nsIXULRuntime.idl index 351b2766ca1f5..c78d3c4565508 100644 --- a/xpcom/system/nsIXULRuntime.idl +++ b/xpcom/system/nsIXULRuntime.idl @@ -272,7 +272,7 @@ interface nsIXULRuntime : nsISupports * The current e10s-multi experiment number. Set dom.ipc.multiOptOut to (at * least) this to disable it until the next experiment. */ - const uint32_t E10S_MULTI_EXPERIMENT = 1; + const int32_t E10S_MULTI_EXPERIMENT = 1; /** * If true, the accessibility service is running. diff --git a/xpfe/appshell/AppWindow.cpp b/xpfe/appshell/AppWindow.cpp index d325b842ca4aa..50fd3e3d5adfc 100644 --- a/xpfe/appshell/AppWindow.cpp +++ b/xpfe/appshell/AppWindow.cpp @@ -1465,8 +1465,10 @@ bool AppWindow::UpdateWindowStateFromMiscXULAttributes() { if (!stateString.IsEmpty()) { nsresult errorCode; int32_t zLevel = stateString.ToInteger(&errorCode); - if (NS_SUCCEEDED(errorCode) && zLevel >= lowestZ && zLevel <= highestZ) + if (NS_SUCCEEDED(errorCode) && zLevel >= int32_t(lowestZ) && + zLevel <= int32_t(highestZ)) { SetZLevel(zLevel); + } } return gotState;