Abstract methods of subtypes overriding abstract methods must be compatiable with the previous definition
parent
2e8097e21e
commit
2e930482d2
19
lib/util.js
19
lib/util.js
|
@ -255,17 +255,19 @@ function method_override(
|
|||
throw new TypeError( "Cannot override method with non-method" );
|
||||
}
|
||||
|
||||
// if we were given a concrete method to an abstract method,
|
||||
// then the method should no longer be considered abstract
|
||||
if ( ( abstract_map[ name ] !== undefined )
|
||||
&& ( exports.isAbstractMethod( new_method.abstractFlag ) === false )
|
||||
)
|
||||
if ( abstract_map[ name ] !== undefined )
|
||||
{
|
||||
var is_abstract = exports.isAbstractMethod( new_method );
|
||||
|
||||
if ( super_method.definition instanceof Array )
|
||||
{
|
||||
var arg_len = ( is_abstract )
|
||||
? new_method.definition.length
|
||||
: new_method.length;
|
||||
|
||||
// ensure the concrete definition is compatible with
|
||||
// that of its supertype
|
||||
if ( new_method.length < super_method.definition.length )
|
||||
if ( arg_len < super_method.definition.length )
|
||||
{
|
||||
throw new Error(
|
||||
"Declaration of " + name + " must be compatiable" +
|
||||
|
@ -274,9 +276,14 @@ function method_override(
|
|||
}
|
||||
}
|
||||
|
||||
// if this was a concrete method, then it should no longer be marked as
|
||||
// abstract
|
||||
if ( is_abstract === false )
|
||||
{
|
||||
delete abstract_methods[ abstract_map[ name ] ];
|
||||
data.abstractModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
// this is the method that will be invoked when the requested
|
||||
// method is called, so note that in the context of this
|
||||
|
|
|
@ -172,6 +172,30 @@ assert.throws( function()
|
|||
});
|
||||
}, Error, "Concrete methods must implement the proper number of argments" );
|
||||
|
||||
assert.throws( function()
|
||||
{
|
||||
AbstractFoo.extend(
|
||||
{
|
||||
// incorrect number of arguments
|
||||
method: abstractMethod(),
|
||||
});
|
||||
}, Error, "Abstract methods of subtypes must implement the proper number of argments" );
|
||||
|
||||
assert.doesNotThrow(
|
||||
function()
|
||||
{
|
||||
AbstractFoo.extend(
|
||||
{
|
||||
// incorrect number of arguments
|
||||
method: abstractMethod( 'one', 'two', 'three', 'four' ),
|
||||
});
|
||||
},
|
||||
Error,
|
||||
"Abstract methods of subtypes may implement additional arguments, so long" +
|
||||
"as they implement at least the required number of arguments as defined by " +
|
||||
"it supertype"
|
||||
);
|
||||
|
||||
assert.doesNotThrow(
|
||||
function()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue