[#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
parent
f6369ba2c4
commit
e6830b741f
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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" );
|
||||
} )();
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue