From 2c49e9719f0dd7190ef7e4ec191896a1ece278c4 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sat, 18 Dec 2010 07:07:27 -0500 Subject: [PATCH] util.propParse() now ignores instance prototype properties --- lib/util.js | 6 ++++++ test/test-util-prop-parse.js | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/util.js b/lib/util.js index 9ead1dd..edb446e 100644 --- a/lib/util.js +++ b/lib/util.js @@ -142,6 +142,12 @@ exports.propParse = function( data, options ) // dealing with (in the classic OO sense) for ( prop in data ) { + // ignore properties of instance prototypes + if ( !( data.hasOwnProperty( prop ) ) ) + { + continue; + } + var value = data[ prop ], getter = ( ( getset ) ? data.__lookupGetter__( prop ) : null ), setter = ( ( getset ) ? data.__lookupSetter__( prop ) : null ); diff --git a/test/test-util-prop-parse.js b/test/test-util-prop-parse.js index 9e554e0..d380477 100644 --- a/test/test-util-prop-parse.js +++ b/test/test-util-prop-parse.js @@ -146,3 +146,24 @@ assert.equal( "Property parser supports passing each property to the provided function" ); + +var Foo = function() {}; +Foo.prototype.one = 1; + +var instance = new Foo(); +instance.two = 2; + +var count = 0; +util.propParse( instance, { + each: function() + { + count++; + }, +} ); + +assert.equal( + count, + 1, + "propParse should ignore prototype properties of instances" +); +