Hi Philip(
On Wednesday, 16 November 2016, <philip chimento gmail com> wrote:
Hi list,
I'm on the verge of merging a branch [1] to GJS master, which will port the underlying JS engine to SpiderMonkey 31 (was 24). This will bring a bunch of new JS features (and I hope performance improvements as well) to gnome-shell and extension authors.
With the new engine, gnome-shell code will be required to call gjs_init() before making any other calls to the GJS API, and call gjs_shutdown() after destroying your last GjsContext. It is planned for both of these methods to be new API in GJS 1.47.1.
I'm always a bit sad when libraries require explicit initialisation and deinitialisation functions; they usually impose additional cognitive burden on developers.
Since GJS is written as a C++ library with a C ABI, wouldn't be possible to use a static constructor to automatically call gjs_init() before the main() function is called? And, symmetrically, use a static destructor to shut it down after main() returns? Is it an ordering problem?
Yes, that worked, thanks for the great suggestion! There is no ordering problem (unless someone felt the need to create a GjsContext in a different static constructor...)
There will still possibly be changes required to gnome-shell, as detailed here [1]; after any call to gjs_context_eval() or gjs_context_eval_file() the caller will need to decide whether to behave any differently if the evaluated JS code executed System.exit().
Regards,
Philip