Extracted Warning into warn/Warning
Test case moved to reflect the path change.protolib
parent
1bba35418a
commit
de33a7c964
56
lib/warn.js
56
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' );
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
Loading…
Reference in New Issue