Static property setter now returns calling class
parent
e3c526b89d
commit
7e53df0e84
|
@ -621,13 +621,18 @@ function attachStatic( ctor, members, base, inheriting )
|
||||||
// cause us to continue checking the parent, thereby potentially
|
// cause us to continue checking the parent, thereby potentially
|
||||||
// failing to set perfectly legal values
|
// failing to set perfectly legal values
|
||||||
var has = Object.prototype.hasOwnProperty.call(
|
var has = Object.prototype.hasOwnProperty.call(
|
||||||
props[ 'public' ], prop
|
props[ 'public' ], prop
|
||||||
);
|
),
|
||||||
|
|
||||||
|
// Determine if we were invoked in the context of a class. If
|
||||||
|
// so, use that. Otherwise, use ourself.
|
||||||
|
context = ( this.___$$sprops$$ ) ? this : ctor
|
||||||
|
;
|
||||||
|
|
||||||
// if we don't own the property, let the parent(s) handle it
|
// if we don't own the property, let the parent(s) handle it
|
||||||
if ( !has )
|
if ( !has )
|
||||||
{
|
{
|
||||||
return base.$.apply( this, arguments );
|
return base.$.apply( context, arguments );
|
||||||
}
|
}
|
||||||
|
|
||||||
// if a value was provided, this method should be treated as a
|
// if a value was provided, this method should be treated as a
|
||||||
|
@ -635,7 +640,7 @@ function attachStatic( ctor, members, base, inheriting )
|
||||||
if ( val )
|
if ( val )
|
||||||
{
|
{
|
||||||
props[ 'public' ][ prop ] = val;
|
props[ 'public' ][ prop ] = val;
|
||||||
return;
|
return context;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -370,3 +370,29 @@ var common = require( './common' ),
|
||||||
);
|
);
|
||||||
} )();
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that the proper context is returned by static property setters. It
|
||||||
|
* should return the calling class, regardless of whether or not it owns the
|
||||||
|
* property being requested.
|
||||||
|
*/
|
||||||
|
( function testStaticPropertySettersReturnProperContext()
|
||||||
|
{
|
||||||
|
var Foo = builder.build(
|
||||||
|
{
|
||||||
|
'public static foo': '',
|
||||||
|
} ),
|
||||||
|
|
||||||
|
SubFoo = builder.build( Foo, {} )
|
||||||
|
;
|
||||||
|
|
||||||
|
assert.ok( Foo.$( 'foo', 'val' ) === Foo,
|
||||||
|
"Static property setter returns self"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.ok( SubFoo.$( 'foo', 'val' ) === SubFoo,
|
||||||
|
"Static property setter returns calling class, even if property is " +
|
||||||
|
"owned by a supertype"
|
||||||
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue