[#25] Refactored common getter/setter code into common method within MemberBuilder
parent
8433511f56
commit
2ba8e2c8f0
|
@ -207,22 +207,9 @@ exports.buildProp = function( members, meta, name, value, keywords, base )
|
||||||
*/
|
*/
|
||||||
exports.buildGetter = function( members, meta, name, value, keywords, base )
|
exports.buildGetter = function( members, meta, name, value, keywords, base )
|
||||||
{
|
{
|
||||||
var prev_data = scanMembers( members, name, base );
|
|
||||||
|
|
||||||
this._validate.validateGetterSetter(
|
this._buildGetterSetter(
|
||||||
name, keywords, prev_data
|
'get', members, meta, name, value, keywords, base
|
||||||
);
|
|
||||||
|
|
||||||
Object.defineProperty(
|
|
||||||
getMemberVisibility( members, keywords, name ),
|
|
||||||
name,
|
|
||||||
{
|
|
||||||
get: value,
|
|
||||||
enumerable: true,
|
|
||||||
|
|
||||||
// otherwise we can't add a setter to this
|
|
||||||
configurable: true,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,6 +233,36 @@ exports.buildGetter = function( members, meta, name, value, keywords, base )
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
exports.buildSetter = function( members, meta, name, value, keywords, base )
|
exports.buildSetter = function( members, meta, name, value, keywords, base )
|
||||||
|
{
|
||||||
|
this._buildGetterSetter(
|
||||||
|
'set', members, meta, name, value, keywords, base
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a getter/setter to the appropriate member prototype, depending on
|
||||||
|
* visibility, and assigns necessary metadata from keywords
|
||||||
|
*
|
||||||
|
* XXX: Combine getter/setter operations for performance benefit
|
||||||
|
*
|
||||||
|
* @param {string} type get/set
|
||||||
|
*
|
||||||
|
* @param {{public: Object, protected: Object, private: Object}} members
|
||||||
|
*
|
||||||
|
* @param {Object} meta metadata container
|
||||||
|
* @param {string} name getter name
|
||||||
|
* @param {*} value getter value
|
||||||
|
*
|
||||||
|
* @param {Object.<string,boolean>} keywords parsed keywords
|
||||||
|
*
|
||||||
|
* @param {Object=} base optional base object to scan
|
||||||
|
*
|
||||||
|
* @return {undefined}
|
||||||
|
*/
|
||||||
|
exports._buildGetterSetter = function(
|
||||||
|
type, members, meta, name, value, keywords, base
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var prev_data = scanMembers( members, name, base );
|
var prev_data = scanMembers( members, name, base );
|
||||||
|
|
||||||
|
@ -253,18 +270,21 @@ exports.buildSetter = function( members, meta, name, value, keywords, base )
|
||||||
name, keywords, prev_data
|
name, keywords, prev_data
|
||||||
);
|
);
|
||||||
|
|
||||||
this._validate.validateGetterSetter( name, members, keywords, base );
|
// the actual data to be set
|
||||||
|
var data = {
|
||||||
Object.defineProperty(
|
|
||||||
getMemberVisibility( members, keywords, name ),
|
|
||||||
name,
|
|
||||||
{
|
|
||||||
set: value,
|
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
|
|
||||||
// otherwise we can't add a getter to this
|
// otherwise we can't add a getter to this
|
||||||
configurable: true,
|
configurable: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// set getter/setter appropriately, depending on the provided type
|
||||||
|
data[ type ] = value;
|
||||||
|
|
||||||
|
Object.defineProperty(
|
||||||
|
getMemberVisibility( members, keywords, name ),
|
||||||
|
name,
|
||||||
|
data
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue