1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/services/sync/tps/extensions/mozmill/resource/modules/errors.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +var EXPORTED_SYMBOLS = ['BaseError', 1.9 + 'ApplicationQuitError', 1.10 + 'AssertionError', 1.11 + 'TimeoutError']; 1.12 + 1.13 + 1.14 +/** 1.15 + * Creates a new instance of a base error 1.16 + * 1.17 + * @class Represents the base for custom errors 1.18 + * @param {string} [aMessage=Error().message] 1.19 + * The error message to show 1.20 + * @param {string} [aFileName=Error().fileName] 1.21 + * The file name where the error has been raised 1.22 + * @param {string} [aLineNumber=Error().lineNumber] 1.23 + * The line number of the file where the error has been raised 1.24 + * @param {string} [aFunctionName=undefined] 1.25 + * The function name in which the error has been raised 1.26 + */ 1.27 +function BaseError(aMessage, aFileName, aLineNumber, aFunctionName) { 1.28 + this.name = this.constructor.name; 1.29 + 1.30 + var err = new Error(); 1.31 + if (err.stack) { 1.32 + this.stack = err.stack; 1.33 + } 1.34 + 1.35 + this.message = aMessage || err.message; 1.36 + this.fileName = aFileName || err.fileName; 1.37 + this.lineNumber = aLineNumber || err.lineNumber; 1.38 + this.functionName = aFunctionName; 1.39 +} 1.40 + 1.41 + 1.42 +/** 1.43 + * Creates a new instance of an application quit error used by Mozmill to 1.44 + * indicate that the application is going to shutdown 1.45 + * 1.46 + * @class Represents an error object thrown when the application is going to shutdown 1.47 + * @param {string} [aMessage=Error().message] 1.48 + * The error message to show 1.49 + * @param {string} [aFileName=Error().fileName] 1.50 + * The file name where the error has been raised 1.51 + * @param {string} [aLineNumber=Error().lineNumber] 1.52 + * The line number of the file where the error has been raised 1.53 + * @param {string} [aFunctionName=undefined] 1.54 + * The function name in which the error has been raised 1.55 + */ 1.56 +function ApplicationQuitError(aMessage, aFileName, aLineNumber, aFunctionName) { 1.57 + BaseError.apply(this, arguments); 1.58 +} 1.59 + 1.60 +ApplicationQuitError.prototype = Object.create(BaseError.prototype, { 1.61 + constructor : { value : ApplicationQuitError } 1.62 +}); 1.63 + 1.64 + 1.65 +/** 1.66 + * Creates a new instance of an assertion error 1.67 + * 1.68 + * @class Represents an error object thrown by failing assertions 1.69 + * @param {string} [aMessage=Error().message] 1.70 + * The error message to show 1.71 + * @param {string} [aFileName=Error().fileName] 1.72 + * The file name where the error has been raised 1.73 + * @param {string} [aLineNumber=Error().lineNumber] 1.74 + * The line number of the file where the error has been raised 1.75 + * @param {string} [aFunctionName=undefined] 1.76 + * The function name in which the error has been raised 1.77 + */ 1.78 +function AssertionError(aMessage, aFileName, aLineNumber, aFunctionName) { 1.79 + BaseError.apply(this, arguments); 1.80 +} 1.81 + 1.82 +AssertionError.prototype = Object.create(BaseError.prototype, { 1.83 + constructor : { value : AssertionError } 1.84 +}); 1.85 + 1.86 +/** 1.87 + * Creates a new instance of a timeout error 1.88 + * 1.89 + * @class Represents an error object thrown by failing assertions 1.90 + * @param {string} [aMessage=Error().message] 1.91 + * The error message to show 1.92 + * @param {string} [aFileName=Error().fileName] 1.93 + * The file name where the error has been raised 1.94 + * @param {string} [aLineNumber=Error().lineNumber] 1.95 + * The line number of the file where the error has been raised 1.96 + * @param {string} [aFunctionName=undefined] 1.97 + * The function name in which the error has been raised 1.98 + */ 1.99 +function TimeoutError(aMessage, aFileName, aLineNumber, aFunctionName) { 1.100 + AssertionError.apply(this, arguments); 1.101 +} 1.102 + 1.103 +TimeoutError.prototype = Object.create(AssertionError.prototype, { 1.104 + constructor : { value : TimeoutError } 1.105 +});