Getters/setters can no longer override properties
parent
c83def013a
commit
fb155d8df5
|
@ -361,10 +361,14 @@ function validateGetterSetter( members, keywords, name, base )
|
||||||
|
|
||||||
if ( prev )
|
if ( prev )
|
||||||
{
|
{
|
||||||
if ( typeof prev === 'function' )
|
// To speed up the system we'll simply check for a getter/setter, rather
|
||||||
|
// than checking separately for methods/properties. This is at the
|
||||||
|
// expense of more detailed error messages. They'll live.
|
||||||
|
if ( !( prev_data.get || prev_data.set ) )
|
||||||
{
|
{
|
||||||
throw TypeError(
|
throw TypeError(
|
||||||
"Cannot override method '" + name + "' with getter/setter"
|
"Cannot override method or property '" + name +
|
||||||
|
"' with getter/setter"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,10 +434,15 @@ function scanMembers( members, name, base )
|
||||||
// locate requested member by scanning each level of visibility
|
// locate requested member by scanning each level of visibility
|
||||||
while ( i-- )
|
while ( i-- )
|
||||||
{
|
{
|
||||||
if ( member = members[ visibility[ i ] ][ name ] )
|
var visobj = members[ visibility[ i ] ];
|
||||||
|
|
||||||
|
// in order to support getters/setters, we must go off of the descriptor
|
||||||
|
if ( member = util.getPropertyDescriptor( visobj, name ) )
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
member: member,
|
get: member.get,
|
||||||
|
set: member.set,
|
||||||
|
member: member.value,
|
||||||
visibility: ( ( fallback ) ? 0 : i ),
|
visibility: ( ( fallback ) ? 0 : i ),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,3 +231,33 @@ testEach( function testCannotOverrideMethodWithGetterOrSetter( type, build )
|
||||||
assert.fail( type + " should not be able to override methods");
|
assert.fail( type + " should not be able to override methods");
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getters/setters should not be able to override properties. While, at first,
|
||||||
|
* this concept may seem odd, keep in mind that the parent would likely not
|
||||||
|
* expect a subtype to be able to override property assignments. This could open
|
||||||
|
* up holes to exploit the parent class.
|
||||||
|
*/
|
||||||
|
testEach( function testCannotOverridePropertiesWithGetterOrSetter( type, build )
|
||||||
|
{
|
||||||
|
setUp();
|
||||||
|
|
||||||
|
// declare a property
|
||||||
|
members[ 'public' ][ name ] = 'foo';
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// attempt to override property with getter/setter (should fail)
|
||||||
|
build( { 'public': true }, null, true );
|
||||||
|
}
|
||||||
|
catch ( e )
|
||||||
|
{
|
||||||
|
assert.ok( e.message.search( name ) !== -1,
|
||||||
|
"Property override error message should contain getter/setter name"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.fail( type + " should not be able to override properties" );
|
||||||
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue