1
0
Fork 0

If a definition is provided for an abstract method, the concrete implementation must be compatiable (proper number of arguments)

closure/master
Mike Gerwitz 2010-11-14 21:33:13 -05:00
parent e0657e1c44
commit d4593725a4
2 changed files with 41 additions and 0 deletions

View File

@ -64,6 +64,8 @@ exports.abstractMethod = function( definition )
};
define_secure_prop( method, 'abstractFlag', true );
define_secure_prop( method, 'definition', definition );
return method;
}
@ -135,6 +137,19 @@ function prop_copy( props, dest, result_data )
// then the method should no longer be considered abstract
if ( abstract_map[ property ] !== undefined )
{
if ( pre.definition )
{
// ensure the concrete definition is compatible with
// that of its supertype
if ( prop.length < pre.definition.length )
{
throw new Error(
"Declaration of " + property + " must be compatiable" +
"with that of its supertype"
);
}
}
delete abstract_methods[ abstract_map[ property ] ];
abstract_regen = true;
}

View File

@ -158,3 +158,29 @@ assert.equal(
"Can call constructors of abstract supertypes"
);
assert.throws( function()
{
AbstractFoo.extend(
{
// incorrect number of arguments
method: function()
{
},
});
}, Error, "Concrete methods must implement the proper number of argments" );
assert.doesNotThrow(
function()
{
AbstractFoo.extend(
{
second: function( foo )
{
},
});
}, Error,
"Concrete methods needn't implement the proper number of arguments if " +
"no definition was provided"
);