1
0
Fork 0

The `weak' keyword can now apply to overrides

Well, technically anything, but we're leaving that behavior as undefined for
now (the documentation will say the same thing).
perfodd
Mike Gerwitz 2014-01-29 00:20:08 -05:00
parent b04a8473b8
commit dac4b9b3a1
3 changed files with 55 additions and 8 deletions

View File

@ -140,19 +140,19 @@ exports.buildMethod = function(
}
else if ( prev )
{
if ( keywords[ 'override' ] || prev_keywords[ 'abstract' ] )
if ( keywords.weak )
{
// another member of the same name has been found; discard the
// weak declaration
return false;
}
else if ( keywords[ 'override' ] || prev_keywords[ 'abstract' ] )
{
// override the method
dest[ name ] = this._overrideMethod(
prev, value, instCallback, cid
);
}
else if ( keywords.weak && keywords[ 'abstract' ] )
{
// another member of the same name has been found; discard the
// weak declaration
return false;
}
else
{
// by default, perform method hiding, even if the keyword was not

View File

@ -187,7 +187,7 @@ exports.prototype.validateMethod = function(
// warning to default to method hiding. Note the check for a
if ( !( keywords[ 'override' ]
|| prev_keywords[ 'abstract' ]
|| ( keywords[ 'abstract' ] && keywords.weak )
|| keywords.weak
) )
{
throw TypeError(

View File

@ -231,4 +231,51 @@ require( 'common' ).testCase(
this.members[ 'public' ].foo();
this.assertOk( called, "Concrete method unkept" );
},
/**
* Same concept as the above, but with virtual methods (which have a
* concrete implementation available by default).
*/
'Weak virtual methods are not processed if override is available':
function()
{
var _self = this,
called = false,
cid = 1,
name = 'foo',
oval = function() { called = true; },
vval = function()
{
_self.fail( true, false, "Method not overridden." );
},
okeywords = { 'override': true },
vkeywords = { weak: true, 'virtual': true },
instCallback = function() {}
;
// define the virtual method
this.assertOk( this.sut.buildMethod(
this.members, {}, name, vval, vkeywords, instCallback, cid, {}
) );
// override should take precedence
this.assertOk( this.sut.buildMethod(
this.members, {}, name, oval, okeywords, instCallback, cid, {}
) );
this.members[ 'public' ].foo();
this.assertOk( called, "Override did not take precedence" );
// now try virtual again to ensure this works from both directions
this.assertOk( this.sut.buildMethod(
this.members, {}, name, vval, vkeywords, instCallback, cid, {}
) === false );
this.members[ 'public' ].foo();
this.assertOk( called, "Override unkept" );
},
} );