Can no longer override getters/setters with properties
parent
394b4981bf
commit
5065525f0d
|
@ -240,6 +240,14 @@ exports.buildProp = function( members, meta, name, value, keywords, base )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do not allow overriding getters/setters
|
||||||
|
if ( prev_data && ( prev_data.get || prev_data.set ) )
|
||||||
|
{
|
||||||
|
throw TypeError(
|
||||||
|
"Cannot override getter/setter '" + name + "' with property"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// do not permit visibility de-escalation
|
// do not permit visibility de-escalation
|
||||||
if ( prev && ( prev_data.visibility < getVisibilityValue( keywords ) ) )
|
if ( prev && ( prev_data.visibility < getVisibilityValue( keywords ) ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,3 +66,75 @@ mb_common.assertCommon();
|
||||||
}, TypeError, "Cannot declare abstract property" );
|
}, TypeError, "Cannot declare abstract property" );
|
||||||
} )();
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* While getters act as properties, it doesn't make sense to override
|
||||||
|
* getters/setters with properties because they are fundamentally different.
|
||||||
|
*/
|
||||||
|
( function testCannotOverrideGetters()
|
||||||
|
{
|
||||||
|
mb_common.members[ 'public' ] = {};
|
||||||
|
Object.defineProperty( mb_common.members[ 'public' ], mb_common.name, {
|
||||||
|
get: function() {},
|
||||||
|
} );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mb_common.value = 'foo';
|
||||||
|
mb_common.buildMemberQuick( {}, true );
|
||||||
|
}
|
||||||
|
catch ( e )
|
||||||
|
{
|
||||||
|
assert.ok( e.message.search( mb_common.name ) !== -1,
|
||||||
|
"Property override getter failure should contain property name"
|
||||||
|
);
|
||||||
|
|
||||||
|
// ensure we have the correct error
|
||||||
|
assert.ok( e.message.search( 'getter' ) !== -1,
|
||||||
|
"Proper error is thrown for getter override failure"
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.fail(
|
||||||
|
"Should not be permitted to override getters with properties"
|
||||||
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* While setters act as properties, it doesn't make sense to override
|
||||||
|
* getters/setters with properties because they are fundamentally different.
|
||||||
|
*/
|
||||||
|
( function testCannotOverrideSetters()
|
||||||
|
{
|
||||||
|
mb_common.members[ 'public' ] = {};
|
||||||
|
Object.defineProperty( mb_common.members[ 'public' ], mb_common.name, {
|
||||||
|
set: function() {},
|
||||||
|
} );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mb_common.value = 'foo';
|
||||||
|
mb_common.buildMemberQuick( {}, true );
|
||||||
|
}
|
||||||
|
catch ( e )
|
||||||
|
{
|
||||||
|
assert.ok( e.message.search( mb_common.name ) !== -1,
|
||||||
|
"Property override setter failure should contain method name"
|
||||||
|
);
|
||||||
|
|
||||||
|
// ensure we have the correct error
|
||||||
|
assert.ok( e.message.search( 'setter' ) !== -1,
|
||||||
|
"Proper error is thrown for setter override failure"
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.fail(
|
||||||
|
"Should not be permitted to override setters with properties"
|
||||||
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue