Moved instance binding test to MethodWrappersTest (#25)
- Ah; see how much nicer this is?closure/master
parent
5937f7b0be
commit
1af7617a83
|
@ -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).
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue