Only methods are permitted within interface declarations
parent
b294f84481
commit
2edcb8a75e
|
@ -47,7 +47,7 @@ function Interface() {}
|
||||||
function extend()
|
function extend()
|
||||||
{
|
{
|
||||||
var args = Array.prototype.slice.call( arguments ),
|
var args = Array.prototype.slice.call( arguments ),
|
||||||
props = args.pop() || {},
|
props = prop_check( args.pop() ) || {},
|
||||||
base = args.pop() || Interface,
|
base = args.pop() || Interface,
|
||||||
prototype = new base();
|
prototype = new base();
|
||||||
|
|
||||||
|
@ -62,3 +62,26 @@ function extend()
|
||||||
return new_interface;
|
return new_interface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to ensure that only methods are being declared
|
||||||
|
*
|
||||||
|
* @param {Object} props interface definition
|
||||||
|
*
|
||||||
|
* @return {Object} the same properties that were passed to the function
|
||||||
|
*/
|
||||||
|
function prop_check( props )
|
||||||
|
{
|
||||||
|
for ( prop in props )
|
||||||
|
{
|
||||||
|
if ( !( props[ prop ] instanceof Function ) )
|
||||||
|
{
|
||||||
|
throw new Error(
|
||||||
|
"Only methods are permitted within Interface definitons"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,8 @@ var assert = require( 'assert' ),
|
||||||
Class = require( 'class' ),
|
Class = require( 'class' ),
|
||||||
Interface = require( 'interface' );
|
Interface = require( 'interface' );
|
||||||
|
|
||||||
var FooType = Interface.extend(
|
var FooType = Interface.extend();
|
||||||
{
|
|
||||||
foo: function( foo, bar ) {},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
( FooType instanceof Object ),
|
( FooType instanceof Object ),
|
||||||
|
@ -44,3 +42,21 @@ assert.equal(
|
||||||
"Generated interface object should be frozen"
|
"Generated interface object should be frozen"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
assert.throws( function()
|
||||||
|
{
|
||||||
|
Interface.extend(
|
||||||
|
{
|
||||||
|
// properties (non-methods) are not permitted
|
||||||
|
prop: 'not permitted',
|
||||||
|
});
|
||||||
|
}, Error, "Only methods are permitted within Interface definitions" );
|
||||||
|
|
||||||
|
assert.doesNotThrow( function()
|
||||||
|
{
|
||||||
|
Interface.extend(
|
||||||
|
{
|
||||||
|
method: function() {},
|
||||||
|
});
|
||||||
|
}, Error, "Method declarations are allowed within Interface definitions" );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue