1
0
Fork 0

Corrected a bug whereby getters were being inadvertently invoked by util.propParse()

Nasty; hopefully this was found before it did any harm to anyone else! This bug was discovered accidentally while I was debugging a separate issue.
perfodd
Mike Gerwitz 2013-01-19 19:54:48 -05:00
parent 02e22e64b9
commit 8b74ed9f1b
No known key found for this signature in database
GPG Key ID: F22BB8158EE30EAB
2 changed files with 17 additions and 4 deletions

View File

@ -297,7 +297,11 @@ exports.propParse = function( data, options )
setter = prop_desc.set; setter = prop_desc.set;
} }
value = data[ prop ]; // do not attempt to retrieve the value if a getter is defined (as that
// would then call the getter)
value = ( typeof getter === 'function' )
? undefined
: data[ prop ];
parse_data = keywordParser( prop ) || {}; parse_data = keywordParser( prop ) || {};
name = parse_data.name || prop; name = parse_data.name || prop;

View File

@ -51,11 +51,13 @@ var data = {
'proxy someProxy': 'dest', 'proxy someProxy': 'dest',
}; };
get_called = false;
// only add getter/setter if it's supported by our engine // only add getter/setter if it's supported by our engine
if ( get_set ) if ( get_set )
{ {
Object.defineProperty( data, 'someFoo', { Object.defineProperty( data, 'someFoo', {
get: function () {}, get: function () { get_called = true; },
set: function () {}, set: function () {},
enumerable: true, enumerable: true,
@ -80,8 +82,10 @@ util.propParse( data, {
// run for each item in data // run for each item in data
each: function( name, value ) each: function( name, value )
{ {
// only remove if the passed value is correct // only remove if the passed value is correct (note the check for
if ( value === data[ name ] ) // 'someFoo', since this has a getter and checking its value would
// invoke the getter, which would taint one of the tests)
if ( ( name === 'someFoo' ) || ( value === data[ name ] ) )
{ {
delete chk_each[ name ]; delete chk_each[ name ];
} }
@ -158,6 +162,11 @@ if ( get_set )
data.__lookupSetter__( 'someFoo' ), data.__lookupSetter__( 'someFoo' ),
"Property parser properly detects setters" "Property parser properly detects setters"
); );
// bug fix
assert.equal( false, get_called,
"Getter should not be called during processing"
);
} }