Bug 1249606 - Automatically generate operator== for WebIDL dictionaries. r=bzbarsky
authorDiego Pino Garcia <dpino@igalia.com>
Thu, 29 Nov 2018 17:07:30 -0500
changeset 505279 e2a7b9a99226012bac933c5315c898ef9379211b
parent 505278 0c715a8f0170fd4b19c4281c269c03f872090648
child 505280 3a2c2eb8f481dedfdf7680b856cdef72a34fece9
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1249606
milestone65.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 1249606 - Automatically generate operator== for WebIDL dictionaries. r=bzbarsky
dom/base/ChromeUtils.cpp
dom/bindings/BindingDeclarations.h
dom/bindings/Codegen.py
--- a/dom/base/ChromeUtils.cpp
+++ b/dom/base/ChromeUtils.cpp
@@ -614,20 +614,17 @@ ChromeUtils::IsOriginAttributesEqual(dom
 {
   return IsOriginAttributesEqual(aA, aB);
 }
 
 /* static */ bool
 ChromeUtils::IsOriginAttributesEqual(const dom::OriginAttributesDictionary& aA,
                                      const dom::OriginAttributesDictionary& aB)
 {
-  return aA.mAppId == aB.mAppId &&
-         aA.mInIsolatedMozBrowser == aB.mInIsolatedMozBrowser &&
-         aA.mUserContextId == aB.mUserContextId &&
-         aA.mPrivateBrowsingId == aB.mPrivateBrowsingId;
+  return aA == aB;
 }
 
 #ifdef NIGHTLY_BUILD
 /* static */ void
 ChromeUtils::GetRecentJSDevError(GlobalObject& aGlobal,
                                 JS::MutableHandleValue aRetval,
                                 ErrorResult& aRv)
 {
--- a/dom/bindings/BindingDeclarations.h
+++ b/dom/bindings/BindingDeclarations.h
@@ -158,16 +158,21 @@ public:
     mImpl.emplace(aValue);
   }
 
   bool operator==(const Optional_base<T, InternalType>& aOther) const
   {
     return mImpl == aOther.mImpl;
   }
 
+  bool operator!=(const Optional_base<T, InternalType>& aOther) const
+  {
+    return mImpl != aOther.mImpl;
+  }
+
   template<typename T1, typename T2>
   explicit Optional_base(const T1& aValue1, const T2& aValue2)
   {
     mImpl.emplace(aValue1, aValue2);
   }
 
   bool WasPassed() const
   {
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -12991,16 +12991,40 @@ class CGDictionary(CGThing):
             body.append(memberAssign)
         body.append(CGGeneric("return *this;\n"))
         return ClassMethod(
             "operator=", "%s&" % self.makeClassName(self.dictionary),
             [Argument("const %s&" % self.makeClassName(self.dictionary),
                       "aOther")],
             body=body.define())
 
+    def canHaveEqualsOperator(self):
+        return all(m.type.isString() or m.type.isPrimitive() for (m,_) in
+                   self.memberInfo)
+
+    def equalsOperator(self):
+        body = CGList([])
+
+        for m, _ in self.memberInfo:
+            memberName = self.makeMemberName(m.identifier.name)
+            memberTest = CGGeneric(fill(
+                """
+                if (${memberName} != aOther.${memberName}) {
+                    return false;
+                }
+                """,
+                memberName=memberName))
+            body.append(memberTest)
+        body.append(CGGeneric("return true;\n"))
+        return ClassMethod(
+            "operator==", "bool",
+            [Argument("const %s&" % self.makeClassName(self.dictionary),
+                      "aOther")
+            ], const=True, body=body.define())
+
     def getStructs(self):
         d = self.dictionary
         selfName = self.makeClassName(d)
         members = [ClassMember(self.makeMemberName(m[0].identifier.name),
                                self.getMemberType(m),
                                visibility="public",
                                body=self.getMemberInitializer(m),
                                hasIgnoreInitCheckFlag=True)
@@ -13071,16 +13095,19 @@ class CGDictionary(CGThing):
                                           bodyInHeader=True,
                                           visibility="public",
                                           explicit=True,
                                           body="*this = aOther;\n"))
             methods.append(self.assignmentOperator())
         else:
             disallowCopyConstruction = True
 
+        if self.canHaveEqualsOperator():
+            methods.append(self.equalsOperator())
+
         struct = CGClass(selfName,
                          bases=[ClassBase(self.base())],
                          members=members,
                          constructors=ctors,
                          methods=methods,
                          isStruct=True,
                          disallowCopyConstruction=disallowCopyConstruction)