Class ___$$meta$$ moved into private symbol field
parent
e0866db313
commit
a35a9c6ed3
|
@ -26,6 +26,7 @@
|
|||
|
||||
var util = require( './util' ),
|
||||
Warning = require( './warn' ).Warning,
|
||||
Symbol = require( './util/Symbol' ),
|
||||
|
||||
hasOwn = Object.prototype.hasOwnProperty,
|
||||
|
||||
|
@ -73,7 +74,18 @@ var util = require( './util' ),
|
|||
'__construct': true,
|
||||
'toString': true,
|
||||
'__toString': true,
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Symbol used to encapsulate internal data
|
||||
*
|
||||
* Note that this is intentionally generated *outside* the ClassBuilder
|
||||
* instance; this ensures that it is properly encapsulated and will not
|
||||
* be exposed on the Classbuilder instance (which would defeat the
|
||||
* purpose).
|
||||
*/
|
||||
_priv = Symbol()
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -225,7 +237,7 @@ exports.getForcedPublicMethods = function()
|
|||
*/
|
||||
exports.getMeta = function( cls )
|
||||
{
|
||||
return cls.___$$meta$$ || {};
|
||||
return ( cls[ _priv ] || {} ).meta || {};
|
||||
}
|
||||
|
||||
|
||||
|
@ -342,7 +354,7 @@ exports.prototype.build = function extend( _, __ )
|
|||
{
|
||||
throw Error(
|
||||
"Cannot extend final class " +
|
||||
( base.___$$meta$$.name || '(anonymous)' )
|
||||
( base[ _priv ].meta.name || '(anonymous)' )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -799,16 +811,19 @@ function validateAbstract( ctor, cname, abstract_methods, auto )
|
|||
*/
|
||||
exports.prototype.createCtor = function( cname, abstract_methods, members )
|
||||
{
|
||||
// concrete class
|
||||
var new_class;
|
||||
|
||||
if ( abstract_methods.__length === 0 )
|
||||
{
|
||||
return this.createConcreteCtor( cname, members );
|
||||
new_class = this.createConcreteCtor( cname, members );
|
||||
}
|
||||
// abstract class
|
||||
else
|
||||
{
|
||||
return this.createAbstractCtor( cname );
|
||||
new_class = this.createAbstractCtor( cname );
|
||||
}
|
||||
|
||||
new_class[ _priv ] = {};
|
||||
return new_class;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1239,21 +1254,27 @@ function createMeta( func, cparent )
|
|||
// copy the parent prototype's metadata if it exists (inherit metadata)
|
||||
if ( parent_meta )
|
||||
{
|
||||
func.___$$meta$$ = util.clone( parent_meta, true );
|
||||
func[ _priv ].meta = util.clone( parent_meta, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
// create empty
|
||||
func.___$$meta$$ = {
|
||||
func[ _priv ].meta = {
|
||||
implemented: [],
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: this should be done elsewhere
|
||||
if ( !func.prototype[ _priv ] )
|
||||
{
|
||||
func.prototype[ _priv ] = {};
|
||||
}
|
||||
|
||||
// store the metadata in the prototype as well (inconsiderable overhead;
|
||||
// it's just a reference)
|
||||
func.prototype.___$$meta$$ = func.___$$meta$$;
|
||||
func.prototype[ _priv ].meta = func[ _priv ].meta;
|
||||
|
||||
return func.___$$meta$$;
|
||||
return func[ _priv ].meta;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue