1 /**
  2  * @namespace
  3  */
  4 jasmine.util = {};
  5 
  6 /**
  7  * Declare that a child class inherit it's prototype from the parent class.
  8  *
  9  * @private
 10  * @param {Function} childClass
 11  * @param {Function} parentClass
 12  */
 13 jasmine.util.inherit = function(childClass, parentClass) {
 14   /**
 15    * @private
 16    */
 17   var subclass = function() {
 18   };
 19   subclass.prototype = parentClass.prototype;
 20   childClass.prototype = new subclass;
 21 };
 22 
 23 jasmine.util.formatException = function(e) {
 24   var lineNumber;
 25   if (e.line) {
 26     lineNumber = e.line;
 27   }
 28   else if (e.lineNumber) {
 29     lineNumber = e.lineNumber;
 30   }
 31 
 32   var file;
 33 
 34   if (e.sourceURL) {
 35     file = e.sourceURL;
 36   }
 37   else if (e.fileName) {
 38     file = e.fileName;
 39   }
 40 
 41   var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString();
 42 
 43   if (file && lineNumber) {
 44     message += ' in ' + file + ' (line ' + lineNumber + ')';
 45   }
 46 
 47   return message;
 48 };
 49 
 50 jasmine.util.htmlEscape = function(str) {
 51   if (!str) return str;
 52   return str.replace(/&/g, '&')
 53     .replace(/</g, '<')
 54     .replace(/>/g, '>');
 55 };
 56 
 57 jasmine.util.argsToArray = function(args) {
 58   var arrayOfArgs = [];
 59   for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
 60   return arrayOfArgs;
 61 };
 62 
 63 jasmine.util.extend = function(destination, source) {
 64   for (var property in source) destination[property] = source[property];
 65   return destination;
 66 };
 67 
 68