1
0
Fork 0

[#25] Moved public default getter/setter test to new location

closure/master
Mike Gerwitz 2011-10-27 20:21:07 -04:00
parent a959e99b06
commit f19a62e733
3 changed files with 41 additions and 46 deletions

View File

@ -191,6 +191,8 @@ exports.buildProp = function( members, meta, name, value, keywords, base )
* Copies a getter to the appropriate member prototype, depending on * Copies a getter to the appropriate member prototype, depending on
* visibility, and assigns necessary metadata from keywords * visibility, and assigns necessary metadata from keywords
* *
* XXX: Combine with buildSetter for performance benefit
*
* @param {{public: Object, protected: Object, private: Object}} members * @param {{public: Object, protected: Object, private: Object}} members
* *
* @param {Object} meta metadata container * @param {Object} meta metadata container
@ -225,6 +227,8 @@ exports.buildGetter = function( members, meta, name, value, keywords, base )
* Copies a setter to the appropriate member prototype, depending on * Copies a setter to the appropriate member prototype, depending on
* visibility, and assigns necessary metadata from keywords * visibility, and assigns necessary metadata from keywords
* *
* XXX: Combine with buildGetter for performance benefit
*
* @param {{public: Object, protected: Object, private: Object}} members * @param {{public: Object, protected: Object, private: Object}} members
* *
* @param {Object} meta metadata container * @param {Object} meta metadata container

View File

@ -22,6 +22,10 @@
* @package test * @package test
*/ */
// get-set-test (supported)
var gst = ( typeof Object.defineProperty === 'function' ) ? true : false;
require( 'common' ).testCase( require( 'common' ).testCase(
{ {
caseSetUp: function() caseSetUp: function()
@ -133,7 +137,7 @@ require( 'common' ).testCase(
{ {
// we cannot perform these tests if getters/setters are unsupported // we cannot perform these tests if getters/setters are unsupported
// by our environment // by our environment
if ( typeof Object.defineProperty !== 'function' ) if ( !gst )
{ {
return; return;
} }
@ -297,7 +301,11 @@ require( 'common' ).testCase(
'Members will be declared public if access modifier is omitted': function() 'Members will be declared public if access modifier is omitted': function()
{ {
var name_prop = 'prop', val_prop = 'foo', var name_prop = 'prop', val_prop = 'foo',
name_method = 'method', val_method = function() {} name_method = 'method', val_method = function() {},
name_gs = 'getset',
getval = function() {},
setval = function() {}
; ;
this.sut.buildProp( this.members, {}, name_prop, val_prop, {}, {} ); this.sut.buildProp( this.members, {}, name_prop, val_prop, {}, {} );
@ -305,6 +313,13 @@ require( 'common' ).testCase(
{}, function() {}, 1, {} {}, function() {}, 1, {}
); );
// getter/setter if supported
if ( gst )
{
this.sut.buildGetter( this.members, {}, name_gs, getval, {}, {} );
this.sut.buildSetter( this.members, {}, name_gs, setval, {}, {} );
}
this.assertStrictEqual( this.assertStrictEqual(
this.members[ 'public' ][ name_prop ][ 0 ], this.members[ 'public' ][ name_prop ][ 0 ],
val_prop, val_prop,
@ -316,6 +331,26 @@ require( 'common' ).testCase(
val_method, val_method,
'Methods should be public by default' 'Methods should be public by default'
); );
// getter/setter if supported
if ( gst )
{
var data = Object.getOwnPropertyDescriptor(
this.members[ 'public' ], name_gs
);
this.assertStrictEqual(
data.get,
getval,
'Getters should be public by default'
);
this.assertStrictEqual(
data.set,
setval,
'Setters should be public by default'
);
}
}, },

View File

@ -96,50 +96,6 @@ function testEach( test )
} }
/**
* Asserts that the given property exists only in the prototype for the
* requested visibility
*/
function assertOnlyVisibility( vis, name, value, message )
{
var check = [ 'public', 'protected', 'private' ],
i = check.length,
visi = '',
cmp;
// forEach not used for pre-ES5 browser support
while ( i-- )
{
visi = check[ i ];
cmp = ( visi === vis ) ? value : undefined;
assert.deepEqual(
members[ visi ].__lookupGetter__( name ),
cmp,
( message + " (0)" )
);
assert.deepEqual(
members[ visi ].__lookupSetter__( name ),
cmp,
( message + " (1)" )
);
}
}
( function testCopiedIntoPublicPrototypeByDefault()
{
buildGetterSetterQuick();
assertOnlyVisibility( 'public',
name,
value,
"Properties are copied only to the public member prototype by default"
);
} )();
( function testThrowsTypeErrorIfMultipleVisibilityKeywordsAreGiven() ( function testThrowsTypeErrorIfMultipleVisibilityKeywordsAreGiven()
{ {
assert.throws( function() assert.throws( function()