Added tests to ensure that static method overrides are supported
parent
9822894eae
commit
a303adddea
|
@ -645,8 +645,10 @@ function attachStatic( ctor, members, base, inheriting )
|
||||||
var methods = members.methods,
|
var methods = members.methods,
|
||||||
props = members.props;
|
props = members.props;
|
||||||
|
|
||||||
// "inherit" the parent's static methods by running the parent's static
|
// "Inherit" the parent's static methods by running the parent's static
|
||||||
// initialization method
|
// 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$$;
|
var baseinit = base.___$$sinit$$;
|
||||||
if ( baseinit )
|
if ( baseinit )
|
||||||
{
|
{
|
||||||
|
|
|
@ -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"
|
||||||
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue