Class name is now provided in all errors where name is available, within class module
parent
da8be9affa
commit
2967cc7a9a
10
lib/class.js
10
lib/class.js
|
@ -425,7 +425,10 @@ var extend = ( function( extending )
|
|||
// disallow use of our internal __initProps() method
|
||||
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 )
|
||||
{
|
||||
throw Error( "Abstract classes cannot be instantiated" );
|
||||
throw Error(
|
||||
"Abstract class " + ( cname || '(anonymous)' ) +
|
||||
" cannot be instantiated"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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"
|
||||
);
|
||||
}
|
||||
} )();
|
||||
|
||||
|
|
Loading…
Reference in New Issue