1
0
Fork 0

Added static validations for getters/setters

perfodd
Mike Gerwitz 2011-12-22 23:25:35 -05:00
parent db84c6fc6e
commit bcb0bcbe80
2 changed files with 26 additions and 1 deletions

View File

@ -299,6 +299,15 @@ exports.prototype.validateGetterSetter = function(
);
}
// virtual static does not make sense, as static methods cannot be
// overridden
if ( keywords[ 'virtual' ] && ( keywords[ 'static' ] ) )
{
throw TypeError(
"Cannot declare static method '" + name + "' as virtual"
);
}
if ( prev || prev_gs )
{
// perform this check first, as it will make more sense than those that

View File

@ -41,7 +41,7 @@ require( 'common' ).testCase(
{
shared.quickKeywordTest.call( this,
'validateGetterSetter', keywords, identifier, prev,
{ get: function() {}, set: function() {} }
prev && { get: function() {}, set: function() {} }
);
};
@ -198,4 +198,20 @@ require( 'common' ).testCase(
{
this.quickKeywordTest( [ 'override' ], 'non-virtual', [] );
},
'Can declare getter/setter as static': function()
{
this.quickKeywordTest( [ 'static' ] );
},
/**
* As static members cannot be overridden, it does not make sense to permit
* the 'static' and 'virtual' keywords to be used together.
*/
'Cannot declare getter/setter as both static and virtual': function()
{
this.quickKeywordTest( [ 'static', 'virtual' ], 'static' );
},
} );