B2G/gecko/toolkit/content/tests/browser/browser_Troubleshoot.js
/**
 * Throws an Error if obj doesn't conform to schema.  That way you get a nice
 * error message and a stack to help you figure out what went wrong, which you
 * wouldn't get if this just returned true or false instead.  There's still
 * room for improvement in communicating validation failures, however.
 *
 * @param obj    The object to validate.
 * @param schema The schema that obj should conform to.
 */
Throws an Error if obj doesn't conform to schema.  That way you get a nice
error message and a stack to help you figure out what went wrong, which you
wouldn't get if this just returned true or false instead.  There's still
room for improvement in communicating validation failures, however.

@param obj    The object to validate.
@param schema The schema that obj should conform to.
Throws an Error if obj doesn ' t conform to schema . That way you get a nice error message and a stack to help you figure out what went wrong which you wouldn ' t get if this just returned true or false instead . There ' s still room for improvement in communicating validation failures however . @param obj The object to validate . @param schema The schema that obj should conform to .
function validateObject(obj, schema) {
  if (obj === undefined && !schema.required)
    return;
  if (typeof(schema.type) != "string")
    throw schemaErr("'type' must be a string", schema);
  if (objType(obj) != schema.type)
    throw validationErr("Object is not of the expected type", obj, schema);
  let validatorFnName = "validateObject_" + schema.type;
  if (!(validatorFnName in this))
    throw schemaErr("Validator function not defined for type", schema);
  this[validatorFnName](obj, schema);
}
function validateObject ( obj , schema ) { if ( obj === undefined && ! schema . required ) return ; if ( typeof ( schema . type ) != "string" ) throw schemaErr ( "'type' must be a string" , schema ) ; if ( objType ( obj ) != schema . type ) throw validationErr ( "Object is not of the expected type" , obj , schema ) ; let validatorFnName = "validateObject_" + schema . type ; if ( ! ( validatorFnName in this ) ) throw schemaErr ( "Validator function not defined for type" , schema ) ; this [ validatorFnName ] ( obj , schema ) ; }
Throws an Error if obj doesn't conform to schema.
Throws an Error if obj doesn ' t conform to schema .