Use xpc_qsThrowMethodFailedWithDetails instead of xpc_qsThrowMethodFailed and xpc_qsThrowGetterSetterFailed, as the latter require an XPConnect object; r=bz
authorMs2ger <ms2ger@gmail.com>
Tue, 07 Feb 2012 21:31:32 +0100
changeset 86010 61b7ed2e15b26d8ae45d8e617e2f1cfa1d438b34
parent 86009 27a9e44e1fbb77d18953364d76f4881a401da8b9
child 86011 9a987b9287c584246387b9470211b0bf2eba2312
push id90
push userMs2ger@gmail.com
push dateTue, 07 Feb 2012 20:32:24 +0000
reviewersbz
milestone13.0a1
Use xpc_qsThrowMethodFailedWithDetails instead of xpc_qsThrowMethodFailed and xpc_qsThrowGetterSetterFailed, as the latter require an XPConnect object; r=bz
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -448,20 +448,22 @@ class PerSignatureCall():
     
     # XXXbz void methods have a signature with a isVoid() type object
     #       as first element.  Methods with no args have length-0 arg
     #       lists as second element in signaure.
     # XXXbz if isInterface() true on a type, type.inner is the interface object
     # XXXbz is isPrimitive() true on a type, then .tag() will return an
     #       IDLType.Tags value.  So you can compare
     #       type.tag() == IDLType.Tags.int8 or whatever.
-    def __init__(self, returnType, arguments, nativeMethodName):
+    def __init__(self, returnType, arguments, nativeMethodName,
+                 scriptableInterfaceAndName):
         self.returnType = returnType
         self.arguments = arguments
         self.nativeMethodName = nativeMethodName
+        self.scriptableInterfaceAndName = scriptableInterfaceAndName
 
     def unwrap_arguments(self):
         return ""
 
     def generate_call(self):
         # XXXbz add provisions for infallible calls here?
         nativeArgs = ["arg" + str(i) for i in range(len(self.arguments))]
         # XXXbz arguments that have to go in outparams go here?
@@ -500,48 +502,46 @@ class PerSignatureCall():
         resultTemplateValues = {'jsvalRef': '*vp', 'jsvalPtr': 'vp'}
         if self.returnType.isPrimitive():
             return "\n" + string.Template(getWrapTemplateForTag(self.returnType.tag())).substitute(resultTemplateValues)
 
         return """
   // XXXbz need to learn to wrap other things
   return false;"""
 
+    def getErrorReport(self):
+        return """
+    return xpc_qsThrowMethodFailedWithDetails(cx, rv, "%s", "%s");""" % self.scriptableInterfaceAndName
+
     def __str__(self):
         return (self.unwrap_arguments() + self.generate_call() +
                 self.wrap_return_value())
 
 class PerSignatureMethodCall(PerSignatureCall):
-    def __init__(self, returnType, arguments, nativeMethodName):
-        PerSignatureCall.__init__(self, returnType, arguments, nativeMethodName)
-    def getErrorReport(self):
-        return """
-    // XXX This does not actually work. It requires an XPConnect object.
-    return xpc_qsThrowMethodFailed(cx, rv, vp);"""
+    def __init__(self, returnType, arguments, nativeMethodName,
+                 scriptableInterfaceAndName):
+        PerSignatureCall.__init__(self, returnType, arguments, nativeMethodName,
+                                  scriptableInterfaceAndName)
 
 class GetterSetterCall(PerSignatureCall):
-    def __init__(self, returnType, arguments, nativeMethodName):
-        PerSignatureCall.__init__(self, returnType, arguments, nativeMethodName)
-    def getErrorReport(self):
-        return """
-    if (js::IsWrapper(obj)) {
-      // Unwrap the security wrappers, because that's what
-      // xpc_qsThrowGetterSetterFailed expects to see.
-      obj = XPCWrapper::Unwrap(cx, obj, false);
-    }
-    // XXX This does not actually work. It requires an XPConnect object.
-    return xpc_qsThrowGetterSetterFailed(cx, rv, obj, id);"""
+    def __init__(self, returnType, arguments, nativeMethodName,
+                 scriptableInterfaceAndName):
+        PerSignatureCall.__init__(self, returnType, arguments, nativeMethodName,
+                                  scriptableInterfaceAndName)
 
 class GetterCall(GetterSetterCall):
