Interfaces permit only abstract methods
parent
2e930482d2
commit
c910dafb76
|
@ -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"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue