1
0
Fork 0

Can no longer set values of undeclared static properties

closure/master
Mike Gerwitz 2011-04-13 23:45:26 -04:00
parent 7e53df0e84
commit 462671cfba
2 changed files with 28 additions and 1 deletions

View File

@ -114,8 +114,15 @@ exports.ClassBase = function Class() {};
* *
* @return {undefined} * @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; return undefined;
}; };

View File

@ -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"
);
} )();