1
0
Fork 0

Added abstract method support to propParse()

closure/master
Mike Gerwitz 2010-12-04 14:03:26 -05:00
parent 4037cc1343
commit 6fd31a8e76
2 changed files with 30 additions and 10 deletions

View File

@ -96,9 +96,10 @@ exports.defineSecureProp = function( obj, prop, value )
*/ */
exports.propParse = function( data, options ) exports.propParse = function( data, options )
{ {
var callback_prop = options.property || function() {}, var callback_prop = options.property || function() {},
callback_method = options.method || function() {}, callback_method = options.method || function() {},
callback = null; callback_abstract_method = options.abstractMethod || function() {},
callback = null;
// for each of the given properties, determine what type of property we're // for each of the given properties, determine what type of property we're
// dealing with (in the classic OO sense) // dealing with (in the classic OO sense)
@ -108,7 +109,11 @@ exports.propParse = function( data, options )
if ( value instanceof Function ) if ( value instanceof Function )
{ {
callback = callback_method; // concrete or abstract?
callback = ( exports.isAbstractMethod( value ) )
? callback_abstract_method
: callback_method
;
} }
else else
{ {

View File

@ -24,8 +24,8 @@
require( './common' ); require( './common' );
var assert = require( 'assert' ), var assert = require( 'assert' ),
propParse = require( '../lib/util' ).propParse; util = require( '../lib/util' );
var data = { var data = {
// scalars (properties) // scalars (properties)
@ -42,13 +42,17 @@ var data = {
// concrete method // concrete method
method: function() {}, method: function() {},
// abstract method
abstractMethod: util.createAbstractMethod(),
}; };
var props = {}, var props = {},
methods = {}; methods = {},
amethods = {};
propParse( data, { util.propParse( data, {
property: function( name, value ) property: function( name, value )
{ {
props[ name ] = value; props[ name ] = value;
@ -59,6 +63,11 @@ propParse( data, {
{ {
methods[ name ] = method; methods[ name ] = method;
}, },
abstractMethod: function( name, def )
{
amethods[ name ] = def;
}
} ); } );
@ -76,6 +85,12 @@ propParse( data, {
assert.equal( assert.equal(
methods.method, methods.method,
data.method, data.method,
"Property parser properly detects methods" "Property parser properly detects concrete methods"
);
assert.equal(
amethods.abstractMethod,
data.abstractMethod,
"Property parser properly detects abstract methods"
); );