1
0
Fork 0

Static property setter now returns calling class

closure/master
Mike Gerwitz 2011-04-13 23:35:54 -04:00
parent e3c526b89d
commit 7e53df0e84
2 changed files with 35 additions and 4 deletions

View File

@ -621,13 +621,18 @@ function attachStatic( ctor, members, base, inheriting )
// cause us to continue checking the parent, thereby potentially
// failing to set perfectly legal values
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 ( !has )
{
return base.$.apply( this, arguments );
return base.$.apply( context, arguments );
}
// if a value was provided, this method should be treated as a
@ -635,7 +640,7 @@ function attachStatic( ctor, members, base, inheriting )
if ( val )
{
props[ 'public' ][ prop ] = val;
return;
return context;
}
else
{

View File

@ -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"
);
} )();