Title:
regsitering a CFC.cbFunc in another CFC and using it uses the wrong variables-scope
| View in TrackerStatus/Resolution/Reason: Closed/Withdrawn/
Reporter/Name(from Bugbase): Martin Baur / Martin Baur (tinu8805)
Created: 12/09/2012
Components: Language, CF Component
Versions: 9.0.1
Failure Type:
Found In Build/Fixed In Build: 9.0.1 /
Priority/Frequency: Major / All users will encounter
Locale/System: English / Win 2008 Server R2
Vote Count: 0
Problem Description:
a cfc method used as a callback function from another cfc uses the variables scope of chte calling cfc instead of the callee.
Problem occurs the same way in CF 10 wher function coudl be used as a type declarator
Steps to Reproduce:
component MCU {
variables.mcu.clock = 0;
// more of variables.mcu.*
Init () {
// Create all targets, call each target’s registerMCUListener to let them know whom to call back.
variables.mcu.targets[i] = CreateObject ("component", "target").Init ();
variables.mcu.targets[i].registerMCUListener (cbFromTarget);
}
private numeric function cbFromTarget (struct msg) {
writedump (var=#variables#); // This shows the variables scope of TARGET, expected MCU <<<<<<<<
variables.mcu.events.list[variables.mcu.events.ptr] = {
clock = variables.mcu.clock,
msg = arguments.msg
};
return 0;
}
}
---
---
component TARGET {
variables.tg.clock = 0;
// more of variables.tg.*
public void function registerMCUListener (any mculistener) {
/*
* register the mcu listener function to notify of any events
*/
variables.tg.mcu.listener = arguments.mculistener;
}
private void function ToMCU (struct msg) {
/*
* register the mcu listener function to notify of any events
*/
if (isCustomFunction (variables.tg.mcu.listener)) {
variables.tg.mcu.listener (msg);
}
}
}
---
Idea: The cbFunc registers the message in the MCU’s variables scope
But it does not. The marked variables.mcu.clock is throwing an error because mcu.clock does not exist in the variables scope.
Observation: CF is using the variables scope of TARGET instead of MCU therefore no clock.
I confirmed that by dumping the variables scope just before that line marked with <<<<<<<<<
Actual Result:
line marked with <<<<<<<< shows the variables of TARGET
Expected Result:
variables of MCU
Any Workarounds:
None, because BOTH cfcs use cb to communicate with each other and other cfcs
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3418667
Deployment Phase: Release Candidate
External Customer Info:
External Company:
External Customer Name: tinu8805
External Customer Email:
External Test Config: My Hardware and Environment details:
Attachments:
- December 17, 2013 00:00:00: 1_bug3418667.cfm
- December 17, 2013 00:00:00: 2_MCU.cfc
- December 17, 2013 00:00:00: 3_target.cfc
Comments: