Bug 873684 - Improve error reporting when a value can't be converted to the expected type. r=bz
authorReuben Morais <reuben.morais@gmail.com>
Fri, 17 May 2013 21:14:18 -0700
changeset 132302 17a16c7e987075856ee516d28dcac812d344bb7e
parent 132301 a20b345ae2cb1f5ab020afe16f2e72927d867fec
child 132303 be729bc526a3879a8c1bcd77d6fa0c7dd415ec93
push id24693
push userphilringnalda@gmail.com
push dateSun, 19 May 2013 01:08:22 +0000
treeherdermozilla-central@317fe0f314ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs873684
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 873684 - Improve error reporting when a value can't be converted to the expected type. r=bz
dom/bindings/Codegen.py
dom/bindings/Errors.msg
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -2550,17 +2550,17 @@ def getJSToNativeConversionInfo(type, de
     def onFailureNotAnObject(failureCode):
         return CGWrapper(CGGeneric(
                 failureCode or
                 ('ThrowErrorMessage(cx, MSG_NOT_OBJECT);\n'
                  '%s' % exceptionCode)), post="\n")
     def onFailureBadType(failureCode, typeName):
         return CGWrapper(CGGeneric(
                 failureCode or
-                ('ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "%s");'
+                ('ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "%s");\n'
                  '%s' % (typeName, exceptionCode))), post="\n")
     def onFailureNotCallable(failureCode):
         return CGWrapper(CGGeneric(
                 failureCode or
                 ('ThrowErrorMessage(cx, MSG_NOT_CALLABLE);\n'
                  '%s' % exceptionCode)), post="\n")
 
     # A helper function for handling default values.  Takes a template
@@ -2737,17 +2737,17 @@ for (uint32_t i = 0; i < length; ++i) {
                         # interfaces, which use an internal holder for the
                         # conversion even when forceOwningType ends up true.
                         "holderName": "tempHolder",
                         }
                     ))).define()
 
         templateBody += "\n}"
         templateBody = wrapObjectTemplate(templateBody, type,
-                                          "${declName}.SetNull()")
+                                          "${declName}.SetNull()", notSequence)
         # Sequence arguments that might contain traceable things need
         # to get traced
         if not isMember and typeNeedsCx(elementType, descriptorProvider):
             holderType = CGTemplatedType("SequenceRooter", elementInfo.declType)
             holderArgs = "cx, &%s" % arrayRef
         else:
             holderType = None
             holderArgs = None
@@ -3084,17 +3084,18 @@ for (uint32_t i = 0; i < length; ++i) {
                     "  ${holderName} = tmp;\n"
                     "}\n")
 
             # And store our tmp, before it goes out of scope.
             templateBody += "${declName} = tmp;"
 
         templateBody = wrapObjectTemplate(templateBody, type,
                                           "${declName} = nullptr",
-                                          failureCode)
+                                          onFailureBadType(failureCode,
+                                                           descriptor.interface.identifier.name).define())
 
         declType = CGGeneric(declType)
         if holderType is not None:
             holderType = CGGeneric(holderType)
         return JSToNativeConversionInfo(templateBody,
                                         declType=declType,
                                         holderType=holderType,
                                         dealWithOptional=isOptional)
@@ -3443,17 +3444,17 @@ for (uint32_t i = 0; i < length; ++i) {
         conversion = (
             "if (!JS_ObjectIsDate(cx, &${val}.toObject()) ||\n"
             "    !%s.SetTimeStamp(cx, &${val}.toObject())) {\n"
             "%s\n"
             "}" %
             (dateVal, CGIndenter(CGGeneric(notDate)).define()))
 
         conversion = wrapObjectTemplate(conversion, type,
-                                        "${declName}.SetNull()")
+                                        "${declName}.SetNull()", notDate)
         return JSToNativeConversionInfo(conversion,
                                         declType=declType,
                                         dealWithOptional=isOptional)
 
     if not type.isPrimitive():
         raise TypeError("Need conversion for argument type '%s'" % str(type))
 
     typeName = builtinNames[type.tag()]
--- a/dom/bindings/Errors.msg
+++ b/dom/bindings/Errors.msg
@@ -16,25 +16,25 @@
  *
  * <FORMAT_STRING> is a string literal, containing <ARGUMENT_COUNT> sequences
  * {X} where X  is an integer representing the argument number that will
  * be replaced with a string value when the error is reported.
  */
 
 MSG_DEF(MSG_INVALID_ENUM_VALUE, 2, "Value '{0}' is not a valid value for enumeration {1}.")
 MSG_DEF(MSG_MISSING_ARGUMENTS, 1, "Not enough arguments to {0}.")
-MSG_DEF(MSG_NOT_OBJECT, 0, "Value not an object.")
+MSG_DEF(MSG_NOT_OBJECT, 0, "Value is not an object.")
 MSG_DEF(MSG_NOT_CALLABLE, 0, "Value is not callable.")
 MSG_DEF(MSG_DOES_NOT_IMPLEMENT_INTERFACE, 1, "Value does not implement interface {0}.")
 MSG_DEF(MSG_NOT_IN_UNION, 1, "Value could not be converted to any of: {0}.")
 MSG_DEF(MSG_ILLEGAL_CONSTRUCTOR, 0, "Illegal constructor.")
 MSG_DEF(MSG_NO_PROPERTY_SETTER, 1, "{0} doesn't have an indexed property setter.")
 MSG_DEF(MSG_ENFORCE_RANGE_NON_FINITE, 1, "Non-finite value is out of range for {0}.")
 MSG_DEF(MSG_ENFORCE_RANGE_OUT_OF_RANGE, 1, "Value is out of range for {0}.")
-MSG_DEF(MSG_NOT_SEQUENCE, 0, "object can not be converted to a sequence")
-MSG_DEF(MSG_NOT_DICTIONARY, 0, "value can not be converted to a dictionary")
-MSG_DEF(MSG_INVALID_ARG, 2, "argument {0} is not valid for any of the {1}-argument overloads")
-MSG_DEF(MSG_GLOBAL_NOT_NATIVE, 0, "global is not a native object")
+MSG_DEF(MSG_NOT_SEQUENCE, 0, "Value can not be converted to a sequence.")
+MSG_DEF(MSG_NOT_DICTIONARY, 0, "Value can not be converted to a dictionary.")
+MSG_DEF(MSG_INVALID_ARG, 2, "Argument {0} is not valid for any of the {1}-argument overloads.")
+MSG_DEF(MSG_GLOBAL_NOT_NATIVE, 0, "Global is not a native object.")
 MSG_DEF(MSG_ENCODING_NOT_SUPPORTED, 1, "The given encoding '{0}' is not supported.")
 MSG_DEF(MSG_DOM_ENCODING_NOT_UTF, 0, "The encoding must be utf-8, utf-16, or utf-16be.")
 MSG_DEF(MSG_NOT_FINITE, 0, "Floating-point value is not finite.")
 MSG_DEF(MSG_INVALID_VERSION, 0, "0 (Zero) is not a valid database version.")
 MSG_DEF(MSG_NOT_DATE, 0, "Value is not a date.")