Re-encapsulated ClassBuilder private symbol
Temporary method removed and symbol now provided directly to the trait ctor; this is needed to retrieve the protected visibility object; there is currently no API for doing so, and there may never be (providing an API for such a thing seems questionable). Of course, if we eventually want to decouple the trait implementation from ClassBuilder (which would be a good idea), we'll have to figure out something.protolib
parent
13b0bd2fb3
commit
17d11c1832
|
@ -882,7 +882,7 @@ exports.prototype.createConcreteCtor = function( cname, members )
|
||||||
// handle internal trait initialization logic, if provided
|
// handle internal trait initialization logic, if provided
|
||||||
if ( typeof this.___$$tctor$$ === 'function' )
|
if ( typeof this.___$$tctor$$ === 'function' )
|
||||||
{
|
{
|
||||||
this.___$$tctor$$.call( this );
|
this.___$$tctor$$.call( this, _priv );
|
||||||
}
|
}
|
||||||
|
|
||||||
// call the constructor, if one was provided
|
// call the constructor, if one was provided
|
||||||
|
@ -1233,10 +1233,6 @@ exports.prototype.attachStatic = function( ctor, members, base, inheriting )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FIXME: this is *temporary* during refactoring!
|
|
||||||
module.exports.___$$privsym$$ = _priv;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes class metadata for the given class
|
* Initializes class metadata for the given class
|
||||||
*
|
*
|
||||||
|
|
20
lib/Trait.js
20
lib/Trait.js
|
@ -673,16 +673,20 @@ function addTraitInst( T, dfn, tc, base )
|
||||||
* This will lazily create the concrete trait class if it does not already
|
* This will lazily create the concrete trait class if it does not already
|
||||||
* exist, which saves work if the trait is never used.
|
* exist, which saves work if the trait is never used.
|
||||||
*
|
*
|
||||||
|
* Note that the private symbol used to encapsulate class data must be
|
||||||
|
* passed to this function to provide us access to implementation details
|
||||||
|
* that we really shouldn't be messing around with. :) In particular, we
|
||||||
|
* need access to the protected visibility object, and there is [currently]
|
||||||
|
* no API for doing so.
|
||||||
|
*
|
||||||
* @param {Object} tc trait class list
|
* @param {Object} tc trait class list
|
||||||
* @param {Class} base target supertype
|
* @param {Class} base target supertype
|
||||||
|
* @param {Symbol} privsym symbol used as key for encapsulated data
|
||||||
*
|
*
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
function tctor( tc, base )
|
function tctor( tc, base, privsym )
|
||||||
{
|
{
|
||||||
// FIXME: this is temporary during refactoring!
|
|
||||||
var cbpriv = ClassBuilder.___$$privsym$$;
|
|
||||||
|
|
||||||
// instantiate all traits and assign the object to their
|
// instantiate all traits and assign the object to their
|
||||||
// respective fields
|
// respective fields
|
||||||
for ( var t in tc )
|
for ( var t in tc )
|
||||||
|
@ -696,11 +700,11 @@ function tctor( tc, base )
|
||||||
// (but not private); in return, we will use its own protected
|
// (but not private); in return, we will use its own protected
|
||||||
// visibility object to gain access to its protected members...quite
|
// visibility object to gain access to its protected members...quite
|
||||||
// the intimate relationship
|
// the intimate relationship
|
||||||
this[ f ] = C( base, this[ cbpriv ].vis )[ cbpriv ].vis;
|
this[ f ] = C( base, this[ privsym ].vis )[ privsym ].vis;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we are a subtype, be sure to initialize our parent's traits
|
// if we are a subtype, be sure to initialize our parent's traits
|
||||||
this.__super && this.__super();
|
this.__super && this.__super( privsym );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -717,9 +721,9 @@ function tctor( tc, base )
|
||||||
*/
|
*/
|
||||||
function createTctor( tc, base )
|
function createTctor( tc, base )
|
||||||
{
|
{
|
||||||
return function()
|
return function( privsym )
|
||||||
{
|
{
|
||||||
return tctor.call( this, tc, base );
|
return tctor.call( this, tc, base, privsym );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue