1
0
Fork 0

Interfaces permit only abstract methods

closure/master
Mike Gerwitz 2010-12-01 21:39:41 -05:00
parent 2e930482d2
commit c910dafb76
2 changed files with 24 additions and 7 deletions

View File

@ -36,6 +36,9 @@ exports.extend = function()
} }
exports.abstractMethod = util.createAbstractMethod;
/** /**
* Default interface implementation * Default interface implementation
* *
@ -71,10 +74,10 @@ function prop_check( props )
{ {
for ( prop in props ) for ( prop in props )
{ {
if ( !( props[ prop ] instanceof Function ) ) if ( util.isAbstractMethod( props[ prop ] ) === false )
{ {
throw new Error( throw new Error(
"Only methods are permitted within Interface definitons" "Only abstract methods are permitted within Interface definitons"
); );
} }
} }

View File

@ -26,7 +26,8 @@ require( './common' );
var assert = require( 'assert' ), var assert = require( 'assert' ),
Class = require( 'class' ), Class = require( 'class' ),
Interface = require( 'interface' ); Interface = require( 'interface' ),
abstractMethod = Interface.abstractMethod;
var FooType = Interface.extend(); var FooType = Interface.extend();
@ -50,13 +51,26 @@ assert.throws( function()
// properties (non-methods) are not permitted // properties (non-methods) are not permitted
prop: 'not permitted', prop: 'not permitted',
}); });
}, Error, "Only methods are permitted within Interface definitions" ); }, Error, "Properties are not permitted within Interface definitions" );
assert.doesNotThrow( function() assert.throws( function()
{ {
Interface.extend( Interface.extend(
{ {
method: function() {}, // concrete method
method: function() {}
}); });
}, Error, "Method declarations are allowed within Interface definitions" ); }, Error, "Concrete methods are not permitted within Interface definitions" );
assert.doesNotThrow(
function()
{
Interface.extend(
{
method: abstractMethod(),
});
},
Error,
"Abstract method declarations are allowed within Interface definitions"
);