From ea0d18d8ebe882bf635c49587f5605497afdf333 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 5 Apr 2011 19:52:14 -0400 Subject: [PATCH] Added regression test to ensure 'this' is bound to the class definition rather than instance within static methods --- test/test-class_builder-static.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test-class_builder-static.js b/test/test-class_builder-static.js index 6fd2d89..e6fa8ed 100644 --- a/test/test-class_builder-static.js +++ b/test/test-class_builder-static.js @@ -150,3 +150,33 @@ var common = require( './common' ), "Public static getters/getters are unavailable on prototype (1)" ); } )(); + + +/** + * With non-static methods, 'this' is bound to the instance. In the case of + * static members, we should bind to the class definition (equivalent of + * this.__self). + * + * This functionality had already existed previously. When a propobj is not + * available for an instance, it falls back. This serves as a regression test to + * ensure this functionality remains. + */ +( function testStaticMethodsBoundToClassRatherThanInstance() +{ + var result = null, + Foo = builder.build( + { + 'public static foo': function() + { + result = this; + }, + } ); + + // call the static method + Foo.foo(); + + assert.deepEqual( result, Foo, + "Static members are bound to class definition rather than instance" + ); +} )(); +