diff --git a/lib/class_builder.js b/lib/class_builder.js index 340cdbb..da45d80 100644 --- a/lib/class_builder.js +++ b/lib/class_builder.js @@ -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; diff --git a/test/test-class_builder-static.js b/test/test-class_builder-static.js index d7e1e2e..7afac76 100644 --- a/test/test-class_builder-static.js +++ b/test/test-class_builder-static.js @@ -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" );