Implemented strict argument check for interface creation
parent
649356ef23
commit
0ccdf07145
|
@ -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;
|
||||
|
||||
|
|
|
@ -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"
|
||||
);
|
||||
}
|
||||
} )();
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue