1
0
Fork 0

Warning no longer issued when overriding weak method appearing later in dfn obj

perfodd
Mike Gerwitz 2014-02-01 23:15:10 -05:00
parent 1b323ed80b
commit 40e287bfc3
2 changed files with 67 additions and 0 deletions

View File

@ -89,6 +89,21 @@ function _addWarn( state, member, id, warn )
} }
/**
* Remove warning from validation state
*
* @param {Object} state validation state
* @param {string} member member name
* @param {string} id warning identifier
*
* @return {undefined}
*/
function _clearWarn( state, member, id, warn )
{
delete ( state.warn[ member ] || {} )[ id ];
}
/** /**
* Validates a method declaration, ensuring that keywords are valid, * Validates a method declaration, ensuring that keywords are valid,
* overrides make sense, etc. * overrides make sense, etc.
@ -260,6 +275,12 @@ exports.prototype.validateMethod = function(
"' without 'override' keyword" "' without 'override' keyword"
); );
} }
// prevent non-override warning
if ( keywords.weak && prev_keywords[ 'override' ] )
{
_clearWarn( state, name, 'no' );
}
} }
else if ( keywords[ 'override' ] ) else if ( keywords[ 'override' ] )
{ {

View File

@ -423,6 +423,52 @@ require( 'common' ).testCase(
}, },
/**
* The above test provides problems if we have a weak method that
* follows the definition of the override within the same definition
* object (that is---A' is defined before A where A' overrides A and A
* is weak); we must ensure that the warning is deferred until we're
* certain that we will not encounter a weak method.
*/
'Does not throw warning when overriding a later weak method': function()
{
var _self = this;
this.warningHandler = function( warning )
{
_self.fail( true, false, "Warning was issued." );
};
this.assertDoesNotThrow( function()
{
var state = {};
// this should place a warning into the state
_self.sut.validateMethod(
'foo',
function() {},
{ 'override': true },
undefined, // no previous because weak was
undefined, // not yet encountered
state
);
// this should remove it upon encountering `weak'
_self.sut.validateMethod(
'foo',
function() {},
{ 'weak': true, 'abstract': true },
{ member: function() {} }, // same as previously defined
{ 'override': true }, // above
state
);
// hopefully we don't trigger warnings (if we do, the warning
// handler defined above will fail this test)
_self.sut.end( state );
} );
},
/** /**
* Wait - what? That doesn't make sense from an OOP perspective, now does * Wait - what? That doesn't make sense from an OOP perspective, now does
* it! Unfortunately, we're forced into this restriction in order to * it! Unfortunately, we're forced into this restriction in order to