1
0
Fork 0

Class name is now provided in all errors where name is available, within class module

closure/master
Mike Gerwitz 2011-03-05 13:13:53 -05:00
parent da8be9affa
commit 2967cc7a9a
2 changed files with 58 additions and 2 deletions

View File

@ -425,7 +425,10 @@ var extend = ( function( extending )
// disallow use of our internal __initProps() method // disallow use of our internal __initProps() method
if ( name === '__initProps' ) if ( name === '__initProps' )
{ {
throw new Error( "__initProps is a reserved method" ); throw new Error(
( ( cname ) ? cname + '::' : '' ) +
"__initProps is a reserved method"
);
} }
}, },
@ -585,7 +588,10 @@ var extend = ( function( extending )
{ {
if ( !extending ) if ( !extending )
{ {
throw Error( "Abstract classes cannot be instantiated" ); throw Error(
"Abstract class " + ( cname || '(anonymous)' ) +
" cannot be instantiated"
);
} }
}; };

View File

@ -234,3 +234,53 @@ var common = require( './common' ),
); );
} )(); } )();
/**
* The class name should be provided in the error thrown when attempting to
* instantiate an abstract class, if it's available
*/
( function testClassNameIsGivenWhenTryingToInstantiateAbstractClass()
{
var name = 'Foo';
try
{
Class( name, { 'abstract foo': [] } )();
// we're not here to test to make sure it is thrown, but if it's not,
// then there's likely a problem
assert.fail(
"Was expecting instantiation error. There's a bug somewhere!"
);
}
catch ( e )
{
assert.notEqual(
e.toString().match( name ),
null,
"Abstract class instantiation error should contain class name"
);
}
// if no name is provided, then (anonymous) should be indicated
try
{
Class( { 'abstract foo': [] } )();
// we're not here to test to make sure it is thrown, but if it's not,
// then there's likely a problem
assert.fail(
"Was expecting instantiation error. There's a bug somewhere!"
);
}
catch ( e )
{
assert.notEqual(
e.toString().match( '(anonymous)' ),
null,
"Abstract class instantiation error should recognize that class " +
"is anonymous if no name was given"
);
}
} )();