1
0
Fork 0

[#25] Now using keywords to compare visibility levels in validations to eliminiate fallback inconsistencies

Ironic, considering the current refactoring (not yet committed) of MemberBuilder to split validation logic into MemberBuilderValidator was partially to be able to easily override the fallback logic. It's a useful refactoring nonetheless, but it could have waited.
closure/master
Mike Gerwitz 2011-10-22 00:32:59 -04:00
parent f6369ba2c4
commit e6830b741f
2 changed files with 9 additions and 17 deletions

View File

@ -29,10 +29,7 @@
*/
var util = require( __dirname + '/util' ),
Warning = require( __dirname + '/warn' ).Warning,
fallback = util.definePropertyFallback(),
visibility = [ 'public', 'protected', 'private' ]
;
@ -244,7 +241,9 @@ exports._validateMethod = function(
}
// do not permit visibility deescalation
if ( prev_data.visibility < this._getVisibilityValue( keywords ) )
if ( this._getVisibilityValue( prev_keywords ) <
this._getVisibilityValue( keywords )
)
{
throw TypeError(
"Cannot de-escalate visibility of method '" + name + "'"
@ -311,7 +310,9 @@ exports.buildProp = function( members, meta, name, value, keywords, base )
// do not permit visibility de-escalation
if ( prev &&
( prev_data.visibility < this._getVisibilityValue( keywords ) )
( this._getVisibilityValue( prev[ 1 ] )
< this._getVisibilityValue( keywords )
)
)
{
throw TypeError(
@ -521,7 +522,6 @@ function scanMembers( members, name, base )
get: member.get,
set: member.set,
member: member.value,
visibility: ( ( fallback ) ? 0 : i ),
};
}
}
@ -613,12 +613,7 @@ exports._overrideMethod = function(
*/
exports._getVisibilityValue = function( keywords )
{
if ( fallback )
{
// if we have to fall back, we don't support levels of visibility
return 0;
}
else if ( keywords[ 'protected' ] )
if ( keywords[ 'protected' ] )
{
return 1;
}

View File

@ -524,8 +524,6 @@ var common = require( './common' ),
}, Error, "Can escalate visibility of subtype members" );
// same level of visibility
assert.doesNotThrow( function()
{
Class(
{
'protected foo': 'bar',
@ -534,7 +532,6 @@ var common = require( './common' ),
'protected foo': 'bar',
'override protected baz': function() {},
} );
}, Error, "Can retain level of visibility for subtype members" );
} )();