diff --git a/lib/interface.js b/lib/interface.js index 2ca594d..6271930 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -143,6 +143,24 @@ function createAnonymousInterface( def ) */ function createNamedInterface( name, def ) { + // if too many arguments were provided, it's likely that they're + // expecting some result that they're not going to get + if ( arguments.length > 2 ) + { + throw Error( + "Expecting two arguments for named Interface definition; " + + arguments.length + " given." + ); + } + + // the definition must be an object + if ( typeof def !== 'object' ) + { + throw TypeError( + "Unexpected value for named class definition; object expected" + ); + } + // add the name to the definition def.__name = name; diff --git a/test/test-interface-name.js b/test/test-interface-name.js index cfe5689..804678b 100644 --- a/test/test-interface-name.js +++ b/test/test-interface-name.js @@ -50,6 +50,27 @@ var common = require( './common' ), { Interface( 'Foo', 'Bar' ); }, TypeError, "Second argument to named interface must be the definition" ); + + // we should be permitted only two arguments + var args = [ 'Foo', {}, 'extra' ]; + try + { + Interface.apply( null, args ); + + // we should not get to this line (an exception should be thrown due to + // too many arguments) + assert.fail( + "Should accept only two arguments when creating named interface" + ); + } + catch ( e ) + { + assert.notEqual( + e.toString().match( args.length + ' given' ), + null, + "Named interface error should provide number of given arguments" + ); + } } )();