Added static validations for getters/setters
parent
db84c6fc6e
commit
bcb0bcbe80
|
@ -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
|
||||
|
|
|
@ -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' );
|
||||
},
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue