From de33a7c9645296a04cf52b114b1664205e0f9740 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 9 Jun 2014 00:03:11 -0400 Subject: [PATCH] Extracted Warning into warn/Warning Test case moved to reflect the path change. --- lib/warn.js | 56 +---------------------- lib/warn/Warning.js | 81 ++++++++++++++++++++++++++++++++++ test/{ => warn}/WarningTest.js | 0 3 files changed, 82 insertions(+), 55 deletions(-) create mode 100644 lib/warn/Warning.js rename test/{ => warn}/WarningTest.js (100%) diff --git a/lib/warn.js b/lib/warn.js index ddc6bbb..289e0a3 100644 --- a/lib/warn.js +++ b/lib/warn.js @@ -36,61 +36,7 @@ var _handler = null; var _console = ( typeof console !== 'undefined' ) ? console : undefined; -/** - * Permits wrapping an exception as a warning - * - * Warnings are handled differently by the system, depending on the warning - * level that has been set. - * - * @param {Error} e exception (error) to wrap - * - * @return {Warning} new warning instance - * - * @constructor - */ -var Warning = exports.Warning = function( e ) -{ - // allow instantiation without use of 'new' keyword - if ( !( this instanceof Warning ) ) - { - return new Warning( e ); - } - - // ensure we're wrapping an exception - if ( !( e instanceof Error ) ) - { - throw TypeError( "Must provide exception to wrap" ); - } - - Error.prototype.constructor.call( this, e.message ); - - // copy over the message for convenience - this.message = e.message; - this.name = 'Warning'; - this._error = e; - - this.stack = e.stack && - e.stack.replace( /^.*?\n+/, - this.name + ': ' + this.message + "\n" - ); -}; - -// ensures the closest compatibility...just be careful not to modify Warning's -// prototype -Warning.prototype = Error(); -Warning.prototype.constructor = Warning; -Warning.prototype.name = 'Warning'; - - -/** - * Return the error wrapped by the warning - * - * @return {Error} wrapped error - */ -Warning.prototype.getError = function() -{ - return this._error; -}; +exports.Warning = require( './warn/Warning' ); /** diff --git a/lib/warn/Warning.js b/lib/warn/Warning.js new file mode 100644 index 0000000..521a6f0 --- /dev/null +++ b/lib/warn/Warning.js @@ -0,0 +1,81 @@ +/** + * Warning prototype + * + * Copyright (C) 2014 Free Software Foundation, Inc. + * + * This file is part of GNU ease.js. + * + * ease.js is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +/** + * Permits wrapping an exception as a warning + * + * Warnings are handled differently by the system, depending on the warning + * level that has been set. + * + * @param {Error} e exception (error) to wrap + * + * @return {Warning} new warning instance + * + * @constructor + */ +function Warning( e ) +{ + // allow instantiation without use of 'new' keyword + if ( !( this instanceof Warning ) ) + { + return new Warning( e ); + } + + // ensure we're wrapping an exception + if ( !( e instanceof Error ) ) + { + throw TypeError( "Must provide exception to wrap" ); + } + + Error.prototype.constructor.call( this, e.message ); + + // copy over the message for convenience + this.message = e.message; + this.name = 'Warning'; + this._error = e; + + this.stack = e.stack && + e.stack.replace( /^.*?\n+/, + this.name + ': ' + this.message + "\n" + ); +}; + +// ensures the closest compatibility...just be careful not to modify Warning's +// prototype +Warning.prototype = Error(); +Warning.prototype.constructor = Warning; +Warning.prototype.name = 'Warning'; + + +/** + * Return the error wrapped by the warning + * + * @return {Error} wrapped error + */ +Warning.prototype.getError = function() +{ + return this._error; +}; + + +module.exports = Warning; + diff --git a/test/WarningTest.js b/test/warn/WarningTest.js similarity index 100% rename from test/WarningTest.js rename to test/warn/WarningTest.js