From 5b6a0c0bb5b571a0d604368073d458146959315f Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 24 May 2015 00:27:46 -0400 Subject: [PATCH] "lazy" metadata support --- lib/ClassBuilder.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/ClassBuilder.js b/lib/ClassBuilder.js index 59c961e..3b716c6 100644 --- a/lib/ClassBuilder.js +++ b/lib/ClassBuilder.js @@ -351,14 +351,15 @@ exports.prototype.build = function extend( _, __ ) props: this._memberBuilder.initMembers(), }, - meta = exports.getMeta( base ) || {}, + // constructor may be different than base + pmeta = exports.getMeta( prototype.constructor ) || {}, abstract_methods = - util.clone( meta.abstractMethods ) + util.clone( pmeta.abstractMethods ) || { __length: 0 }, virtual_members = - util.clone( meta.virtualMembers ) + util.clone( pmeta.virtualMembers ) || {} ; @@ -476,7 +477,7 @@ exports.prototype.build = function extend( _, __ ) util.defineSecureProp( prototype, '__self', new_class.___$$svis$$ ); // create internal metadata for the new class - var meta = createMeta( new_class, base ); + var meta = createMeta( new_class, base, pmeta ); meta.abstractMethods = abstract_methods; meta.virtualMembers = virtual_members; meta.name = cname; @@ -1267,18 +1268,23 @@ exports.prototype.attachStatic = function( ctor, members, base, inheriting ) /** * Initializes class metadata for the given class * + * DYNMETA is used only when CPARENT's metadata are flagged as "lazy", + * meaning that the data are not available at the time of its definition, + * but are available now as DYNMETA. + * * @param {Function} func class to initialize metadata for * @param {Function} cparent class parent + * @param {?Object} dynmeta dynamic metadata * * @return {undefined} * * Suppressed due to warnings for use of __cid * @suppress {checkTypes} */ -function createMeta( func, cparent ) +function createMeta( func, cparent, dynmeta ) { var id = func.__cid, - parent_meta = ( ( cparent.__cid ) + parent_meta = ( cparent[ _priv ] ? exports.getMeta( cparent ) : undefined ); @@ -1286,7 +1292,13 @@ function createMeta( func, cparent ) // copy the parent prototype's metadata if it exists (inherit metadata) if ( parent_meta ) { - return func[ _priv ].meta = util.clone( parent_meta, true ); + return func[ _priv ].meta = util.clone( + // "lazy" metadata are unavailable at the time of definition + parent_meta._lazy + ? dynmeta + : parent_meta, + true + ); } // create empty