From a303adddea337904c115682c047932b2dc52fbb0 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 11 May 2011 18:36:49 -0400 Subject: [PATCH] Added tests to ensure that static method overrides are supported --- lib/class_builder.js | 6 +++-- test/test-class_builder-static.js | 41 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/class_builder.js b/lib/class_builder.js index 4fc0977..2f94a6c 100644 --- a/lib/class_builder.js +++ b/lib/class_builder.js @@ -645,8 +645,10 @@ function attachStatic( ctor, members, base, inheriting ) var methods = members.methods, props = members.props; - // "inherit" the parent's static methods by running the parent's static - // initialization method + // "Inherit" the parent's static methods by running the parent's static + // initialization method. It is important that we do this before anything, + // because this will recursively inherit all members in order, permitting + // overrides. var baseinit = base.___$$sinit$$; if ( baseinit ) { diff --git a/test/test-class_builder-static.js b/test/test-class_builder-static.js index ec7c1a9..82d8fa0 100644 --- a/test/test-class_builder-static.js +++ b/test/test-class_builder-static.js @@ -526,3 +526,44 @@ var common = require( './common' ), ); } )(); + +/** + * Public and protected static methods should be able to be overridden by + * subtypes. We needn't test private methods, as they are not inherited. + */ +( function testStaticMethodsCanBeOverriddenBySubtypes() +{ + var val = 'bar', + Foo = builder.build( + { + 'public static foo': function() {}, + 'protected static bar': function() {}, + } ), + + SubFoo = builder.build( Foo, + { + 'public static foo': function() + { + return val; + }, + + 'public static prot': function() + { + return this.bar(); + }, + + 'protected static bar': function() + { + return val; + }, + } ); + + assert.equal( SubFoo.foo(), val, + "Public static methods can be overridden by subtypes" + ); + + assert.equal( SubFoo.prot(), val, + "Protected static methods can be overridden by subtypes" + ); +} )(); +