1
0
Fork 0

Methods can no longer be overridden with non-methods (anything other than a Function)

closure/master
Mike Gerwitz 2010-11-10 23:42:26 -05:00
parent c34f40db19
commit 16a91b728e
2 changed files with 18 additions and 2 deletions

View File

@ -73,6 +73,7 @@ function prop_copy( props, dest )
// 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 );
@ -92,6 +93,12 @@ function prop_copy( props, dest )
// check for method overrides
else if ( ( pre !== undefined ) && ( pre instanceof Function ) )
{
// ensure we're overriding the method with another method
if ( !( prop instanceof Function ) )
{
throw new TypeError( "Cannot override method with non-method" );
}
dest[ property ] = ( function( method, super_method )
{
// this is the method that will be invoked when the requested
@ -109,11 +116,11 @@ function prop_copy( props, dest )
return retval;
}
})( props[ property ], dest[ property ] );
})( prop, dest[ property ] );
}
else
{
dest[ property ] = props[ property ];
dest[ property ] = prop;
}
}
}

View File

@ -118,3 +118,12 @@ assert.equal(
"The parent property may also be used to invoke parent methods"
);
assert.throws( function()
{
Foo.extend(
{
// overriding method with scalar; shouldn't be allowed
myMethod: 'scalar',
});
}, TypeError, "Methods must be overridden with a Function" );