Now storing visibility data in class instance (so GC can clear it)
parent
66758500e6
commit
b2161d1822
46
lib/class.js
46
lib/class.js
|
@ -28,29 +28,6 @@ var util = require( './util' ),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores class instance visibility object
|
|
||||||
*
|
|
||||||
* An entry in this table exists for each instance, with the instance id (iid)
|
|
||||||
* as the key. For each instance, there is always a base. The base will contain
|
|
||||||
* a proxy to the public members on the instance itself. The base will also
|
|
||||||
* contain all protected members.
|
|
||||||
*
|
|
||||||
* Atop the base object is a private member object, with the base as its
|
|
||||||
* prototype. There exists a private member object for the instance itself and
|
|
||||||
* one for each supertype. This is stored by the class id (cid) as the key. This
|
|
||||||
* permits the private member object associated with the class of the method
|
|
||||||
* call to be bound to that method. For example, if a parent method is called,
|
|
||||||
* that call must be invoked in the context of the parent, so the private
|
|
||||||
* members of the parent must be made available.
|
|
||||||
*
|
|
||||||
* The resulting structure looks something like this:
|
|
||||||
* class_instance = { iid: { cid: {} } }
|
|
||||||
*
|
|
||||||
* @type {Object.<number, Object<number, Object>>}
|
|
||||||
*/
|
|
||||||
var class_instance = {};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IE contains a nasty enumeration "bug" (poor implementation) that makes
|
* IE contains a nasty enumeration "bug" (poor implementation) that makes
|
||||||
* toString unenumerable. This means that, if you do obj.toString = foo,
|
* toString unenumerable. This means that, if you do obj.toString = foo,
|
||||||
|
@ -748,6 +725,21 @@ function setupProps( func, abstract_methods, class_id )
|
||||||
* This will be passed to all methods when invoked, permitting them to access
|
* This will be passed to all methods when invoked, permitting them to access
|
||||||
* the private and protected members while keeping them encapsulated.
|
* the private and protected members while keeping them encapsulated.
|
||||||
*
|
*
|
||||||
|
* For each instance, there is always a base. The base will contain a proxy to
|
||||||
|
* the public members on the instance itself. The base will also contain all
|
||||||
|
* protected members.
|
||||||
|
*
|
||||||
|
* Atop the base object is a private member object, with the base as its
|
||||||
|
* prototype. There exists a private member object for the instance itself and
|
||||||
|
* one for each supertype. This is stored by the class id (cid) as the key. This
|
||||||
|
* permits the private member object associated with the class of the method
|
||||||
|
* call to be bound to that method. For example, if a parent method is called,
|
||||||
|
* that call must be invoked in the context of the parent, so the private
|
||||||
|
* members of the parent must be made available.
|
||||||
|
*
|
||||||
|
* The resulting structure looks something like this:
|
||||||
|
* class_instance = { iid: { cid: {} } }
|
||||||
|
*
|
||||||
* @param {number} iid instance id
|
* @param {number} iid instance id
|
||||||
* @param {Object} instance instance to initialize
|
* @param {Object} instance instance to initialize
|
||||||
*
|
*
|
||||||
|
@ -759,7 +751,7 @@ function initInstance( iid, instance )
|
||||||
prot.prototype = instance;
|
prot.prototype = instance;
|
||||||
|
|
||||||
// add the visibility objects to the data object for this class instance
|
// add the visibility objects to the data object for this class instance
|
||||||
class_instance[ iid ] = new prot();
|
instance.___$$vis$$ = new prot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -805,12 +797,12 @@ function attachPropInit( prototype, properties, members, cid )
|
||||||
// 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[ iid ], properties[ 'public' ]
|
this, this.___$$vis$$, 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)
|
||||||
class_instance[ iid ][ cid ] = propobj.setup(
|
this.___$$vis$$[ cid ] = propobj.setup(
|
||||||
inst_props, properties, members
|
inst_props, properties, members
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1012,7 +1004,7 @@ function getMeta( cls )
|
||||||
function getMethodInstance( inst, cid )
|
function getMethodInstance( inst, cid )
|
||||||
{
|
{
|
||||||
var iid = inst.__iid,
|
var iid = inst.__iid,
|
||||||
data = class_instance[ iid ];
|
data = inst.___$$vis$$;
|
||||||
|
|
||||||
return ( iid && data )
|
return ( iid && data )
|
||||||
? data[ cid ]
|
? data[ cid ]
|
||||||
|
|
Loading…
Reference in New Issue