Bug 1041626 - Use a macro in XrayEnumerateProperties to make the logic easier to follow. r=bz, a=sledru
authorBobby Holley <bobbyholley@gmail.com>
Wed, 23 Jul 2014 12:36:21 -0700
changeset 217273 4bee07e2ba798d2f311965d73391ef63de0108ff
parent 217272 3ff21bc2a66941426e847915ecf0ac767bb1f96e
child 217274 e0a751a852390886dd5877b5955d845c485752b4
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, sledru
bugs1041626
milestone33.0a2
Bug 1041626 - Use a macro in XrayEnumerateProperties to make the logic easier to follow. r=bz, a=sledru
dom/bindings/BindingUtils.cpp
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -1360,77 +1360,47 @@ XrayEnumerateAttributesOrMethods(JSConte
           return false;
         }
       }
     }
   }
   return true;
 }
 
+#define ENUMERATE_IF_DEFINED(fieldName) {                                     \
+  if (nativeProperties->fieldName##s &&                                       \
+      !XrayEnumerateAttributesOrMethods(cx, wrapper, obj,                     \
+                                        nativeProperties->fieldName##s,       \
+                                        nativeProperties->fieldName##Ids,     \
+                                        nativeProperties->fieldName##Specs,   \
+                                        flags, props)) {                      \
+    return false;                                                             \
+  }                                                                           \
+}
+
+
 bool
 XrayEnumerateProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
                         JS::Handle<JSObject*> obj,
                         unsigned flags, JS::AutoIdVector& props,
                         DOMObjectType type,
                         const NativeProperties* nativeProperties)
 {
   if (type == eInterface) {
-    if (nativeProperties->staticMethods &&
-        !XrayEnumerateAttributesOrMethods(cx, wrapper, obj,
-                                          nativeProperties->staticMethods,
-                                          nativeProperties->staticMethodIds,
-                                          nativeProperties->staticMethodSpecs,
-                                          flags, props)) {
-      return false;
-    }
+    ENUMERATE_IF_DEFINED(staticMethod);
   } else {
-    if (nativeProperties->methods &&
-        !XrayEnumerateAttributesOrMethods(cx, wrapper, obj,
-                                          nativeProperties->methods,
-                                          nativeProperties->methodIds,
-                                          nativeProperties->methodSpecs,
-                                          flags, props)) {
-      return false;
-    }
-    if (nativeProperties->unforgeableMethods &&
-        !XrayEnumerateAttributesOrMethods(cx, wrapper, obj,
-                                          nativeProperties->unforgeableMethods,
-                                          nativeProperties->unforgeableMethodIds,
-                                          nativeProperties->unforgeableMethodSpecs,
-                                          flags, props)) {
-      return false;
-    }
+    ENUMERATE_IF_DEFINED(method);
+    ENUMERATE_IF_DEFINED(unforgeableMethod);
   }
 
   if (type == eInterface) {
-    if (nativeProperties->staticAttributes &&
-        !XrayEnumerateAttributesOrMethods(cx, wrapper, obj,
-                                          nativeProperties->staticAttributes,
-                                          nativeProperties->staticAttributeIds,
-                                          nativeProperties->staticAttributeSpecs,
-                                          flags, props)) {
-      return false;
-    }
+    ENUMERATE_IF_DEFINED(staticAttribute);
   } else {
-    if (nativeProperties->attributes &&
-        !XrayEnumerateAttributesOrMethods(cx, wrapper, obj,
-                                          nativeProperties->attributes,
-                                          nativeProperties->attributeIds,
-                                          nativeProperties->attributeSpecs,
-                                          flags, props)) {
-      return false;
-    }
-    if (nativeProperties->unforgeableAttributes &&
-        !XrayEnumerateAttributesOrMethods(cx, wrapper, obj,
-                                          nativeProperties->unforgeableAttributes,
-                                          nativeProperties->unforgeableAttributeIds,
-                                          nativeProperties->unforgeableAttributeSpecs,
-                                          flags, props)) {
-      return false;
-    }
+    ENUMERATE_IF_DEFINED(attribute);
+    ENUMERATE_IF_DEFINED(unforgeableAttribute);
   }
 
   if (nativeProperties->constants) {
     const Prefable<const ConstantSpec>* constant;
     for (constant = nativeProperties->constants; constant->specs; ++constant) {
       if (constant->isEnabled(cx, obj)) {
         // Set i to be the index into our full list of ids/specs that we're
         // looking at now.
@@ -1442,16 +1412,18 @@ XrayEnumerateProperties(JSContext* cx, J
         }
       }
     }
   }
 
   return true;
 }
 
+#undef ENUMERATE_IF_DEFINED
+
 bool
 XrayEnumerateNativeProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
                               const NativePropertyHooks* nativePropertyHooks,
                               DOMObjectType type, JS::Handle<JSObject*> obj,
                               unsigned flags, JS::AutoIdVector& props)
 {
   if (type == eInterface &&
       nativePropertyHooks->mPrototypeID != prototypes::id::_ID_Count &&