From b321610cc72007b3990a86e7b1fe8b67ef03fee8 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sat, 5 Mar 2011 21:46:44 -0500 Subject: [PATCH] Interface name included in instantiation error, if available --- lib/interface.js | 11 ++++++++--- test/test-interface-name.js | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/interface.js b/lib/interface.js index 47051d0..d42df51 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -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" + ); } }; } diff --git a/test/test-interface-name.js b/test/test-interface-name.js index a50f101..dad582c 100644 --- a/test/test-interface-name.js +++ b/test/test-interface-name.js @@ -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" + ); + } +} )(); +