-    def __init__(self, returnType, nativeMethodName):
-        GetterSetterCall.__init__(self, returnType, [], nativeMethodName)
+    def __init__(self, returnType, nativeMethodName,
+                 scriptableInterfaceAndName):
+        GetterSetterCall.__init__(self, returnType, [], nativeMethodName,
+                                  scriptableInterfaceAndName)
 
 class SetterCall(GetterSetterCall):
-    def __init__(self, argType, nativeMethodName):
-        GetterSetterCall.__init__(self, None, [argType], nativeMethodName)
+    def __init__(self, argType, nativeMethodName, scriptableInterfaceAndName):
+        GetterSetterCall.__init__(self, None, [argType], nativeMethodName,
+                                  scriptableInterfaceAndName)
     def wrap_return_value(self):
         # We have no return value
         return "\n return true;"
 
 class CGAbstractBindingMethod(CGAbstractStaticMethod):
     def __init__(self, descriptor, name, returnType, args):
         CGAbstractStaticMethod.__init__(self, descriptor, name,
                                         returnType, args)
@@ -574,47 +574,51 @@ class CGNativeMethod(CGAbstractBindingMe
          return """
   JSObject *obj = JS_THIS_OBJECT(cx, vp);
   if (!obj)
     return false;""" + CGAbstractBindingMethod.unwrap_this(self)
 
     def generate_code(self):
         signatures = self.method.signatures()
         nativeName = MakeNativeName(self.method.identifier.name)
-        callGenerators = [PerSignatureMethodCall(s[0], s[1], nativeName)
+        callGenerators = [PerSignatureMethodCall(s[0], s[1], nativeName,
+                                                 (self.descriptor.name,
+                                                  self.method.identifier.name))
                           for s in signatures]
         if len(callGenerators) != 1:
             raise TypeError("Don't know how to handle overloads yet.  Will need to generate code to pick the right overload based on the arguments, then jump to the right generated code")
 
         return str(callGenerators[0]);
 
 class CGNativeGetter(CGAbstractBindingMethod):
     def __init__(self, descriptor, attr):
         self.attr = attr
         args = [Argument('JSContext*', 'cx'), Argument('JSObject*', 'obj'),
                 Argument('jsid', 'id'), Argument('JS::Value*', 'vp')]
         CGAbstractBindingMethod.__init__(self, descriptor,
                                          'get_'+attr.identifier.name,
                                          'JSBool', args)
     def generate_code(self):
         nativeMethodName = "Get" + MakeNativeName(self.attr.identifier.name)
-        return str(GetterCall(self.attr.type, nativeMethodName))
+        return str(GetterCall(self.attr.type, nativeMethodName,
+                              (self.descriptor.name, self.attr.identifier.name)))
 
 class CGNativeSetter(CGAbstractBindingMethod):
     def __init__(self, descriptor, attr):
         self.attr = attr
         args = [Argument('JSContext*', 'cx'), Argument('JSObject*', 'obj'),
                 Argument('jsid', 'id'), Argument('JSBool', 'strict'),
                 Argument('JS::Value*', 'vp')]
         CGAbstractBindingMethod.__init__(self, descriptor,
                                          'set_'+attr.identifier.name,
                                          'JSBool', args)
     def generate_code(self):
         nativeMethodName = "Set" + MakeNativeName(self.attr.identifier.name)
-        return str(SetterCall(self.attr.type, nativeMethodName))
+        return str(SetterCall(self.attr.type, nativeMethodName,
+                              (self.descriptor.name, self.attr.identifier.name)))
 
 class CGDescriptor(CGThing):
     def __init__(self, descriptor):
         CGThing.__init__(self)
 
         # XXXbholley - Not everything should actually have a jsclass.
         cgThings = [CGNativeMethod(descriptor, m) for m in
                     descriptor.interface.members if m.isMethod()]