From bcb0bcbe803fa2d44e6a6b4c73fa893944042280 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 22 Dec 2011 23:25:35 -0500 Subject: [PATCH] Added static validations for getters/setters --- lib/MemberBuilderValidator.js | 9 +++++++++ .../MemberBuilderValidator/GetterSetterTest.js | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/MemberBuilderValidator.js b/lib/MemberBuilderValidator.js index c0d4f3e..5960f81 100644 --- a/lib/MemberBuilderValidator.js +++ b/lib/MemberBuilderValidator.js @@ -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 diff --git a/test/MemberBuilderValidator/GetterSetterTest.js b/test/MemberBuilderValidator/GetterSetterTest.js index a0e5b6f..db1f4eb 100644 --- a/test/MemberBuilderValidator/GetterSetterTest.js +++ b/test/MemberBuilderValidator/GetterSetterTest.js @@ -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' ); + }, } );