From 17d11c1832ef58604251ee2a722203125c957c83 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 7 Jul 2014 00:20:37 -0400 Subject: [PATCH] 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. --- lib/ClassBuilder.js | 6 +----- lib/Trait.js | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/ClassBuilder.js b/lib/ClassBuilder.js index 2657e8b..3a6f8a9 100644 --- a/lib/ClassBuilder.js +++ b/lib/ClassBuilder.js @@ -882,7 +882,7 @@ exports.prototype.createConcreteCtor = function( cname, members ) // handle internal trait initialization logic, if provided if ( typeof this.___$$tctor$$ === 'function' ) { - this.___$$tctor$$.call( this ); + this.___$$tctor$$.call( this, _priv ); } // 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 * diff --git a/lib/Trait.js b/lib/Trait.js index cec7875..4bd17c2 100644 --- a/lib/Trait.js +++ b/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 * exist, which saves work if the trait is never used. * - * @param {Object} tc trait class list - * @param {Class} base target supertype + * 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 {Class} base target supertype + * @param {Symbol} privsym symbol used as key for encapsulated data * * @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 // respective fields for ( var t in tc ) @@ -696,11 +700,11 @@ function tctor( tc, base ) // (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( 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 - this.__super && this.__super(); + this.__super && this.__super( privsym ); }; @@ -717,9 +721,9 @@ function tctor( tc, base ) */ function createTctor( tc, base ) { - return function() + return function( privsym ) { - return tctor.call( this, tc, base ); + return tctor.call( this, tc, base, privsym ); }; }