1
0
Fork 0

[#25] Began refactoring getter/setter building into a single method (util.propParse)

I'm unsure as to why I originally placed them in separate methods. propParse() will
always find a getter at the same time it finds a setter, and vice versa, should they
both have been defined on the object.
closure/master
Mike Gerwitz 2011-10-29 08:08:02 -04:00
parent 2ba8e2c8f0
commit 02cd52cfb7
6 changed files with 21 additions and 40 deletions

View File

@ -465,21 +465,16 @@ exports.prototype.buildMembers = function buildMembers(
); );
}, },
getter: function( name, value, keywords ) getset: function( name, get, set, keywords )
{ {
var dest = ( keywordStatic( keywords ) ) ? smethods : members; var dest = ( keywordStatic( keywords ) ) ? smethods : members;
_self._memberBuilder.buildGetter( _self._memberBuilder.buildGetter(
dest, null, name, value, keywords, base dest, null, name, get, keywords, base
); );
},
setter: function( name, value, keywords )
{
var dest = ( keywordStatic( keywords ) ) ? smethods : members;
_self._memberBuilder.buildSetter( _self._memberBuilder.buildSetter(
dest, null, name, value, keywords, base dest, null, name, set, keywords, base
); );
}, },

View File

@ -209,19 +209,11 @@ var extend = ( function( extending )
); );
}, },
getter: function() getset: function()
{ {
throw TypeError( throw TypeError(
"Getter not permitter within definition of Interface '" + "Getters/setters are not permitter within definition " +
iname + "'" "of Interface '" + iname + "'"
);
},
setter: function()
{
throw TypeError(
"Setter within definition of Interface '" +
iname + "'"
); );
}, },

View File

@ -261,8 +261,7 @@ exports.propParse = function( data, options )
callbackEach = options.each || undefined, callbackEach = options.each || undefined,
callbackProp = options.property || fvoid, callbackProp = options.property || fvoid,
callbackMethod = options.method || fvoid, callbackMethod = options.method || fvoid,
callbackGetter = options.getter || fvoid, callbackGetSet = options.getset || fvoid,
callbackSetter = options.setter || fvoid,
keywordParser = options.keywordParser || propParseKeywords, keywordParser = options.keywordParser || propParseKeywords,
hasOwn = Object.prototype.hasOwnProperty, hasOwn = Object.prototype.hasOwnProperty,
@ -319,8 +318,9 @@ exports.propParse = function( data, options )
// getter/setter // getter/setter
if ( getter || setter ) if ( getter || setter )
{ {
callbackGetter.call( callbackGetter, name, getter, keywords ); callbackGetSet.call( callbackGetSet,
callbackSetter.call( callbackSetter, name, setter, keywords ); name, getter, setter, keywords
);
} }
// method // method
else if ( value instanceof Function ) else if ( value instanceof Function )

View File

@ -203,9 +203,6 @@ var common = require( './common' ),
{ {
// cause the error // cause the error
tries[ i ](); tries[ i ]();
// we shouldn't get to this point...
assert.fail( "Expected error. Something's wrong." );
} }
catch ( e ) catch ( e )
{ {
@ -215,7 +212,12 @@ var common = require( './common' ),
null, null,
"Error contains interface name when available (" + i + ")" "Error contains interface name when available (" + i + ")"
); );
return;
} }
// we shouldn't get to this point...
assert.fail( "Expected error. Something's wrong: " + i );
} }
} )(); } )();

View File

@ -190,14 +190,10 @@ var common = require( './common' ),
util.propParse( data, { util.propParse( data, {
getter: function( name, value, keywords ) getset: function( name, get, set, keywords )
{ {
parsed_keywords[ name + 'g' ] = keywords; get && ( parsed_keywords[ name + 'g' ] = keywords );
}, set && ( parsed_keywords[ name + 's' ] = keywords );
setter: function( name, value, keywords )
{
parsed_keywords[ name + 's' ] = keywords;
}, },
} ); } );

View File

@ -96,15 +96,11 @@ util.propParse( data, {
to[ name ] = method; to[ name ] = method;
}, },
getter: function( name, func ) getset: function( name, get, set )
{ {
getters[ name ] = func; getters[ name ] = get;
setters[ name ] = set;
}, },
setter: function( name, func )
{
setters[ name ] = func;
}
} ); } );