1
0
Fork 0

Implement GH#1 Provide useful error when attempting to extend from non-constructor

closure/master
Mike Gerwitz 2011-05-22 21:54:41 -04:00
parent 8c62ee021c
commit cf344186fc
2 changed files with 34 additions and 0 deletions

View File

@ -200,6 +200,12 @@ exports.build = function extend()
|| { __length: 0 } || { __length: 0 }
; ;
// must extend from constructor or class
if ( typeof base !== 'function' )
{
throw TypeError( "Must extend from class or constructor");
}
// prevent extending final classes // prevent extending final classes
if ( base.___$$final$$ === true ) if ( base.___$$final$$ === true )
{ {

View File

@ -373,3 +373,31 @@ for ( var i = 0; i < class_count; i++ )
); );
} )(); } )();
/**
* Previously, when attempting to extend from an invalid supertype, you'd get a
* CALL_NON_FUNCTION_AS_CONSTRUCTOR error, which is not very helpful to someone
* who is not familiar with the ease.js internals. Let's provide a more useful
* error that clearly states what's going on.
*/
( function testExtendingFromNonCtorOrClassProvidesUsefulError()
{
try
{
// invalid supertype
Class.extend( 'oops', {} );
}
catch ( e )
{
assert.ok( e.message.search( 'extend from' ),
"Error message for extending from non-ctor or class makes sense"
);
return;
}
assert.fail(
"Attempting to extend from non-ctor or class should throw exception"
);
} )();