Introduce mozilla::dom::bindings::Throw, to be implemented in a way that doesn't use XPConnect (for workers).
authorMs2ger <ms2ger@gmail.com>
Tue, 14 Feb 2012 12:17:28 +0100
changeset 86821 8222d23e721626fe47131d655d21d40f344b8c3e
parent 86820 61d5493255ff9a8ed1d71546efcbfd9b00d8d089
child 86822 3ce98a4f1f5d42bbaad08c4b197847d8dd3f7757
push id124
push userMs2ger@gmail.com
push dateTue, 14 Feb 2012 11:17:37 +0000
milestone13.0a1
Introduce mozilla::dom::bindings::Throw, to be implemented in a way that doesn't use XPConnect (for workers).
dom/bindings/Codegen.py
dom/bindings/Utils.h
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -527,17 +527,17 @@ class ConcreteObjectUnwrapper():
   }""").substitute(self.substitution)
 
 class FailureFatalConcreteObjectUnwrapper(ConcreteObjectUnwrapper):
     """
     As ConcreteObjectUnwrapper, but defaulting to throwing if unwrapping fails
     """
     def __init__(self, descriptor, source, target):
         ConcreteObjectUnwrapper.__init__(self, descriptor, source, target,
-                                         "return xpc_qsThrow(cx, rv);")
+                                         "return Throw(cx, rv);")
 
 def getArgumentConversionTemplate(type, descriptor):
     if type.isSequence() or type.isArray():
         raise TypeError("Can't handle sequence or array arguments yet")
 
     if descriptor is not None:
         assert(type.isInterface())
         # This is an interface that we implement as a concrete class
@@ -559,17 +559,17 @@ def getArgumentConversionTemplate(type, 
                             "have no support for unwrapping non-concrete types: " + type)
         if type.nullable():
             template += (
                 "  } else if (${argVal}.isNullOrUndefined()) {\n"
                 "    ${name}%s = NULL;\n" % nameSuffix)
 
         template += (
             "  } else {\n"
-            "    return xpc_qsThrow(cx, NS_ERROR_XPC_BAD_CONVERT_JS);\n"
+            "    return Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);\n"
             "  }\n")
 
         if not type.nullable():
             template += "  ${typeName} &${name} = *${name}_ptr;\n"
             
         return template
 
     if type.isInterface():
@@ -987,17 +987,17 @@ class PerSignatureCall():
     def wrap_return_value(self):
         resultTemplateValues = {'jsvalRef': '*vp', 'jsvalPtr': 'vp'}
         return string.Template(
             getWrapTemplateForType(self.returnType, self.descriptor,
                                    self.resultAlreadyAddRefed)
             ).substitute(resultTemplateValues)
 
     def getErrorReport(self):
-        return 'return xpc_qsThrowMethodFailedWithDetails(cx, rv, "%s", "%s");'\
+        return 'return ThrowMethodFailedWithDetails(cx, rv, "%s", "%s");'\
                % (self.descriptor.name, self.idlNode.identifier.name)
 
     def __str__(self):
         return (self.unwrap_arguments() + self.generate_call() +
                 self.wrap_return_value())
 
 class PerSignatureMethodCall(PerSignatureCall):
     def __init__(self, returnType, arguments, nativeMethodName, descriptor,
@@ -1012,17 +1012,17 @@ class PerSignatureMethodCall(PerSignatur
         requiredArgs = len(self.arguments)
         while requiredArgs and self.arguments[requiredArgs-1].optional:
             requiredArgs -= 1
         argv = "  JS::Value *argv = JS_ARGV(cx, vp);\n" if len(self.arguments) > 0 else ""
         return ("""
   // XXXbz is this the right place for this check?  Or should it be more
   // up-front somewhere, not per-signature?
   if (argc < %d) {
-    return xpc_qsThrow(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS);
+    return Throw(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS);
   }
 %s""" % (requiredArgs, argv)) + PerSignatureCall.unwrap_arguments(self)
 
 class GetterSetterCall(PerSignatureCall):
     def __init__(self, returnType, arguments, nativeMethodName, descriptor,
                  attr, extendedAttributes):
         PerSignatureCall.__init__(self, returnType, arguments, nativeMethodName,
                                   descriptor, attr, extendedAttributes)
--- a/dom/bindings/Utils.h
+++ b/dom/bindings/Utils.h
@@ -3,26 +3,45 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_bindings_Utils_h__
 #define mozilla_dom_bindings_Utils_h__
 
 #include "mozilla/dom/bindings/DOMJSClass.h"
+
+#include "jsapi.h"
+
 #include "XPCQuickStubs.h"
 #include "XPCWrapper.h"
 
 /* All DOM globals must have a slot at DOM_PROTOTYPE_SLOT */
 #define DOM_PROTOTYPE_SLOT (JSCLASS_GLOBAL_SLOT_COUNT + 1)
 
 namespace mozilla {
 namespace dom {
 namespace bindings {
 
+inline bool
+Throw(JSContext* cx, nsresult rv)
+{
+  // XXX Introduce exception machinery.
+  JS_ReportError(cx, "Exception thrown (nsresult = %x).", rv);
+  return false;
+}
+
+inline bool
+ThrowMethodFailedWithDetails(JSContext* cx, nsresult rv,
+                             const char* /* ifaceName */,
+                             const char* /* memberName */)
+{
+  return Throw(cx, rv);
+}
+
 // "Hide" some stuff in detail...
 namespace detail {
 
 // Little helper for testing nsISupports inheritance.
 // Types we need to determine inheritance relationships.
 typedef char TrueType;
 
 struct FalseType
@@ -293,17 +312,17 @@ WrapOtherObject(JSContext *cx, JSObject 
 {
   XPCLazyCallContext lccx(JS_CALLER, cx, scope);
 
   xpcObjectHelper helper(value);
   nsresult rv;
   if (!XPCConvert::NativeInterface2JSObject(lccx, vp, NULL, helper, NULL, NULL,
                                             true, OBJ_IS_NOT_GLOBAL, &rv)) {
     if (!JS_IsExceptionPending(cx))
-      XPCThrower::Throw(rv, cx);
+      Throw(cx, rv);
     return false;
   }
 
   return true;
 }
 
 // Support for nullable types
 template<typename T>
@@ -368,17 +387,17 @@ FindEnumStringIndex(JSContext *cx, jsval
     }
 
     if (equal) {
       *ok = true;
       return i;
     }
   }
 
-  *ok = xpc_qsThrow(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
+  *ok = Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
   return 0;
 }
 
 } // namespace bindings
 } // namespace dom
 } // namespace mozilla
 
 #endif /* mozilla_dom_bindings_Utils_h__ */