1
0
Fork 0

Using visibility fallback for browsers that do not support getters/setters

closure/master
Mike Gerwitz 2011-03-06 22:43:14 -05:00
parent df2943b5a1
commit c1765cd720
3 changed files with 38 additions and 4 deletions

View File

@ -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 );
});
}

View File

@ -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;
};

View File

@ -22,9 +22,10 @@
* @package test
*/
var common = require( './common' ),
assert = require( 'assert' ),
Class = common.require( 'class' ),
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,