From 26cf32abe5315943f7f02714be27f7eef311b07d Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 13 Apr 2011 23:52:25 -0400 Subject: [PATCH] Enhanced static property setter to support setting to both undefined and null values --- lib/class_builder.js | 5 +++-- test/test-class_builder-static.js | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) 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" );