Commit graph

15 commits

Author SHA1 Message Date
vyordan
835d23dd60 Move Script* classes to Script namespace
- Renamed ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest
  to Script::Engine, Script::Context, Script::Interface, Script::Request.
- Removed 'Script' prefix from file names.
- Updated all includes, forward declarations, and friend classes.

Fixes #7516
2026-05-12 23:17:29 -06:00
phosit
6bdcab11b9
Don't forward declare CompiledModule
When using `std::unordered_map` it's types have to be complete.
2025-11-13 19:50:38 +01:00
Itms
9150c20818
Remove ScriptTypes and ScriptExtraHeaders headers
The first header was used to include the SpiderMonkey JS API at once,
with safeguards and preprocessor defines. Nowadays, SpiderMonkey
provides modular headers allowing us to include what we use, refs #8086.

Some defines have to be moved to compiler options but it is apparently
a mistake from the SM developers:
https://bugzilla.mozilla.org/show_bug.cgi?id=1987876
2025-09-14 13:17:18 +02:00
Ralph Sennhauser
6ed56954ab
Add missing const in ModuleLoader
Add the required const to operator == and != as required and warned
about with C++20.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-12 20:45:15 +02:00
Ralph Sennhauser
b066bb0b99
Fix includes in source/scriptinterface
Make include-what-you-use happy with files in source/scriptinterface and
fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-07 11:45:19 +02:00
phosit
77b1addb45 Enable modules in the GUI
Doesn't actually change a GUI-page to use modules. Adopting a GUI-page
now only requires JS and XML changes.

Ref: #8081
2025-06-26 10:50:21 +02:00
phosit
b8348bec55 Store the ScriptInterface& in ModuleLoader::Result
During hotloading the `ScriptRequest` was constructed from a
`JSContext*`. That requires that already an other `ScriptRequest` is
active. Which isn't always the case.
Now The `ScriptRequest` is constructed from a `ScriptInterface&`.

Storing a `ScriptInterface&` in the `ModuleLoader::Result` allows to
remove the `m_Result` as it is retrieved from the `ScriptInterface`.
2025-06-26 10:50:21 +02:00
phosit
05869454e5 Disalow importing some files
Not all modules should be able to load all other modules. A predicate
function can to be passed to the `ScriptInterface`. That function
returns whether the module is allowed to loat the module. If no
predicate is passed in no modules can be loaded through that
`ScriptInterface`.
2025-06-06 17:36:35 +02:00
phosit
6492bc705a Allow modules to be hotloaded
Reload a module when it's script file got changed or when one of it's
imported modules got reloaded.

This doesn't work for dynamic `import`s.
2025-06-06 17:36:35 +02:00
phosit
d76e107dca Support the import.meta property
Through the `import.meta` property the engine can pass some values to
the module. Currently only the `path` of the script file is exposed.
2025-06-06 17:36:35 +02:00
phosit
a40caaffc4 Support dynamic import
The static `import` should be prefered over the dynamic but it might be
usefull when loading an object from a json file.
2025-06-06 17:36:35 +02:00
phosit
252df0a1db Return the namespace of a module
To make it easy for the engine to access the exported values the
namespace is returned from the future.
2025-06-06 17:36:35 +02:00
phosit
d26d9b9b2b Rethrow exceptions from the top level of a module 2025-06-06 17:36:35 +02:00
phosit
ce01bdddf6 Allow to check whether modules finished evaluating 2025-06-06 17:36:35 +02:00
phosit
c6d42ebbd5 Support JavaScript modules
- With modules JavaScript code can be split up into multiple files. We
	already implemented such a mechanism (`Engine.LoadLibrary`) in
	multiple parts of the engine. The advantage of using modules is
	that it's standart (JS-devs are familiar with it) and it doesn't
	has to be implemented multiple times.
	Note that `Engine.LoadLibrary` loads all files in a directory
	while the new `import` only loads one file.

- With modules seemingly global variables are local to that
	script/module. We already implemented such a mechanism
	(`ScriptInterface::LoadScript`).
2025-06-06 17:36:35 +02:00