diff --git a/test/MethodWrappersTest.js b/test/MethodWrappersTest.js index a3d03bd..fd49a56 100644 --- a/test/MethodWrappersTest.js +++ b/test/MethodWrappersTest.js @@ -29,6 +29,56 @@ var common = require( './common' ), ; +/** + * The wrappers accept a function that should return the instance to be bound to + * 'this' when invoking a method. This has some important consequences, such as + * the ability to implement protected/private members. + */ +( function testMethodInvocationBindsThisToPassedInstance() +{ + var instance = function() {}, + val = 'fooboo', + val2 = 'fooboo2', + iid = 1, + called = false, + + getInst = function() + { + called = true; + return instance; + } + + method = sut.standard.wrapNew( + function() + { + return this.foo; + }, + null, 0, getInst + ), + + override = sut.standard.wrapOverride( + function() + { + return this.foo2; + }, + method, 0, getInst + ) + ; + + // set instance values + instance.foo = val; + instance.foo2 = val2; + + assert.equal( method(), val, + "Calling method will bind 'this' to passed instance" + ); + + assert.equal( override(), val2, + "Calling method override will bind 'this' to passed instance" + ); +} )(); + + /** * The __super property is defined for method overrides and permits invoking the * overridden method (method of the supertype). diff --git a/test/test-member_builder-method.js b/test/test-member_builder-method.js index 1e6f216..7f5cc43 100644 --- a/test/test-member_builder-method.js +++ b/test/test-member_builder-method.js @@ -255,77 +255,6 @@ mb_common.assertCommon(); } )(); -/** - * One of the powerful features of the method builder is the ability to pass in - * an instance to be bound to 'this' when invoking a method. This has some - * important consequences, such as the ability to implement protected/private - * members. - */ -( function testMethodInvocationBindsThisToPassedInstance() -{ - var instance = function() {}, - val = 'fooboo', - val2 = 'fooboo2', - iid = 1, - - func = function() - { - return this.foo; - }, - - func2 = function() - { - return this.foo2; - }, - - called = false, - instCallback = function() - { - called = true; - return instance; - }, - - members = builder.initMembers() - ; - - // set instance values - instance.foo = val; - instance.foo2 = val2; - - // concrete method - mb_common.buildMember( - members, - exports.meta, - 'func', - func, - { 'virtual': true }, - instCallback - ); - - assert.equal( - members[ 'public' ].func(), - val, - "Calling method will bind 'this' to passed instance" - ); - - // override method - mb_common.buildMember( - members, - exports.meta, - 'func', - func2, - { 'override': true }, - instCallback - ); - - assert.equal( - members[ 'public' ].func(), - val2, - "Calling method override will bind 'this' to passed instance" - ); -} )(); - - /** * It does not make sense to be able to declare abstract private methods, since * they cannot be inherited and overridden by subtypes.