1
0
Fork 0

Added tests to ensure that static method overrides are supported

closure/master
Mike Gerwitz 2011-05-11 18:36:49 -04:00
parent 9822894eae
commit a303adddea
2 changed files with 45 additions and 2 deletions

View File

@ -645,8 +645,10 @@ function attachStatic( ctor, members, base, inheriting )
var methods = members.methods,
props = members.props;
// "inherit" the parent's static methods by running the parent's static
// initialization method
// "Inherit" the parent's static methods by running the parent's static
// initialization method. It is important that we do this before anything,
// because this will recursively inherit all members in order, permitting
// overrides.
var baseinit = base.___$$sinit$$;
if ( baseinit )
{

View File

@ -526,3 +526,44 @@ var common = require( './common' ),
);
} )();
/**
* Public and protected static methods should be able to be overridden by
* subtypes. We needn't test private methods, as they are not inherited.
*/
( function testStaticMethodsCanBeOverriddenBySubtypes()
{
var val = 'bar',
Foo = builder.build(
{
'public static foo': function() {},
'protected static bar': function() {},
} ),
SubFoo = builder.build( Foo,
{
'public static foo': function()
{
return val;
},
'public static prot': function()
{
return this.bar();
},
'protected static bar': function()
{
return val;
},
} );
assert.equal( SubFoo.foo(), val,
"Public static methods can be overridden by subtypes"
);
assert.equal( SubFoo.prot(), val,
"Protected static methods can be overridden by subtypes"
);
} )();