1
0
Fork 0

Enhanced static property setter to support setting to both undefined and null values

closure/master
Mike Gerwitz 2011-04-13 23:52:25 -04:00
parent 969687e770
commit 26cf32abe5
2 changed files with 16 additions and 4 deletions

View File

@ -643,8 +643,9 @@ function attachStatic( ctor, members, base, inheriting )
}
// if a value was provided, this method should be treated as a
// setter rather than a getter
if ( val )
// setter rather than a getter (we *must* test using
// arguments.length to ensure that setting to undefined works)
if ( arguments.length > 1 )
{
props[ 'public' ][ prop ] = val;
return context;

View File

@ -362,9 +362,20 @@ var common = require( './common' ),
} )
;
Foo.$( 'foo', undefined );
Foo.$( 'foo', val );
// first check to ensure we can set the value to null
Foo.$( 'foo', null );
assert.strictEqual( Foo.$( 'foo' ), null,
"Static properties may be set to null"
);
// then undefined (this actually won't do anything)
Foo.$( 'foo', undefined );
assert.strictEqual( Foo.$( 'foo' ), undefined,
"Static properties may be set to undefined"
);
// then set back to a scalar
Foo.$( 'foo', val );
assert.equal( Foo.$( 'foo' ), val,
"Setting static property to undefined does not corrupt lookup process"
);