diff --git a/lib/member_builder.js b/lib/member_builder.js index 559e6bc..f47cb4c 100644 --- a/lib/member_builder.js +++ b/lib/member_builder.js @@ -74,8 +74,51 @@ exports.buildMethod = function( { // TODO: We can improve performance by not scanning each one individually // every time this method is called - var prev_data = scanMembers( members, name, base ), - prev = ( prev_data ) ? prev_data.member : null, + var prev_data = scanMembers( members, name, base ), + 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.} 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$$ : {} @@ -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; -}; +} /**