Interface name included in instantiation error, if available
parent
6f7dabe35e
commit
b321610cc7
|
@ -197,7 +197,7 @@ var extend = ( function( extending )
|
||||||
// sanity check
|
// sanity check
|
||||||
inheritCheck( prototype );
|
inheritCheck( prototype );
|
||||||
|
|
||||||
var new_interface = createInterface();
|
var new_interface = createInterface( iname );
|
||||||
|
|
||||||
util.propParse( props, {
|
util.propParse( props, {
|
||||||
property: function()
|
property: function()
|
||||||
|
@ -261,9 +261,11 @@ var extend = ( function( extending )
|
||||||
/**
|
/**
|
||||||
* Creates a new interface constructor function
|
* Creates a new interface constructor function
|
||||||
*
|
*
|
||||||
|
* @param {string=} iname interface name
|
||||||
|
*
|
||||||
* @return {function()}
|
* @return {function()}
|
||||||
*/
|
*/
|
||||||
function createInterface()
|
function createInterface( iname )
|
||||||
{
|
{
|
||||||
return function()
|
return function()
|
||||||
{
|
{
|
||||||
|
@ -273,7 +275,10 @@ var extend = ( function( extending )
|
||||||
{
|
{
|
||||||
// only called if someone tries to create a new instance of an
|
// only called if someone tries to create a new instance of an
|
||||||
// interface
|
// interface
|
||||||
throw Error( "Interfaces cannot be instantiated" );
|
throw Error(
|
||||||
|
"Interface" + ( ( iname ) ? ( iname + ' ' ) : '' ) +
|
||||||
|
" cannot be instantiated"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,3 +218,26 @@ var common = require( './common' ),
|
||||||
}
|
}
|
||||||
} )();
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
( function testInterfaceNameIsIncludedInInstantiationError()
|
||||||
|
{
|
||||||
|
var name = 'Foo';
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// this should throw an exception (cannot instantiate interfaces)
|
||||||
|
Interface( name )();
|
||||||
|
|
||||||
|
// we should never get here
|
||||||
|
assert.fail( "Exception expected. There's a bug somewhere." );
|
||||||
|
}
|
||||||
|
catch ( e )
|
||||||
|
{
|
||||||
|
assert.notEqual(
|
||||||
|
e.toString().match( name ),
|
||||||
|
null,
|
||||||
|
"Interface name is included in instantiation error message"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue