1
0
Fork 0

Resolved getter/setter test issues for browsers that do not support the functionality

- __define{Getter,Setter}__ had to be used rather than object notation due to syntax errors in older browsers
closure/master
Mike Gerwitz 2010-12-28 09:02:23 -05:00
parent 5dcc4452be
commit 2325bd9a8f
3 changed files with 79 additions and 61 deletions

View File

@ -30,47 +30,42 @@ if ( Object.prototype.__defineGetter__ === undefined )
var common = require( './common' ),
assert = require( 'assert' ),
Class = common.require( 'class' );
Class = common.require( 'class' ),
foo_def = {},
sub_foo_def = {}
;
var Foo = Class.extend(
// to prevent syntax errors in browsers that do not support getters/setters in
// object notation
foo_def.__defineGetter__( 'foo', function ()
{
_foo: '',
set foo( val )
{
this._foo = ''+( val );
},
get foo()
{
return this._foo;
},
set bar( val )
{
},
get bar()
{
return 'durp';
},
});
var SubFoo = Foo.extend(
return this._foo;
} );
foo_def.__defineSetter__( 'foo', function ( val )
{
bar2: null,
this._foo = ''+( val );
} );
foo_def.__defineGetter__( 'bar', function ()
{
return 'durp';
} );
foo_def.__defineSetter__( 'bar', function ( val )
{
} );
set bar( val )
{
this.bar2 = val;
},
sub_foo_def.__defineGetter__( 'bar', function ()
{
return this.bar2;
} );
sub_foo_def.__defineSetter__( 'bar', function ( val )
{
this.bar2 = val;
} );
get bar()
{
return this.bar2;
},
});
var Foo = Class.extend( foo_def ),
SubFoo = Foo.extend( sub_foo_def );
var foo = new Foo(),
sub = new SubFoo(),

View File

@ -26,17 +26,22 @@ var common = require( './common' ),
assert = require( 'assert' ),
propCopy = common.require( 'util' ).propCopy;
var props = {
one: 1,
two: 2,
get_set = ( Object.prototype.__defineGetter__ ) ? true : false;
method: function two() {},
props = {
one: 1,
two: 2,
get val() {},
set val() {},
};
method: function two() {},
},
dest = {}
;
var dest = {};
if ( get_set )
{
props.__defineGetter__( 'val', function () {} );
props.__defineSetter__( 'val', function () {} );
}
propCopy( props, dest );
assert.ok(
@ -95,7 +100,15 @@ propCopy( props, dest2, {
},
} );
[ each, prop, method, getter, setter, override ].forEach( function( item, i )
var check = [ each, prop, method, override ];
if ( get_set )
{
check.push( getter );
check.push( setter );
}
check.forEach( function( item, i )
{
assert.notEqual(
item,

View File

@ -22,9 +22,12 @@
* @package test
*/
var common = require( './common' ),
var common = require( './common' ),
assert = require( 'assert' ),
util = common.require( 'util' );
util = common.require( 'util' ),
get_set = ( ( Object.prototype.__defineGetter__ ) ? true : false )
;
var data = {
// scalars (properties)
@ -39,10 +42,6 @@ var data = {
// object (property)
propObj: {},
// getter/setter
get someFoo() {},
set someFoo() {},
// concrete method
method: function() {},
@ -50,6 +49,14 @@ var data = {
abstractMethod: util.createAbstractMethod(),
};
// only add getter/setter if it's supported by our engine
if ( get_set )
{
data.__defineGetter__( 'someFoo', function () {} );
data.__defineSetter__( 'someFoo', function () {} );
}
var chk_each = {};
for ( item in data )
{
@ -93,7 +100,7 @@ util.propParse( data, {
setter: function( name, func )
{
setters[ name ] = func;
},
}
} );
@ -120,17 +127,20 @@ assert.equal(
"Property parser properly detects abstract methods"
);
assert.equal(
getters.someFoo,
data.__lookupGetter__( 'someFoo' ),
"Property parser properly detects getters"
);
if ( get_set )
{
assert.equal(
getters.someFoo,
data.__lookupGetter__( 'someFoo' ),
"Property parser properly detects getters"
);
assert.equal(
setters.someFoo,
data.__lookupSetter__( 'someFoo' ),
"Property parser properly detects setters"
);
assert.equal(
setters.someFoo,
data.__lookupSetter__( 'someFoo' ),
"Property parser properly detects setters"
);
}
var chk_each_count = 0;