[1 failing test] Crude beginning of implementation of propParse()
- Looks ugly now because it is. Attempting to refactor before doing a proper implementation. Baby steps.closure/master
parent
fd2b3ccc6d
commit
abefb0858b
113
lib/util.js
113
lib/util.js
|
@ -177,63 +177,88 @@ exports.propCopy = function( props, dest, result_data )
|
|||
abstract_map[ method ] = i;
|
||||
}
|
||||
|
||||
// copy each of the properties to the destination object
|
||||
for ( property in props )
|
||||
function attempt_override( name, pre, func, data )
|
||||
{
|
||||
// if the property already exists, then it's being overridden (we only
|
||||
// care about methods - properties will simply have their values
|
||||
// overwritten)
|
||||
var pre = dest[ property ],
|
||||
prop = props[ property ],
|
||||
getter = ( ( getset ) ? props.__lookupGetter__( property ) : null ),
|
||||
setter = ( ( getset ) ? props.__lookupSetter__( property ) : null );
|
||||
|
||||
// check for getter/setter overrides
|
||||
if ( getter || setter )
|
||||
if ( pre instanceof Function )
|
||||
{
|
||||
if ( getter )
|
||||
{
|
||||
dest.__defineGetter__( property, getter );
|
||||
}
|
||||
|
||||
if ( setter )
|
||||
{
|
||||
dest.__defineSetter__( property, setter );
|
||||
}
|
||||
}
|
||||
// check for method overrides
|
||||
else if ( ( pre !== undefined ) && ( pre instanceof Function ) )
|
||||
{
|
||||
var data = { abstractModified: false };
|
||||
|
||||
dest[ property ] = method_override(
|
||||
return method_override(
|
||||
pre,
|
||||
prop,
|
||||
property,
|
||||
func,
|
||||
name,
|
||||
abstract_map,
|
||||
abstract_methods,
|
||||
data
|
||||
);
|
||||
|
||||
if ( data.abstractModified )
|
||||
{
|
||||
abstract_regen = true;
|
||||
}
|
||||
}
|
||||
// just copy over the property
|
||||
else
|
||||
{
|
||||
// if we were given an abstract method, add it to our list of
|
||||
// abstract methods
|
||||
if ( ( prop instanceof Function ) && ( prop.abstractFlag === true ) )
|
||||
{
|
||||
abstract_methods.push( property );
|
||||
}
|
||||
|
||||
dest[ property ] = prop;
|
||||
// todo: attempted override of property with abstract method
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// default functionality
|
||||
var actions = {
|
||||
property: function( name, value )
|
||||
{
|
||||
dest[ name ] = value;
|
||||
},
|
||||
|
||||
getter: function( name, func )
|
||||
{
|
||||
dest.__defineGetter__( name, func );
|
||||
},
|
||||
|
||||
setter: function( name, func )
|
||||
{
|
||||
dest.__defineSetter__( name, func );
|
||||
},
|
||||
|
||||
abstractMethod: function( name, def )
|
||||
{
|
||||
var data = { abstractModified: false },
|
||||
pre = dest[ name ];
|
||||
|
||||
// check for override
|
||||
if ( pre !== undefined )
|
||||
{
|
||||
dest[ name ] = attempt_override( name, pre, def, data );
|
||||
if ( data.abstractModified )
|
||||
{
|
||||
abstract_regen = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
abstract_methods.push( name );
|
||||
dest[ name ] = def;
|
||||
}
|
||||
},
|
||||
|
||||
method: function( name, func )
|
||||
{
|
||||
var data = { abstractModified: false },
|
||||
pre = dest[ name ];
|
||||
|
||||
// check for override
|
||||
if ( pre !== undefined )
|
||||
{
|
||||
dest[ name ] = attempt_override( name, pre, func, data );
|
||||
if ( data.abstractModified )
|
||||
{
|
||||
abstract_regen = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// simply copy over the method
|
||||
dest[ name ] = func;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
exports.propParse( props, actions );
|
||||
|
||||
// should we regenerate the array of abstract methods? (this must be done
|
||||
// because the length of the array remains the same after deleting elements)
|
||||
if ( abstract_regen )
|
||||
|
|
Loading…
Reference in New Issue