Using visibility fallback for browsers that do not support getters/setters
parent
df2943b5a1
commit
c1765cd720
|
@ -788,6 +788,8 @@ function attachPropInit( prototype, properties, members )
|
|||
this, class_instance[ this.__iid ], properties[ 'public' ]
|
||||
);
|
||||
|
||||
class_instance[ this.__iid ] = inst_props;
|
||||
|
||||
propobj.setup( this, inst_props, properties, members );
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,7 +22,12 @@
|
|||
* @package core
|
||||
*/
|
||||
|
||||
var util = require( './util' );
|
||||
var util = require( './util' ),
|
||||
|
||||
// whether or not we support defining properties through
|
||||
// Object.defineProperty()
|
||||
defprop = ( Object.defineProperty !== undefined ) ? true : false;
|
||||
;
|
||||
|
||||
|
||||
exports.setup = function( base, dest, properties, members )
|
||||
|
@ -81,6 +86,11 @@ exports.createPropProxy = function( base, dest, props )
|
|||
{
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
|
||||
if ( !defprop )
|
||||
{
|
||||
return base;
|
||||
}
|
||||
|
||||
for ( prop in props )
|
||||
{
|
||||
if ( !( hasOwn.call( props, prop ) ) )
|
||||
|
@ -114,3 +124,17 @@ exports.createPropProxy = function( base, dest, props )
|
|||
return dest;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether property proxying is supported
|
||||
*
|
||||
* Proxying is done via getters and setters. If the JS engine doesn't support
|
||||
* them (pre-ES5), then the proxy will not work.
|
||||
*
|
||||
* @return {boolean} true if supported, otherwise false
|
||||
*/
|
||||
exports.supportsPropProxy = function()
|
||||
{
|
||||
return defprop;
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
var common = require( './common' ),
|
||||
assert = require( 'assert' ),
|
||||
Class = common.require( 'class' ),
|
||||
propobj = common.require( 'propobj' ),
|
||||
|
||||
pub = 'foo',
|
||||
prot = 'bar',
|
||||
|
@ -145,6 +146,13 @@ var common = require( './common' ),
|
|||
|
||||
( function testProtectedAndPrivateMembersAreNotAccessibleExternally()
|
||||
{
|
||||
// browsers that do not support the property proxy will not support
|
||||
// encapsulating properties
|
||||
if ( !( propobj.supportsPropProxy() ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assert.equal(
|
||||
foo.peeps,
|
||||
undefined,
|
||||
|
|
Loading…
Reference in New Issue