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 // if a value was provided, this method should be treated as a
// setter rather than a getter // setter rather than a getter (we *must* test using
if ( val ) // arguments.length to ensure that setting to undefined works)
if ( arguments.length > 1 )
{ {
props[ 'public' ][ prop ] = val; props[ 'public' ][ prop ] = val;
return context; return context;

View File

@ -362,9 +362,20 @@ var common = require( './common' ),
} ) } )
; ;
Foo.$( 'foo', undefined ); // first check to ensure we can set the value to null
Foo.$( 'foo', val ); 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, assert.equal( Foo.$( 'foo' ), val,
"Setting static property to undefined does not corrupt lookup process" "Setting static property to undefined does not corrupt lookup process"
); );