Removed Interface.abstractMethod() in favor of 'abstract' keyword
parent
44186068b4
commit
928a0ea297
|
@ -36,9 +36,6 @@ exports.extend = function()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.abstractMethod = util.createAbstractMethod;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default interface implementation
|
* Default interface implementation
|
||||||
*
|
*
|
||||||
|
@ -50,13 +47,24 @@ function Interface() {}
|
||||||
function extend()
|
function extend()
|
||||||
{
|
{
|
||||||
var args = Array.prototype.slice.call( arguments ),
|
var args = Array.prototype.slice.call( arguments ),
|
||||||
props = prop_check( args.pop() ) || {},
|
props = args.pop() || {},
|
||||||
base = args.pop() || Interface,
|
base = args.pop() || Interface,
|
||||||
prototype = new base();
|
prototype = new base();
|
||||||
|
|
||||||
var new_interface = function() {};
|
var new_interface = function() {};
|
||||||
|
|
||||||
util.propCopy( props, prototype );
|
util.propCopy( props, prototype, {
|
||||||
|
each: function( name, value )
|
||||||
|
{
|
||||||
|
if ( util.isAbstractMethod( value ) === false )
|
||||||
|
{
|
||||||
|
throw TypeError(
|
||||||
|
"Only abstract methods are permitted within Interface " +
|
||||||
|
"definitons"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} );
|
||||||
|
|
||||||
attach_extend( new_interface );
|
attach_extend( new_interface );
|
||||||
new_interface.prototype = prototype;
|
new_interface.prototype = prototype;
|
||||||
|
@ -69,29 +77,6 @@ function extend()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 ( util.isAbstractMethod( props[ prop ] ) === false )
|
|
||||||
{
|
|
||||||
throw new Error(
|
|
||||||
"Only abstract methods are permitted within Interface definitons"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return props;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches extend method to the given function (interface)
|
* Attaches extend method to the given function (interface)
|
||||||
*
|
*
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
|
|
||||||
var common = require( './common' ),
|
var common = require( './common' ),
|
||||||
assert = require( 'assert' ),
|
assert = require( 'assert' ),
|
||||||
Interface = common.require( 'interface' ),
|
Interface = common.require( 'interface' );
|
||||||
abstractMethod = Interface.abstractMethod;
|
|
||||||
|
|
||||||
|
|
||||||
assert.throws( function()
|
assert.throws( function()
|
||||||
|
@ -35,7 +34,7 @@ assert.throws( function()
|
||||||
// properties (non-methods) are not permitted
|
// properties (non-methods) are not permitted
|
||||||
prop: 'not permitted',
|
prop: 'not permitted',
|
||||||
});
|
});
|
||||||
}, Error, "Properties are not permitted within Interface definitions" );
|
}, TypeError, "Properties are not permitted within Interface definitions" );
|
||||||
|
|
||||||
assert.throws( function()
|
assert.throws( function()
|
||||||
{
|
{
|
||||||
|
@ -44,24 +43,24 @@ assert.throws( function()
|
||||||
// concrete method
|
// concrete method
|
||||||
method: function() {}
|
method: function() {}
|
||||||
});
|
});
|
||||||
}, Error, "Concrete methods are not permitted within Interface definitions" );
|
}, TypeError, "Concrete methods are not permitted within Interface definitions" );
|
||||||
|
|
||||||
assert.doesNotThrow(
|
assert.doesNotThrow(
|
||||||
function()
|
function()
|
||||||
{
|
{
|
||||||
Interface.extend(
|
Interface.extend(
|
||||||
{
|
{
|
||||||
method: abstractMethod(),
|
'abstract method': [],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
Error,
|
TypeError,
|
||||||
"Abstract method declarations are allowed within Interface definitions"
|
"Abstract method declarations are allowed within Interface definitions"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
var BaseType = Interface.extend(
|
var BaseType = Interface.extend(
|
||||||
{
|
{
|
||||||
method: abstractMethod(),
|
'abstract method': [],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
|
@ -72,7 +71,7 @@ assert.ok(
|
||||||
|
|
||||||
var SubType = Interface.extend( BaseType,
|
var SubType = Interface.extend( BaseType,
|
||||||
{
|
{
|
||||||
second: abstractMethod(),
|
'abstract second': [],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
|
@ -99,7 +98,7 @@ assert.ok(
|
||||||
|
|
||||||
var SubType2 = BaseType.extend(
|
var SubType2 = BaseType.extend(
|
||||||
{
|
{
|
||||||
second: abstractMethod(),
|
'abstract second': [],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
|
|
Loading…
Reference in New Issue