1
0
Fork 0

Storing each supertype's private members in a separate object to prepare for future change

- sid = super identifier
closure/master
Mike Gerwitz 2011-03-13 03:55:43 -04:00
parent 6b374902ae
commit e4e8900a9f
2 changed files with 15 additions and 34 deletions

View File

@ -774,10 +774,13 @@ function initInstance( iid, instance )
*/ */
function attachPropInit( prototype, properties, members ) function attachPropInit( prototype, properties, members )
{ {
util.defineSecureProp( prototype, '__initProps', function( inherit ) util.defineSecureProp( prototype, '__initProps', function( inherit, sid )
{ {
// defaults to false // defaults to false, sid = super identifier
inherit = !!inherit; inherit = !!inherit;
sid = ( sid ) ? +sid : 0;
var iid = this.__iid;
// first initialize the parent's properties, so that ours will overwrite // first initialize the parent's properties, so that ours will overwrite
// them // them
@ -787,22 +790,20 @@ function attachPropInit( prototype, properties, members )
// call the parent prop_init, letting it know that it's been // call the parent prop_init, letting it know that it's been
// inherited so that it does not initialize private members or // inherited so that it does not initialize private members or
// perform other unnecessary tasks // perform other unnecessary tasks
parent_init.call( this, true ); parent_init.call( this, true, ( sid + 1 ) );
} }
// this will return our property proxy, if supported by our environment, // this will return our property proxy, if supported by our environment,
// otherwise just a normal object with everything merged in // otherwise just a normal object with everything merged in
var inst_props = propobj.createPropProxy( var inst_props = propobj.createPropProxy(
this, class_instance[ this.__iid ], properties[ 'public' ] this, class_instance[ iid ], properties[ 'public' ]
); );
// if we're inheriting, perform a setup that doesn't include everything // if we're inheriting, perform a setup that doesn't include everything
// that we don't want (e.g. private properties) // that we don't want (e.g. private properties)
var setup = ( inherit ) class_instance[ iid ][ sid ] = propobj.setup(
? propobj.setupInherited inst_props, properties, members, sid
: propobj.setup );
;
class_instance[ this.__iid ] = setup( inst_props, properties, members );
}); });
} }
@ -993,7 +994,7 @@ function getMethodInstance( method )
data = class_instance[ method.__iid ]; data = class_instance[ method.__iid ];
return ( iid && data ) return ( iid && data )
? data ? data[ 0 ]
: null : null
; ;
} }

View File

@ -30,28 +30,6 @@ var util = require( './util' ),
; ;
/**
* Sets up properties when inheriting
*
* This does not include private members.
*
* @param {Object} dest destination object
* @param {Object} properties properties to copy
* @param {Object=} methods methods to copy
*
* @return {Object} dest
*/
exports.setupInherited = function( dest, properties, methods )
{
// initialize each of the properties for this instance to
// ensure we're not sharing references to prototype values
doSetup( dest, properties[ 'public' ] );
doSetup( dest, properties[ 'protected' ], methods[ 'protected'] );
return dest;
};
/** /**
* Sets up properties (non-inheriting) * Sets up properties (non-inheriting)
* *
@ -75,8 +53,10 @@ exports.setup = function( dest, properties, methods )
var obj = new obj_ctor(); var obj = new obj_ctor();
// first, set up the public and protected members // initialize each of the properties for this instance to
exports.setupInherited( dest, properties, methods ); // ensure we're not sharing references to prototype values
doSetup( dest, properties[ 'public' ] );
doSetup( dest, properties[ 'protected' ], methods[ 'protected'] );
// then add the private parts // then add the private parts
doSetup( obj, properties[ 'private' ], methods[ 'private' ] ); doSetup( obj, properties[ 'private' ], methods[ 'private' ] );