1
0
Fork 0

[1 failing test] Added support for 'each' in propParse()

closure/master
Mike Gerwitz 2010-12-07 00:39:25 -05:00
parent abefb0858b
commit 994b8e16fa
2 changed files with 36 additions and 0 deletions

View File

@ -97,6 +97,7 @@ exports.defineSecureProp = function( obj, prop, value )
exports.propParse = function( data, options )
{
var fvoid = function() {},
callback_each = options.each || undefined,
callback_prop = options.property || fvoid,
callback_method = options.method || fvoid,
callback_abstract_method = options.abstractMethod || fvoid,
@ -112,6 +113,12 @@ exports.propParse = function( data, options )
getter = ( ( getset ) ? data.__lookupGetter__( prop ) : null ),
setter = ( ( getset ) ? data.__lookupSetter__( prop ) : null );
// if an 'each' callback was provided, pass the data before parsing it
if ( callback_each )
{
callback_each( prop, value );
}
// getter/setter
if ( getter || setter )
{

View File

@ -51,6 +51,12 @@ var data = {
abstractMethod: util.createAbstractMethod(),
};
var chk_each = {};
for ( item in data )
{
chk_each[ item ] = 1;
}
var props = {},
methods = {},
@ -59,6 +65,16 @@ var props = {},
setters = {};
util.propParse( data, {
// run for each item in data
each: function( name, value )
{
// only remove if the passed value is correct
if ( value === data[ name ] )
{
delete chk_each[ name ];
}
},
property: function( name, value )
{
props[ name ] = value;
@ -122,3 +138,16 @@ assert.equal(
"Property parser properly detects setters"
);
var chk_each_count = 0;
for ( item in chk_each )
{
chk_each_count++;
}
assert.equal(
chk_each_count,
0,
"Property parser supports passing each property to the provided function"
);