In save.js there is a comment about a function being a hack.
And indeed a workaround it is, because the GUI can just pass the JS Value storing the GUI data to be added to the savegame when calling the JS function,
rather than the savegame code calling the topmost GUI page to obtain that.
It seems like the save.js function was not called since rP14496 anymore, but not sure how JS worked back then.