define_secure_prop moved to util.defineSecureProp
parent
2edcb8a75e
commit
c29bd010b0
46
lib/class.js
46
lib/class.js
|
@ -22,7 +22,7 @@
|
||||||
* @package core
|
* @package core
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var propCopy = require( './util' ).propCopy,
|
var util = require( './util' ),
|
||||||
can_freeze = require( './util' ).canFreeze();
|
can_freeze = require( './util' ).canFreeze();
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,8 +60,8 @@ exports.abstractMethod = function( definition )
|
||||||
throw new Error( "Cannot call abstract method" );
|
throw new Error( "Cannot call abstract method" );
|
||||||
};
|
};
|
||||||
|
|
||||||
define_secure_prop( method, 'abstractFlag', true );
|
util.defineSecureProp( method, 'abstractFlag', true );
|
||||||
define_secure_prop( method, 'definition', definition );
|
util.defineSecureProp( method, 'definition', definition );
|
||||||
|
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ var extend = ( function( extending )
|
||||||
var result_data = {
|
var result_data = {
|
||||||
abstractMethods: ( base.abstractMethods || [] ).slice()
|
abstractMethods: ( base.abstractMethods || [] ).slice()
|
||||||
};
|
};
|
||||||
propCopy( props, prototype, result_data );
|
util.propCopy( props, prototype, result_data );
|
||||||
|
|
||||||
// reference to the parent prototype (for more experienced users)
|
// reference to the parent prototype (for more experienced users)
|
||||||
prototype.parent = base.prototype;
|
prototype.parent = base.prototype;
|
||||||
|
@ -198,38 +198,6 @@ function setup_props( func, class_data )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to define a non-enumerable, non-writable and non-configurable
|
|
||||||
* property on the given object
|
|
||||||
*
|
|
||||||
* If the operation is unsupported, a normal property will be set.
|
|
||||||
*
|
|
||||||
* @param {Object} obj object to set property on
|
|
||||||
* @param {string} prop name of property to set
|
|
||||||
* @param {mixed} value value to set
|
|
||||||
*
|
|
||||||
* @return {undefined}
|
|
||||||
*/
|
|
||||||
function define_secure_prop( obj, prop, value )
|
|
||||||
{
|
|
||||||
if ( Object.defineProperty === undefined )
|
|
||||||
{
|
|
||||||
func[ prop ] = value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Object.defineProperty( obj, prop,
|
|
||||||
{
|
|
||||||
value: value,
|
|
||||||
|
|
||||||
enumerable: false,
|
|
||||||
writable: false,
|
|
||||||
configurable: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches isAbstract() method to the class
|
* Attaches isAbstract() method to the class
|
||||||
*
|
*
|
||||||
|
@ -248,7 +216,7 @@ function attach_abstract( func, methods )
|
||||||
*
|
*
|
||||||
* @return {Boolean} true if class is abstract, otherwise false
|
* @return {Boolean} true if class is abstract, otherwise false
|
||||||
*/
|
*/
|
||||||
define_secure_prop( func, 'isAbstract', function()
|
util.defineSecureProp( func, 'isAbstract', function()
|
||||||
{
|
{
|
||||||
return is_abstract;
|
return is_abstract;
|
||||||
});
|
});
|
||||||
|
@ -256,7 +224,7 @@ function attach_abstract( func, methods )
|
||||||
// attach the list of abstract methods to the class (make the copy of the
|
// attach the list of abstract methods to the class (make the copy of the
|
||||||
// methods to ensure that they won't be gc'd or later modified and screw up
|
// methods to ensure that they won't be gc'd or later modified and screw up
|
||||||
// the value)
|
// the value)
|
||||||
define_secure_prop( func, 'abstractMethods', methods );
|
util.defineSecureProp( func, 'abstractMethods', methods );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,7 +247,7 @@ function attach_extend( func )
|
||||||
*
|
*
|
||||||
* @return {Object} extended class
|
* @return {Object} extended class
|
||||||
*/
|
*/
|
||||||
define_secure_prop( func, 'extend', function( props )
|
util.defineSecureProp( func, 'extend', function( props )
|
||||||
{
|
{
|
||||||
return extend( this, props );
|
return extend( this, props );
|
||||||
});
|
});
|
||||||
|
|
32
lib/util.js
32
lib/util.js
|
@ -47,6 +47,38 @@ exports.canFreeze = function()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to define a non-enumerable, non-writable and non-configurable
|
||||||
|
* property on the given object
|
||||||
|
*
|
||||||
|
* If the operation is unsupported, a normal property will be set.
|
||||||
|
*
|
||||||
|
* @param {Object} obj object to set property on
|
||||||
|
* @param {string} prop name of property to set
|
||||||
|
* @param {mixed} value value to set
|
||||||
|
*
|
||||||
|
* @return {undefined}
|
||||||
|
*/
|
||||||
|
exports.defineSecureProp = function( obj, prop, value )
|
||||||
|
{
|
||||||
|
if ( Object.defineProperty === undefined )
|
||||||
|
{
|
||||||
|
func[ prop ] = value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Object.defineProperty( obj, prop,
|
||||||
|
{
|
||||||
|
value: value,
|
||||||
|
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies properties to the destination object
|
* Copies properties to the destination object
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue