Bug 987007, part 1 - Make CGProxyIndexed{Getter,Setter,PresenceChecker,Deleter} return finished C++ code with the type already in it (rather than a template to be filled in later). r=bz.
authorJason Orendorff <jorendorff@mozilla.com>
Fri, 25 Apr 2014 15:07:17 -0500
changeset 180687 024eb3e19b741769861ffac85edb3d624c0c9201
parent 180686 b51cc5e640ec40ab19effd112597d5add445be9c
child 180688 b588b9285415b66ecdf297b9bc7cbb557f94a5a4
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbz
bugs987007
milestone31.0a1
Bug 987007, part 1 - Make CGProxyIndexed{Getter,Setter,PresenceChecker,Deleter} return finished C++ code with the type already in it (rather than a template to be filled in later). r=bz.
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -8855,17 +8855,17 @@ class CGProxyIndexedOperation(CGProxySpe
         # Our first argument is the id we're getting.
         argName = self.arguments[0].identifier.name
         if argName == "index":
             # We already have our index in a variable with that name
             setIndex = ""
         else:
             setIndex = "uint32_t %s = index;\n" % argName
         if self.doUnwrap:
-            unwrap = "%s* self = UnwrapProxy(proxy);\n"
+            unwrap = "%s* self = UnwrapProxy(proxy);\n" % self.descriptor.nativeType
         else:
             unwrap = ""
         return (setIndex + unwrap +
                 CGProxySpecialOperation.define(self))
 
 
 class CGProxyIndexedGetter(CGProxyIndexedOperation):
     """
@@ -8900,16 +8900,24 @@ class CGProxyIndexedPresenceChecker(CGPr
 class CGProxyIndexedSetter(CGProxyIndexedOperation):
     """
     Class to generate a call to an indexed setter.
     """
     def __init__(self, descriptor):
         CGProxyIndexedOperation.__init__(self, descriptor, 'IndexedSetter')
 
 
+class CGProxyIndexedDeleter(CGProxyIndexedOperation):
+    """
+    Class to generate a call to an indexed deleter.
+    """
+    def __init__(self, descriptor):
+        CGProxyIndexedOperation.__init__(self, descriptor, 'IndexedDeleter')
+
+
 class CGProxyNamedOperation(CGProxySpecialOperation):
     """
     Class to generate a call to a named operation.
 
     'value' is the jsval to use for the name; None indicates that it should be
     gotten from the property id.
     """
     def __init__(self, descriptor, name, value=None):
@@ -8999,24 +9007,16 @@ class CGProxyNamedPresenceChecker(CGProx
 class CGProxyNamedSetter(CGProxyNamedOperation):
     """
     Class to generate a call to a named setter.
     """
     def __init__(self, descriptor):
         CGProxyNamedOperation.__init__(self, descriptor, 'NamedSetter')
 
 
-class CGProxyIndexedDeleter(CGProxyIndexedOperation):
-    """
-    Class to generate a call to an indexed deleter.
-    """
-    def __init__(self, descriptor):
-        CGProxyIndexedOperation.__init__(self, descriptor, 'IndexedDeleter')
-
-
 class CGProxyNamedDeleter(CGProxyNamedOperation):
     """
     Class to generate a call to a named deleter.
     """
     def __init__(self, descriptor):
         CGProxyNamedOperation.__init__(self, descriptor, 'NamedDeleter')
 
 
@@ -9081,18 +9081,17 @@ class CGDOMJSProxyHandler_getOwnProperty
                 'successCode': fillDescriptor
             }
             get = fill(
                 """
                 if (IsArrayIndex(index)) {
                   $*{callGetter}
                 }
                 """,
-                callGetter=(CGProxyIndexedGetter(self.descriptor, templateValues).define() %
-                            self.descriptor.nativeType))
+                callGetter=CGProxyIndexedGetter(self.descriptor, templateValues).define())
 
         if UseHolderForUnforgeable(self.descriptor):
             tryHolder = dedent("""
                 if (!JS_GetPropertyDescriptorById(cx, ${holder}, id, flags, desc)) {
                   return false;
                 }
                 MOZ_ASSERT_IF(desc.object(), desc.object() == ${holder});
                 """)
@@ -9212,22 +9211,26 @@ class CGDOMJSProxyHandler_defineProperty
 
     def getBody(self):
         set = ""
 
         indexedSetter = self.descriptor.operations['IndexedSetter']
         if indexedSetter:
             if self.descriptor.operations['IndexedCreator'] is not indexedSetter:
                 raise TypeError("Can't handle creator that's different from the setter")
-            set += ("int32_t index = GetArrayIndexFromId(cx, id);\n" +
-                    "if (IsArrayIndex(index)) {\n" +
-                    "  *defined = true;" +  # SUPER BOGUS missing newline here
-                    indent(CGProxyIndexedSetter(self.descriptor).define()) +
-                    "  return true;\n" +
-                    "}\n") % self.descriptor.nativeType
+            set += fill(
+                """
+                int32_t index = GetArrayIndexFromId(cx, id);
+                if (IsArrayIndex(index)) {
+                  *defined = true;
+                  $*{callSetter}
+                  return true;
+                }
+                """,
+                callSetter=CGProxyIndexedSetter(self.descriptor).define())
         elif self.descriptor.supportsIndexedProperties():
             set += fill(
                 """
                 if (IsArrayIndex(GetArrayIndexFromId(cx, id))) {
                   return js::IsInNonStrictPropertySet(cx) || ThrowErrorMessage(cx, MSG_NO_INDEXED_SETTER, "${name}");
                 }
                 """,
                 name=self.descriptor.name)
@@ -9336,17 +9339,17 @@ class CGDOMJSProxyHandler_delete(ClassMe
                 """
                 int32_t index = GetArrayIndexFromId(cx, id);
                 if (IsArrayIndex(index)) {
                   $*{indexedBody}
                   // We always return here, even if the property was not found
                   return true;
                 }
                 """,
-                indexedBody=indexedBody % self.descriptor.nativeType)
+                indexedBody=indexedBody)
 
         if UseHolderForUnforgeable(self.descriptor):
             unforgeable = dedent("""
                 bool hasUnforgeable;
                 if (!JS_HasPropertyById(cx, ${holder}, id, &hasUnforgeable)) {
                   return false;
                 }
                 if (hasUnforgeable) {
@@ -9474,18 +9477,17 @@ class CGDOMJSProxyHandler_hasOwn(ClassMe
                 if (IsArrayIndex(index)) {
                   $*{presenceChecker}
 
                   *bp = found;
                   return true;
                 }
 
                 """,
-                presenceChecker=(CGProxyIndexedPresenceChecker(self.descriptor).define() %
-                                 self.descriptor.nativeType))
+                presenceChecker=CGProxyIndexedPresenceChecker(self.descriptor).define())
         else:
             indexed = ""
 
         if UseHolderForUnforgeable(self.descriptor):
             unforgeable = dedent("""
                 bool b = true;
                 bool ok = JS_AlreadyHasOwnPropertyById(cx, ${holder}, id, &b);
                 *bp = !!b;
@@ -9593,18 +9595,17 @@ class CGDOMJSProxyHandler_get(ClassMetho
                 if (IsArrayIndex(index)) {
                   $*{callGetter}
                   // Even if we don't have this index, we don't forward the
                   // get on to our expando object.
                 } else {
                   $*{getUnforgeableOrExpando}
                 }
                 """,
-                callGetter=(CGProxyIndexedGetter(self.descriptor, templateValues).define() %
-                            self.descriptor.nativeType),
+                callGetter=CGProxyIndexedGetter(self.descriptor, templateValues).define(),
                 getUnforgeableOrExpando=getUnforgeableOrExpando)
         else:
             getIndexedOrExpando = getUnforgeableOrExpando
 
         if self.descriptor.supportsNamedProperties():
             getNamed = CGProxyNamedGetter(self.descriptor, templateValues)
             if self.descriptor.supportsIndexedProperties():
                 getNamed = CGIfWrapper(getNamed, "!IsArrayIndex(index)")