If a definition is provided for an abstract method, the concrete implementation must be compatiable (proper number of arguments)
parent
e0657e1c44
commit
d4593725a4
15
lib/class.js
15
lib/class.js
|
@ -64,6 +64,8 @@ exports.abstractMethod = function( definition )
|
||||||
};
|
};
|
||||||
|
|
||||||
define_secure_prop( method, 'abstractFlag', true );
|
define_secure_prop( method, 'abstractFlag', true );
|
||||||
|
define_secure_prop( method, 'definition', definition );
|
||||||
|
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +137,19 @@ function prop_copy( props, dest, result_data )
|
||||||
// then the method should no longer be considered abstract
|
// then the method should no longer be considered abstract
|
||||||
if ( abstract_map[ property ] !== undefined )
|
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 ] ];
|
delete abstract_methods[ abstract_map[ property ] ];
|
||||||
abstract_regen = true;
|
abstract_regen = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,3 +158,29 @@ assert.equal(
|
||||||
"Can call constructors of abstract supertypes"
|
"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"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue