[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;
|
abstract_map[ method ] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy each of the properties to the destination object
|
function attempt_override( name, pre, func, data )
|
||||||
for ( property in props )
|
|
||||||
{
|
{
|
||||||
// if the property already exists, then it's being overridden (we only
|
if ( pre instanceof Function )
|
||||||
// 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 ( getter )
|
return method_override(
|
||||||
{
|
|
||||||
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(
|
|
||||||
pre,
|
pre,
|
||||||
prop,
|
func,
|
||||||
property,
|
name,
|
||||||
abstract_map,
|
abstract_map,
|
||||||
abstract_methods,
|
abstract_methods,
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( data.abstractModified )
|
|
||||||
{
|
|
||||||
abstract_regen = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// just copy over the property
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if we were given an abstract method, add it to our list of
|
// todo: attempted override of property with abstract method
|
||||||
// abstract methods
|
return null;
|
||||||
if ( ( prop instanceof Function ) && ( prop.abstractFlag === true ) )
|
|
||||||
{
|
|
||||||
abstract_methods.push( property );
|
|
||||||
}
|
|
||||||
|
|
||||||
dest[ property ] = prop;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// should we regenerate the array of abstract methods? (this must be done
|
||||||
// because the length of the array remains the same after deleting elements)
|
// because the length of the array remains the same after deleting elements)
|
||||||
if ( abstract_regen )
|
if ( abstract_regen )
|
||||||
|
|
Loading…
Reference in New Issue