1
0
Fork 0

Interface name included in instantiation error, if available

closure/master
Mike Gerwitz 2011-03-05 21:46:44 -05:00
parent 6f7dabe35e
commit b321610cc7
2 changed files with 31 additions and 3 deletions

View File

@ -197,7 +197,7 @@ var extend = ( function( extending )
// sanity check
inheritCheck( prototype );
var new_interface = createInterface();
var new_interface = createInterface( iname );
util.propParse( props, {
property: function()
@ -261,9 +261,11 @@ var extend = ( function( extending )
/**
* Creates a new interface constructor function
*
* @param {string=} iname interface name
*
* @return {function()}
*/
function createInterface()
function createInterface( iname )
{
return function()
{
@ -273,7 +275,10 @@ var extend = ( function( extending )
{
// only called if someone tries to create a new instance of an
// interface
throw Error( "Interfaces cannot be instantiated" );
throw Error(
"Interface" + ( ( iname ) ? ( iname + ' ' ) : '' ) +
" cannot be instantiated"
);
}
};
}

View File

@ -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"
);
}
} )();