1
0
Fork 0

Refactored method validations into separate method

closure/master
Mike Gerwitz 2011-05-22 11:25:03 -04:00
parent 9690663d1c
commit b359906aa3
1 changed files with 46 additions and 26 deletions

View File

@ -76,6 +76,49 @@ exports.buildMethod = function(
// every time this method is called // every time this method is called
var prev_data = scanMembers( members, name, base ), var prev_data = scanMembers( members, name, base ),
prev = ( prev_data ) ? prev_data.member : null, prev = ( prev_data ) ? prev_data.member : null,
dest = getMemberVisibility( members, keywords );
;
// ensure that the declaration is valid (keywords make sense, argument
// length, etc)
validateMethod( keywords, prev_data, value, name );
// we might be overriding an existing method
if ( prev )
{
// override the method
dest[ name ] = overrideMethod( prev, value, instCallback, cid );
}
else if ( keywords[ 'abstract' ] )
{
// we do not want to wrap abstract methods, since they are not callable
dest[ name ] = value;
}
else
{
// we are not overriding the method, so simply copy it over, wrapping it
// to ensure privileged calls will work properly
dest[ name ] = overrideMethod( value, null, instCallback, cid );
}
// store keywords for later reference (needed for pre-ES5 fallback)
dest[ name ].___$$keywords$$ = keywords;
};
/**
* Validates a method declaration, ensuring that keywords are valid, overrides
* make sense, etc.
*
* @param {Object.<string,boolean>} keywords parsed keywords
*
* @param {Object} prev_data data of member being overridden, if available
* @param {*} value property value
* @param {string} name property name
*/
function validateMethod( keywords, prev_data, value, name )
{
var prev = ( prev_data ) ? prev_data.member : null,
prev_keywords = ( prev && prev.___$$keywords$$ ) prev_keywords = ( prev && prev.___$$keywords$$ )
? prev.___$$keywords$$ ? prev.___$$keywords$$
: {} : {}
@ -155,30 +198,7 @@ exports.buildMethod = function(
); );
} }
} }
var dest = getMemberVisibility( members, keywords );
// we might be overriding an existing method
if ( prev )
{
// override the method
dest[ name ] = overrideMethod( prev, value, instCallback, cid );
} }
else if ( keywords[ 'abstract' ] )
{
// we do not want to wrap abstract methods, since they are not callable
dest[ name ] = value;
}
else
{
// we are not overriding the method, so simply copy it over, wrapping it
// to ensure privileged calls will work properly
dest[ name ] = overrideMethod( value, null, instCallback, cid );
}
// store keywords for later reference (needed for pre-ES5 fallback)
dest[ name ].___$$keywords$$ = keywords;
};
/** /**