PushGuiPage:
JS can open child GUI pages with the PushGuiPage command.
If the parent GUI page wants to execute a callback function upon closing of the child GUI page,
then the PushGuiPage function needs to pass the name of a global function.
Instead, PushGuiPage should receive the function, not the name of the function.
Use cases:
- Inlining functions to reduce globals and fragmentation of the code (for example gamesetup.js / #5322 or functions_msgbox.js).
- Syntax errors at code interpret time instead of runtime errors if the function name contains a typo.
Prior to rP14496, this was the case.
PopGuiPage:
rP14496 also introduced PopGuiPageCB, which is to be called in order to close with callback arguments (whereas PopGuiPage closes without callback arguments).
The alternative function can be removed by having the PopGuiPage call the callback functions if it was passed to PushGuiPage.
Notice however that this also makes it possible for the child GUI page to decide that the parent GUI page may not perform the callback function.
This behavior was used by the structree / civinfo switch-page button added in rP21339.
The code of that revision looks like a workaround and the code rewritten here appears like a different workaround
(because globals should be avoided and the parent GUI page should avoid having to specify implementation details of child GUI pages).