Add type.isString().
authorMs2ger <ms2ger@gmail.com>
Sun, 12 Feb 2012 17:49:31 +0100
changeset 86757 7c2ba97d094951fd75d5f1e8d474a5dcfe6c311d
parent 86756 8cf0a37a7936f39e3d2b507d5820fe5979e67f3f
child 86758 ca1591ca387f3b5da6e1e55e57414a15f68251c2
push id109
push userMs2ger@gmail.com
push dateSun, 12 Feb 2012 17:09:25 +0000
milestone13.0a1
Add type.isString().
dom/bindings/Codegen.py
dom/bindings/parser/WebIDL.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -564,31 +564,27 @@ def getArgumentConversionTemplate(type, 
             "    return xpc_qsThrow(cx, NS_ERROR_XPC_BAD_CONVERT_JS);\n"
             "  }\n")
 
         if not type.nullable():
             template += "  ${typeName} &${name} = *${name}_ptr;\n"
             
         return template
 
-    try:
-        if type.tag() is IDLType.Tags.domstring:
-            # XXXbz Need to figure out string behavior?  Also, how to
-            # detect them?  Also, nullability?
-            
-            return (
-                "  xpc_qsDOMString ${name}(cx, ${argVal}, ${argPtr},\n"
-                "                       xpc_qsDOMString::eDefaultNullBehavior,\n"
-                "                       xpc_qsDOMString::eDefaultUndefinedBehavior);\n"
-                "  if (!${name}.IsValid()) {\n"
-                "    return false;\n"
-                "  }\n")
-    except:
-        # Some types just throw when you call tag() on them....
-        pass
+    if type.isString():
+        # XXXbz Need to figure out string behavior?  Also, how to
+        # detect them?  Also, nullability?
+
+        return (
+            "  xpc_qsDOMString ${name}(cx, ${argVal}, ${argPtr},\n"
+            "                       xpc_qsDOMString::eDefaultNullBehavior,\n"
+            "                       xpc_qsDOMString::eDefaultUndefinedBehavior);\n"
+            "  if (!${name}.IsValid()) {\n"
+            "    return false;\n"
+            "  }\n")
 
     if type.isEnum():
         enum = type.inner.identifier.name
         return (
             "  %(enumtype)s ${name};\n"
             "  {\n"
             "    bool ok;\n"
             "    $name = (%(enumtype)s) FindEnumStringIndex(cx, ${argVal}, %(values)s, &ok);\n"
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -518,16 +518,19 @@ class IDLType(IDLObject):
         return str(self.name)
 
     def nullable(self):
         return False
 
     def isPrimitive(self):
         return False
 
+    def isString(self):
+        return False
+
     def isVoid(self):
         return self.name == "Void"
 
     def isSequence(self):
         return False
 
     def isArray(self):
         return False
@@ -588,16 +591,19 @@ class IDLNullableType(IDLType):
         return self.inner.__str__() + "OrNull"
 
     def nullable(self):
         return True
 
     def isPrimitive(self):
         return self.inner.isPrimitive()
 
+    def isString(self):
+        return self.inner.isString()
+
     def isVoid(self):
         return False
 
     def isSequence(self):
         return self.inner.isSequence()
 
     def isArray(self):
         return self.inner.isArray()
@@ -626,16 +632,19 @@ class IDLSequenceType(IDLType):
         return self.inner.__str__() + "Sequence"
 
     def nullable(self):
         return False
 
     def isPrimitive(self):
         return self.inner.isPrimitive()
 
+    def isString(self):
+        return self.inner.isString()
+
     def isVoid(self):
         return False
 
     def isSequence(self):
         return True
 
     def isArray(self):
         return self.inner.isArray()
@@ -670,16 +679,19 @@ class IDLArrayType(IDLType):
         return self.inner.__str__() + "Array"
 
     def nullable(self):
         return False
 
     def isPrimitive(self):
         return self.inner.isPrimitive()
 
+    def isString(self):
+        return self.inner.isString()
+
     def isVoid(self):
         return False
 
     def isSequence(self):
         assert not self.inner.isSequence()
         return self.inner.isSequence()
 
     def isArray(self):
@@ -714,16 +726,19 @@ class IDLTypedefType(IDLType, IDLObjectW
         return self.identifier.name
 
     def nullable(self):
         return self.inner.nullable()
 
     def isPrimitive(self):
         return self.inner.isPrimitive()
 
+    def isString(self):
+        return self.inner.isString()
+
     def isVoid(self):
         return self.inner.void()
 
     def isSequence(self):
         return self.inner.isSequence()
 
     def isArray(self):
         return self.inner.isArray()
@@ -755,16 +770,19 @@ class IDLWrapperType(IDLType):
         return str(self.name.name)
 
     def nullable(self):
         return False
 
     def isPrimitive(self):
         return False
 
+    def isString(self):
+        return False
+
     def isVoid(self):
         return False
 
     def isSequence(self):
         return False
 
     def isArray(self):
         return False
@@ -838,16 +856,19 @@ class IDLBuiltinType(IDLType):
     def __init__(self, location, name, type):
         IDLType.__init__(self, location, name)
         self.builtin = True
         self.type = type
 
     def isPrimitive(self):
         return self.type < IDLBuiltinType.Types.double
 
+    def isString(self):
+        return self.type == IDLBuiltinType.Types.domstring
+
     def isInteger(self):
         return self.type <= IDLBuiltinType.Types.unsigned_long_long
 
     def isArrayBuffer(self):
         return self.type == IDLBuiltinType.Types.ArrayBuffer
 
     def isInterface(self):
         # ArrayBuffers are interface types per the TypedArray spec,