1
0
Fork 0

Classes can now access trait protected members

Slight oversight in the original commit.
perfodd
Mike Gerwitz 2014-01-26 03:28:36 -05:00
parent c10fe5e248
commit 987a2b88ec
2 changed files with 29 additions and 3 deletions

View File

@ -268,9 +268,12 @@ function tctor()
T = tc[ t ][ 1 ], T = tc[ t ][ 1 ],
C = T.__ccls || ( T.__ccls = createConcrete( T.__acls ) ); C = T.__ccls || ( T.__ccls = createConcrete( T.__acls ) );
// TODO: pass protected visibility object once we create // instantiate the trait, providing it with our protected visibility
// trait class ctors // object so that it has access to our public and protected members
this[ f ] = C(); // (but not private); in return, we will use its own protected
// visibility object to gain access to its protected members...quite
// the intimate relationship
this[ f ] = C( this.___$$vis$$ ).___$$vis$$;
} }
}; };

View File

@ -126,4 +126,27 @@ require( 'common' ).testCase(
inst.invokePriv(); inst.invokePriv();
}, Error ); }, Error );
}, },
/**
* If this seems odd at first, consider this: traits provide
* copy/paste-style functionality, meaning they need to be able to
* provide public methods. However, we may not always want to mix trait
* features into a public API; therefore, we need the ability to mix in
* protected members.
*/
'Classes can access protected trait members': function()
{
var T = this.Sut( { 'protected foo': function() {} } );
var _self = this;
this.assertDoesNotThrow( function()
{
_self.Class.use( T ).extend(
{
// invokes protected trait method
'public callFoo': function() { this.foo(); }
} )().callFoo();
} );
},
} ); } );