1
0
Fork 0

[#19] Cannot declare virtual properties

closure/master
Mike Gerwitz 2011-06-09 19:46:13 -04:00
parent 7f24d094ba
commit 08dc2559b4
2 changed files with 32 additions and 0 deletions

View File

@ -251,6 +251,12 @@ exports.buildProp = function( members, meta, name, value, keywords, base )
);
}
// properties are inherently virtual
if ( keywords['virtual'] )
{
throw TypeError( "Cannot declare property '" + name + "' as virtual" );
}
getMemberVisibility( members, keywords )[ name ] = [ value, keywords ];
};

View File

@ -66,3 +66,29 @@ mb_common.assertCommon();
}, TypeError, "Cannot declare abstract property" );
} )();
/**
* Properties, unlike methods, are virtual by default. If a property's value can
* be reassigned, why would a subclass not be able to reassign it? If one wishes
* to prevent a property's value from changing, they should use the visibility
* modifiers or declare the property as a constant.
*/
( function testCannotDeclareVirtualProperty()
{
try
{
mb_common.buildMemberQuick( { 'virtual': true } );
}
catch ( e )
{
assert.ok(
e.message.search( mb_common.name ) !== -1,
"Virtual property error message should contain property name"
);
return;
}
assert.fail( "Should not be permitted to declare virtual properties" );
} )();