diff --git a/lib/class_builder.js b/lib/class_builder.js index d3cf71e..340cdbb 100644 --- a/lib/class_builder.js +++ b/lib/class_builder.js @@ -114,8 +114,15 @@ exports.ClassBase = function Class() {}; * * @return {undefined} */ -exports.ClassBase.$ = function( prop ) +exports.ClassBase.$ = function( prop, val ) { + if ( val !== undefined ) + { + throw ReferenceError( + "Cannot set value of undeclared static property '" + prop + "'" + ); + } + return undefined; }; diff --git a/test/test-class_builder-static.js b/test/test-class_builder-static.js index 360a1f3..d7e1e2e 100644 --- a/test/test-class_builder-static.js +++ b/test/test-class_builder-static.js @@ -396,3 +396,23 @@ var common = require( './common' ), ); } )(); + +/** + * Users should not be permitted to set values of static properties that have + * not been declared. + */ +( function testAttemptingToSetUndeclaredStaticPropertyResultsInException() +{ + assert.throws( + function() + { + // should throw an exception since property 'foo' has not been + // declared + builder.build( {} ).$( 'foo', 'val' ); + }, + ReferenceError, + "Attempting to set an undeclaraed static property results in an " + + "exception" + ); +} )(); +