HomeWildfire Games

Removes g_ScriptingHost and implements global to compartment 1 to 1 relation.

Description

Removes g_ScriptingHost and implements global to compartment 1 to 1 relation.
Each GUI Page gets its own compartment and all ScriptInterfaces in the same thread should now use the same JS Runtime.
This is required for the SpiderMonkey upgrade.
Check the ticket for details.

Closes #2241
Refs #1886
Refs #1966

Details

Committed
YvesJan 4 2014, 11:14 AM
Parents
rP14495: Roman tower remake
Branches
Unknown
Tags
Unknown

Event Timeline

elexis raised a concern with this commit.Sep 26 2018, 10:17 AM
elexis added a subscriber: elexis.
elexis added inline comments.
/ps/trunk/binaries/data/mods/public/gui/common/functions_global_object.js
16

// Because passing functions accross compartment boundaries is a pain, we just store them here together with some optional arguments.

I can confirm is a pain to implement the callback function properly, because the JS function has to be stored as a JS::Value in a C++ struct, but the function doesn't have to be passed between compartment boundaries, the callback function is still performed in the same context.

33

all of this ugly/hack example ^

56

ugly/hack example ^

/ps/trunk/binaries/data/mods/public/gui/msgbox/msgbox.xml
85

ugliness example ^

/ps/trunk/source/gui/GUIManager.cpp
131

Passing a function name instead of a function is a really uncomfortable solution that leaves much uglier JS code than the alternative that passes a function.

It for example means that the AI config dialog in gamesetup.js requires a global function that is 1000+ lines away from it's PushGuiPageCB call and prevents that from confining the AI behavior logic to one hunk.

Secondly it's easier for the JS dev if there is only one Push and one Pop function where the callback function and the return value are optional.

This commit now has outstanding concerns.Sep 26 2018, 10:17 AM
historic_bruno raised a concern with this commit.Jul 24 2019, 8:45 PM
historic_bruno added a subscriber: historic_bruno.
historic_bruno added inline comments.
/ps/trunk/source/ps/GameSetup/HWDetect.cpp
193

This commit likely broke Engine.DisplayErrorDialog for hwdetect.js, but almost nobody would ever encounter it, so we never noticed. See D2123

The hwdetect concern was addressed in rP22549 (and I guess the patch isn't scheduled to be audited completely).

elexis removed an auditor: elexis.Aug 16 2019, 8:47 PM

Passing callback functions as arguments instead of names fixed in rP22676.

This commit no longer requires audit.Aug 16 2019, 8:47 PM
elexis added inline comments.Sep 3 2019, 3:58 PM
/ps/trunk/source/gui/scripting/ScriptFunctions.cpp
619

missing AutoRequest

631

missing AutoRequest

elexis added inline comments.Tue, Sep 17, 9:24 PM
/ps/trunk/binaries/data/mods/public/gui/savedgames/save.js
103

This hack originates from rP13579.
Not 100% sure, but it looks like this commit (rP14496) made this function unused, rather than being called, since Engine.SaveGame -> SavedGames::Save now receives the data and doesnt call this anymore.

/ps/trunk/source/ps/SavedGame.cpp
83

This previously called the GUI page function ("hack"), wheras now it uses the data already received.

elexis added inline comments.Wed, Oct 9, 5:40 PM
/ps/trunk/source/gui/CGUI.cpp
1354

The call change obsoleted PSERROR_Scripting catch (refs D2363)

/ps/trunk/source/scriptinterface/ScriptInterface.cpp
1031

(No PSERROR_Scripting exceptions thrown here)