Altered warning display and stack trace
parent
3820ee4b07
commit
1b1a4b60d5
12
lib/warn.js
12
lib/warn.js
|
@ -53,12 +53,24 @@ var Warning = exports.Warning = function( e )
|
|||
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 = this.stack &&
|
||||
this.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';
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,17 +29,27 @@ var common = require( './common' ),
|
|||
|
||||
|
||||
/**
|
||||
* Warning's prototype should be Error to ensure instanceof() checks work
|
||||
* properly
|
||||
* Warning should be a subtype of Error
|
||||
*/
|
||||
( function testWarningIsAvailableAndHasErrorAsPrototype()
|
||||
( function testWarningIsAvailableAndHasErrorPrototype()
|
||||
{
|
||||
assert.ok( ( Warning.prototype instanceof Error ),
|
||||
assert.ok( ( Warning( Error() ) instanceof Error ),
|
||||
"Warning should be an instance of Error"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
/**
|
||||
* Make clear that we're working with a warning
|
||||
*/
|
||||
( function testWarningShouldAlterErrorName()
|
||||
{
|
||||
assert.equal( Warning( Error() ).name, 'Warning',
|
||||
"Warning name should be properly set"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
/**
|
||||
* Just as with the other Error classes, as well as all ease.js classes, the
|
||||
* 'new' keyword should be optional when instantiating the class
|
||||
|
|
Loading…
Reference in New Issue