From 994b8e16fa0d2a2ac38cc82c00d4cb7082cf1729 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 7 Dec 2010 00:39:25 -0500 Subject: [PATCH] [1 failing test] Added support for 'each' in propParse() --- lib/util.js | 7 +++++++ test/test-util-prop-parse.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/util.js b/lib/util.js index c8c0109..6bbd593 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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 ) { diff --git a/test/test-util-prop-parse.js b/test/test-util-prop-parse.js index 6191169..6c66740 100644 --- a/test/test-util-prop-parse.js +++ b/test/test-util-prop-parse.js @@ -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" +); +