Replaed all __{define,lookup}[GS]etter__'s with defineProperty/getOwnPropertyDescriptor
parent
fbc58384b4
commit
841b5ac5a5
|
@ -157,7 +157,17 @@ exports.buildProp = function( members, meta, name, value, keywords )
|
||||||
*/
|
*/
|
||||||
exports.buildGetter = function( members, meta, name, value, keywords )
|
exports.buildGetter = function( members, meta, name, value, keywords )
|
||||||
{
|
{
|
||||||
getMemberVisibility( members, keywords ).__defineGetter__( name, value );
|
Object.defineProperty(
|
||||||
|
getMemberVisibility( members, keywords ),
|
||||||
|
name,
|
||||||
|
{
|
||||||
|
get: value,
|
||||||
|
enumerable: true,
|
||||||
|
|
||||||
|
// otherwise we can't add a setter to this
|
||||||
|
configurable: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,7 +187,17 @@ exports.buildGetter = function( members, meta, name, value, keywords )
|
||||||
*/
|
*/
|
||||||
exports.buildSetter = function( members, meta, name, value, keywords )
|
exports.buildSetter = function( members, meta, name, value, keywords )
|
||||||
{
|
{
|
||||||
getMemberVisibility( members, keywords ).__defineSetter__( name, value );
|
Object.defineProperty(
|
||||||
|
getMemberVisibility( members, keywords ),
|
||||||
|
name,
|
||||||
|
{
|
||||||
|
set: value,
|
||||||
|
enumerable: true,
|
||||||
|
|
||||||
|
// otherwise we can't add a getter to this
|
||||||
|
configurable: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
19
lib/util.js
19
lib/util.js
|
@ -25,15 +25,6 @@
|
||||||
var propParseKeywords = require( './prop_parser' ).parseKeywords;
|
var propParseKeywords = require( './prop_parser' ).parseKeywords;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether getters/setters are supported
|
|
||||||
* @var {boolean}
|
|
||||||
*/
|
|
||||||
var getset = ( Object.prototype.__defineGetter__ === undefined )
|
|
||||||
? false
|
|
||||||
: true
|
|
||||||
;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether we can actually define properties, or we need to fall back
|
* Whether we can actually define properties, or we need to fall back
|
||||||
*
|
*
|
||||||
|
@ -220,9 +211,15 @@ exports.propParse = function( data, options )
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// retrieve getters/setters, if supported
|
||||||
|
if ( can_define_prop )
|
||||||
|
{
|
||||||
|
var prop_desc = Object.getOwnPropertyDescriptor( data, prop );
|
||||||
|
getter = prop_desc.get;
|
||||||
|
setter = prop_desc.set;
|
||||||
|
}
|
||||||
|
|
||||||
value = data[ prop ];
|
value = data[ prop ];
|
||||||
getter = ( ( getset ) ? data.__lookupGetter__( prop ) : null );
|
|
||||||
setter = ( ( getset ) ? data.__lookupSetter__( prop ) : null );
|
|
||||||
|
|
||||||
parse_data = keywordParser( prop ) || {};
|
parse_data = keywordParser( prop ) || {};
|
||||||
name = parse_data.name || prop;
|
name = parse_data.name || prop;
|
||||||
|
|
|
@ -22,46 +22,60 @@
|
||||||
* @package test
|
* @package test
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// don't perform these tests if getters/setters are unsupported
|
|
||||||
if ( Object.prototype.__defineGetter__ === undefined )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var common = require( './common' ),
|
var common = require( './common' ),
|
||||||
assert = require( 'assert' ),
|
assert = require( 'assert' ),
|
||||||
Class = common.require( 'class' ),
|
Class = common.require( 'class' ),
|
||||||
|
util = common.require( 'util' ),
|
||||||
|
|
||||||
foo_def = {},
|
foo_def = {},
|
||||||
sub_foo_def = {}
|
sub_foo_def = {}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
// don't perform these tests if getters/setters are unsupported
|
||||||
|
if ( util.definePropertyFallback() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// to prevent syntax errors in browsers that do not support getters/setters in
|
// to prevent syntax errors in browsers that do not support getters/setters in
|
||||||
// object notation
|
// object notation
|
||||||
foo_def.__defineGetter__( 'foo', function ()
|
Object.defineProperty( foo_def, 'foo', {
|
||||||
{
|
get: function ()
|
||||||
return this._foo;
|
{
|
||||||
} );
|
return this._foo;
|
||||||
foo_def.__defineSetter__( 'foo', function ( val )
|
},
|
||||||
{
|
set: function ( val )
|
||||||
this._foo = ''+( val );
|
{
|
||||||
} );
|
this._foo = ''+( val );
|
||||||
foo_def.__defineGetter__( 'bar', function ()
|
},
|
||||||
{
|
|
||||||
return 'durp';
|
enumerable: true,
|
||||||
} );
|
|
||||||
foo_def.__defineSetter__( 'bar', function ( val )
|
|
||||||
{
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
sub_foo_def.__defineGetter__( 'bar', function ()
|
Object.defineProperty( foo_def, 'bar', {
|
||||||
{
|
get: function ()
|
||||||
return this.bar2;
|
{
|
||||||
|
return 'durp';
|
||||||
|
},
|
||||||
|
set: function ( val )
|
||||||
|
{
|
||||||
|
},
|
||||||
|
|
||||||
|
enumerable: true,
|
||||||
} );
|
} );
|
||||||
sub_foo_def.__defineSetter__( 'bar', function ( val )
|
|
||||||
{
|
Object.defineProperty( sub_foo_def, 'bar', {
|
||||||
this.bar2 = val;
|
get: function ()
|
||||||
|
{
|
||||||
|
return this.bar2;
|
||||||
|
},
|
||||||
|
set: function ( val )
|
||||||
|
{
|
||||||
|
this.bar2 = val;
|
||||||
|
},
|
||||||
|
|
||||||
|
enumerable: true,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
var Foo = Class.extend( foo_def ),
|
var Foo = Class.extend( foo_def ),
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
|
|
||||||
var common = require( './common' ),
|
var common = require( './common' ),
|
||||||
assert = require( 'assert' ),
|
assert = require( 'assert' ),
|
||||||
Interface = common.require( 'interface' );
|
Interface = common.require( 'interface' ),
|
||||||
|
util = common.require( 'util' )
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
( function testPropertiesNotPermittedWithinInterfaces()
|
( function testPropertiesNotPermittedWithinInterfaces()
|
||||||
|
@ -43,7 +45,7 @@ var common = require( './common' ),
|
||||||
( function testGettersAndSettersNotPermittedWithinInterfaces()
|
( function testGettersAndSettersNotPermittedWithinInterfaces()
|
||||||
{
|
{
|
||||||
// don't perform this test if unsupported by environment
|
// don't perform this test if unsupported by environment
|
||||||
if ( Object.prototype.__defineGetter__ === undefined )
|
if ( util.definePropertyFallback() )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -51,8 +53,12 @@ var common = require( './common' ),
|
||||||
// so we don't break browsers that do not support getters/setters in object
|
// so we don't break browsers that do not support getters/setters in object
|
||||||
// notation
|
// notation
|
||||||
var data = {};
|
var data = {};
|
||||||
data.__defineGetter__( 'foo', function() {} );
|
Object.defineProperty( data, 'foo', {
|
||||||
data.__defineSetter__( 'foo', function() {} );
|
get: function() {},
|
||||||
|
set: function() {},
|
||||||
|
|
||||||
|
enumerable: true,
|
||||||
|
} );
|
||||||
|
|
||||||
assert.throws( function()
|
assert.throws( function()
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
|
|
||||||
var common = require( './common' ),
|
var common = require( './common' ),
|
||||||
assert = require( 'assert' ),
|
assert = require( 'assert' ),
|
||||||
util = common.require( 'util' );
|
util = common.require( 'util' )
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
( function testAbstractKeywordDesignatesMethodAsAbstract()
|
( function testAbstractKeywordDesignatesMethodAsAbstract()
|
||||||
|
@ -173,15 +174,19 @@ var common = require( './common' ),
|
||||||
|
|
||||||
|
|
||||||
// for browsers that support it
|
// for browsers that support it
|
||||||
if ( Object.prototype.__defineGetter__ !== undefined )
|
if ( util.definePropertyFallback() === false )
|
||||||
{
|
{
|
||||||
data = {};
|
data = {};
|
||||||
parsed_keywords = {};
|
parsed_keywords = {};
|
||||||
|
|
||||||
// to prevent syntax errors for environments that don't support
|
// to prevent syntax errors for environments that don't support
|
||||||
// getters/setters in object notation
|
// getters/setters in object notation
|
||||||
data.__defineGetter__( 'public foo', function() {} );
|
Object.defineProperty( data, 'public foo', {
|
||||||
data.__defineSetter__( 'public foo', function() {} );
|
get: function() {},
|
||||||
|
set: function() {},
|
||||||
|
|
||||||
|
enumerable: true,
|
||||||
|
} );
|
||||||
|
|
||||||
|
|
||||||
util.propParse( data, {
|
util.propParse( data, {
|
||||||
|
|
|
@ -26,7 +26,7 @@ var common = require( './common' ),
|
||||||
assert = require( 'assert' ),
|
assert = require( 'assert' ),
|
||||||
util = common.require( 'util' ),
|
util = common.require( 'util' ),
|
||||||
|
|
||||||
get_set = ( ( Object.prototype.__defineGetter__ ) ? true : false )
|
get_set = !( util.definePropertyFallback() )
|
||||||
;
|
;
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
|
@ -52,8 +52,12 @@ var data = {
|
||||||
// only add getter/setter if it's supported by our engine
|
// only add getter/setter if it's supported by our engine
|
||||||
if ( get_set )
|
if ( get_set )
|
||||||
{
|
{
|
||||||
data.__defineGetter__( 'someFoo', function () {} );
|
Object.defineProperty( data, 'someFoo', {
|
||||||
data.__defineSetter__( 'someFoo', function () {} );
|
get: function () {},
|
||||||
|
set: function () {},
|
||||||
|
|
||||||
|
enumerable: true,
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue