Philip_Baird
11 years agoCommunity Expert
Error using JScript function::apply() in Script Extension
Hi all, I am attempting to write a Script Extension which contains a function which accepts a function and a list of parameters and attempts to invoke the passed in function using function::apply()
In the Script Unit "TheFactory" I have a simple function
function testPassFunction( func ) {
func.apply( null, [ 123 ] );
}
If I call this from the Script Unit "TestTheFactory" as such:
//USEUNIT TheFactory
function test001() {
TheFactory.testPassFunction(
function( i ) {
Log.Message( i );
}
);
}
It logs 123 as I would expect.
However, when the Script Unit "TheFactory" is compiled into a Script Extension, calling the same function:
function test001() {
ArcInnovations.TOF.testPassFunction(
function( i ) {
Log.Message( i );
}
);
}
I get the following Exception dialog:
---------------------------
TestComplete
---------------------------
JScript object expected
Microsoft JScript runtime error
testobjectfactory.js Line: 131 Column: 2.
Plug-in: Test Object Factory 1.0 by Phillip Baird (c) 2014 ARC Innovations
Location: C:\Program Files (x86)\SmartBear\TestComplete 10\Bin\extensions\ScriptExtensions\testobjectfactory
---------------------------
Help OK
---------------------------
If I invoke the function directly in the Script Extension:
function testPassFunction( func ) {
func( 123 );
}
It works fine, but this is not useful for what I am wanting to do.
Is this a limitation within the Test Complete runtime and the way that Script Extensions are executed?
Is this related to the fact the Script Extensions cannot reference other Script Units?
Regards,
Phil Baird