From 928a0ea297909244cac933a40770f78761ab897e Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 28 Dec 2010 20:13:50 -0500 Subject: [PATCH] Removed Interface.abstractMethod() in favor of 'abstract' keyword --- lib/interface.js | 41 +++++++++++------------------------ test/test-interface-extend.js | 21 +++++++++--------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/lib/interface.js b/lib/interface.js index 9ae38d2..473304c 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -36,9 +36,6 @@ exports.extend = function() } -exports.abstractMethod = util.createAbstractMethod; - - /** * Default interface implementation * @@ -50,13 +47,24 @@ function Interface() {} function extend() { var args = Array.prototype.slice.call( arguments ), - props = prop_check( args.pop() ) || {}, + props = args.pop() || {}, base = args.pop() || Interface, prototype = new base(); 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 ); 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) * diff --git a/test/test-interface-extend.js b/test/test-interface-extend.js index e5b6604..efa3236 100644 --- a/test/test-interface-extend.js +++ b/test/test-interface-extend.js @@ -22,10 +22,9 @@ * @package test */ -var common = require( './common' ), - assert = require( 'assert' ), - Interface = common.require( 'interface' ), - abstractMethod = Interface.abstractMethod; +var common = require( './common' ), + assert = require( 'assert' ), + Interface = common.require( 'interface' ); assert.throws( function() @@ -35,7 +34,7 @@ assert.throws( function() // properties (non-methods) are not permitted prop: 'not permitted', }); -}, Error, "Properties are not permitted within Interface definitions" ); +}, TypeError, "Properties are not permitted within Interface definitions" ); assert.throws( function() { @@ -44,24 +43,24 @@ assert.throws( function() // concrete method method: function() {} }); -}, Error, "Concrete methods are not permitted within Interface definitions" ); +}, TypeError, "Concrete methods are not permitted within Interface definitions" ); assert.doesNotThrow( function() { Interface.extend( { - method: abstractMethod(), + 'abstract method': [], }); }, - Error, + TypeError, "Abstract method declarations are allowed within Interface definitions" ); var BaseType = Interface.extend( { - method: abstractMethod(), + 'abstract method': [], }); assert.ok( @@ -72,7 +71,7 @@ assert.ok( var SubType = Interface.extend( BaseType, { - second: abstractMethod(), + 'abstract second': [], }); assert.ok( @@ -99,7 +98,7 @@ assert.ok( var SubType2 = BaseType.extend( { - second: abstractMethod(), + 'abstract second': [], }); assert.ok(