Declaring named class will throw error for extreaneous arguments
parent
7bb87e370f
commit
b158e542d5
12
lib/class.js
12
lib/class.js
|
@ -67,7 +67,7 @@ module.exports = function()
|
||||||
if ( arguments.length > 1 )
|
if ( arguments.length > 1 )
|
||||||
{
|
{
|
||||||
throw Error(
|
throw Error(
|
||||||
"Expecting one argument for Class definition; " +
|
"Expecting one argument for anonymous Class definition; " +
|
||||||
arguments.length + " given."
|
arguments.length + " given."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,16 @@ module.exports = function()
|
||||||
name = arguments[ 0 ];
|
name = arguments[ 0 ];
|
||||||
def = arguments[ 1 ];
|
def = arguments[ 1 ];
|
||||||
|
|
||||||
|
// 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 Class definition; " +
|
||||||
|
arguments.length + " given."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// add the name to the definition
|
// add the name to the definition
|
||||||
def.__name = name;
|
def.__name = name;
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,27 @@ var common = require( './common' ),
|
||||||
{
|
{
|
||||||
Class( 'Foo', 'Bar' );
|
Class( 'Foo', 'Bar' );
|
||||||
}, TypeError, "Second argument to named class must be the definition" );
|
}, TypeError, "Second argument to named class must be the definition" );
|
||||||
|
|
||||||
|
// we should be permitted only two arguments
|
||||||
|
var args = [ 'Foo', {}, 'extra' ];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.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 class"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch ( e )
|
||||||
|
{
|
||||||
|
assert.notEqual(
|
||||||
|
e.toString().match( args.length + ' given' ),
|
||||||
|
null,
|
||||||
|
"Named class error should provide number of given arguments"
|
||||||
|
);
|
||||||
|
}
|
||||||
} )();
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue