From 9067bbf0cfb81b7eadda60b1b1e22ad36df5ad74 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 11 May 2011 20:53:43 -0400 Subject: [PATCH] Static property accessor method is no longer enumerable --- lib/class_builder.js | 4 ++-- test/test-class_builder-static.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/class_builder.js b/lib/class_builder.js index 8b40a66..f8858c0 100644 --- a/lib/class_builder.js +++ b/lib/class_builder.js @@ -661,7 +661,7 @@ function attachStatic( ctor, members, base, inheriting ) ctor.___$$sprops$$ = props; // provide a method to access static properties - ctor.$ = function( prop, val ) + util.defineSecureProp( ctor, '$', function( prop, val ) { // we use hasOwnProperty to ensure that undefined values will not // cause us to continue checking the parent, thereby potentially @@ -694,7 +694,7 @@ function attachStatic( ctor, members, base, inheriting ) // return the value return props[ 'public' ][ prop ]; } - }; + } ); } // copy over public static methods diff --git a/test/test-class_builder-static.js b/test/test-class_builder-static.js index 50ce570..542f5e0 100644 --- a/test/test-class_builder-static.js +++ b/test/test-class_builder-static.js @@ -71,6 +71,28 @@ var common = require( './common' ), } )(); +/** + * If supported by the environment, ensure that the accessor method used to + * access static properties is not enumerable. It's unnecessary clutter (and + * confusion) otherwise. + */ +( function testStaticPropertyAccessorIsNotEnumerable() +{ + var get = Object.getOwnPropertyDescriptor, + Foo = builder.build( {} ); + + // don't perform the test if unsupported + if ( fallback ) + { + return; + } + + assert.equal( get( Foo, '$' ).enumerable, false, + "Static property accessor method should not be enumerable" + ); +} )(); + + /** * Static members, by their nature, should be accessible through the class * definition itself; that is, without instantiation. It should also not be