From ce1370e025c80d47800786146478717b42c11176 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 31 Aug 2011 00:05:07 -0400 Subject: [PATCH] Now passing getInst() directly into MethodwrapperFactory factory function, like good 'ol times - I seem to have forgotten that this is necessary due to the static implementation --- lib/MethodWrapperFactory.js | 9 ++++---- test/MethodWrapperFactoryTest.js | 36 +++++++------------------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/lib/MethodWrapperFactory.js b/lib/MethodWrapperFactory.js index fc35b1a..5ed4a18 100644 --- a/lib/MethodWrapperFactory.js +++ b/lib/MethodWrapperFactory.js @@ -33,15 +33,14 @@ * perform the actual * wrapping */ -module.exports = exports = function MethodWrapperFactory( getInst, factory ) +module.exports = exports = function MethodWrapperFactory( factory ) { // permit omission of the 'new' keyword for instantiation if ( !( this instanceof exports ) ) { - return new exports( getInst, factory ); + return new exports( factory ); } - this._getInst = getInst; this._factory = factory; }; @@ -56,8 +55,8 @@ module.exports = exports = function MethodWrapperFactory( getInst, factory ) * @param {function()} super_method super method, if overriding * @param {number} cid class id that method is associated with */ -exports.prototype.wrapMethod = function( method, super_method, cid ) +exports.prototype.wrapMethod = function( method, super_method, cid, getInst ) { - return this._factory( method, super_method, cid, this._getInst ); + return this._factory( method, super_method, cid, getInst ); }; diff --git a/test/MethodWrapperFactoryTest.js b/test/MethodWrapperFactoryTest.js index d22c367..3a759aa 100644 --- a/test/MethodWrapperFactoryTest.js +++ b/test/MethodWrapperFactoryTest.js @@ -64,11 +64,11 @@ var common = require( './common' ), method = function() {}, super_method = function() {}, cid = 55, + getInst = function() {}, retval = 'foobar'; var result = Sut( - function() {}, - function( given_method, given_super, given_cid ) + function( given_method, given_super, given_cid, givenGetInst ) { called = true; @@ -84,9 +84,13 @@ var common = require( './common' ), "Factory method should be provided with cid" ); + assert.equal( givenGetInst, getInst, + "Factory method should be provided with proper inst function" + ); + return retval; } - ).wrapMethod( method, super_method, cid ); + ).wrapMethod( method, super_method, cid, getInst ); // we'll include this in addition to the following assertion (which is // redundant) to make debugging more clear @@ -99,29 +103,3 @@ var common = require( './common' ), ); } )(); - -/** - * The instance function, which should be made available to the factory - * function, is used to retrieve the visibility object associated with the - * instance that the context is associated with. - */ -( function testProvidedFactoryFunctionIsCalledWithInstanceFunction() -{ - var called = false; - - Sut( - function() - { - called = true; - }, - function( _, __, ___, inst ) - { - inst(); - } - ).wrapMethod( null, null, 0 ); - - assert.equal( called, true, - "Instance callback should be provided to factory function" - ); -} )(); -