summaryrefslogtreecommitdiff
path: root/gjs
Commit message (Collapse)AuthorAgeFilesLines
* context: Clear all vectors of JS::Heap on disposeDaniel van Vugt2023-04-131-0/+3
| | | | | | | | Otherwise we might still have some `JS::Heap`s lingering after `JS_DestroyContext`, which will fail to destruct (crash) when their destructors are called later in `~GjsContextPrivate()`. Fixes: https://gitlab.gnome.org/GNOME/gjs/-/issues/472
* stack: Print stack trace using glib logging functionsSebastian Keller2023-04-062-1/+54
| | | | | | | | | | | | | | | | When the gjs process is logging to the systemd journal directly via the glib logging functions, the stack trace would get logged indirectly via stderr. This however is not guaranteed to get added to the journal at the same time as the error messages logged via glib. This is especially noticeable when triggered from an endless loop or an idle callback. In some cases it even can result in the stack trace not getting logged at all. There is currently no public API in mozjs to dump a stack trace directly to a string from arbitrary threads, only to files, so this uses open_memstream() as a workaround. Related: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/1868
* context: Fix job queue ending prematurely when dispatcher resetPhilip Chimento2023-03-043-15/+6
| | | | | | | | | | | | | | | | | | | | | | | When the promise job dispatcher is reset, its GCancellable is replaced with a different instance. However, the original GCancellable instance was passed to GjsContextPrivate::runJobs(), which aborts the job queue if the GCancellable is cancelled. This wasn't normally a problem, because the GCancellable isn't usually cancelled. However, running JS with code coverage instrumentation starts and stops the job dispatcher after every job, in order for the debugger code to do its thing. So the GCancellable was getting cancelled and immediately replaced with a fresh one, but the job queue was still getting aborted. This still didn't seem to have any noticeable effect until we merged the runAsync() feature recently. From that point, async module evaluate operations started getting dropped on the floor when code coverage was active, which is very bad news. The fix is to not hold on to the GCancellable across jobs. Instead of checking whether the GCancellable is cancelled, instead check whether the promise job dispatcher is running.
* mainloop: Instrument main loop and promise job dispatcher with debug logsPhilip Chimento2023-03-044-10/+33
| | | | | This adds a new debug topic, JS MAINLOOP, and adds debug log statements to the promise job queue, GSource, dispatcher, and main loop machinery.
* context: Instrument module evaluation promises with debug logsPhilip Chimento2023-03-041-0/+18
|
* context: Use module name in promise reaction function debug tagPhilip Chimento2023-03-041-2/+2
| | | | | | For debugging, make sure the module identifier is part of the promise reaction function's debug tag, so that when we break on it we can tell which module was being evaluated.
* context: Use correct debug tag with promise reaction functionPhilip Chimento2023-03-041-2/+2
| | | | | | | The reaction functions of the module evaluation promise accidentally had their function IDs switched, leading to potential confusion when debugging: a function called "async reject" would be called when the module evaluation promise resolved, and vice versa.
* cleanup: Replace static_cast<GjsContext*> with runtime castPhilip Chimento2023-03-043-3/+3
| | | | | The runtime cast is defined anyway by the GObject macros, and allows turning runtime checking on or off at build time as desired.
* Introduce runAsync() to run main loops without blocking module resolutionEvan Welsh2023-02-204-19/+120
| | | | | | | | | | | | | | | All modules are promises. If Gtk.Application.run() or GLib.MainLoop.run() is called within a module it will block all other promises as run() is a synchronous, blocking function. To work around this there is now a setMainLoopHook function exposed which runs a callback after module resolution is complete. This allows APIs to "install" a mainloop asynchronously. For Gio.Application and GLib.MainLoop there are now runAsync() versions of their run() functions. runAsync() returns a Promise which will resolve once the mainloop has exited. Fixes #468
* jsapi-util: Mark assignment/move operators as constexprMarco Trevisan (Treviño)2022-11-191-2/+2
| | | | They only use constexpr operations, so indeed they can be too.
* module: Use GjsAutoChar to hold the module nameMarco Trevisan (Treviño)2022-11-191-17/+14
|
* coverage: Use GjsAutoUnref to hold GFile instancesMarco Trevisan (Treviño)2022-11-191-16/+9
|
* stack: Hold context reference in a smart pointerMarco Trevisan (Treviño)2022-11-191-2/+1
|
* objectbox: Use GjsAutoPointer for impl tooMarco Trevisan (Treviño)2022-11-192-5/+5
| | | | It makes access to members using constexpr definitions
* objectbox: Define Ptr as a GjsAutoPointerMarco Trevisan (Treviño)2022-11-192-5/+11
| | | | | We can avoid storing the destructor in this way, together with all the constexpr operations.
* console: Use auto-pointers to manage all items' lifecycleMarco Trevisan (Treviño)2022-11-191-48/+34
|
* console: Use GjsAutoStrv to handle Strv cleanupMarco Trevisan (Treviño)2022-11-191-39/+33
|
* console: Use GStrvBuilder if available in the GLib version we useMarco Trevisan (Treviño)2022-11-191-0/+24
|
* console: Just return instead of exit from main functionMarco Trevisan (Treviño)2022-11-191-7/+8
| | | | | Return will implies also calling the auto-cleanups functions we have, so it's just nicer.
* jsapi-util: Add const definition for GjsAutoPointer out() methodMarco Trevisan (Treviño)2022-11-191-0/+1
|
* text-encoding: Use simpler array of char instead of vectorMarco Trevisan (Treviño)2022-11-191-6/+5
| | | | We can use a simpler version here.
* maint: Update includes to match new version of IWYUPhilip Chimento2022-11-156-7/+7
|
* Revert "closure: Store JSFunction* pointer instead of JSObject*"Philip Chimento2022-11-061-11/+0
| | | | | | | | | | | | | | | | | | | This is basically a revert of commit 7140cac8, although so much has changed in the meantime that none of the revert applied cleanly, so it's more of an "un-rewrite". This fixes a regression that has been present for almost exactly 4 years. Storing a JSFunction* pointer in closures did not take into account the fact that not all callable JSObjects have an associated JSFunction. They could be exotic objects with a [[Call]] method. In particular, introspected functions are this, so this prevented g-i function objects from being used as signal handlers. (Less importantly, the same probably applied to callable Proxy objects.) Also adds a regression test so that this doesn't happen again. Closes: #518
* profiler: Use std::array instead of stack arrayPhilip Chimento2022-11-012-4/+6
| | | | | | | | | | In newer Clang the stack allocation of the array produces the odd -Walign-mismatch message: error: passing 1-byte aligned argument to 8-byte aligned parameter 'this' of '' may result in an unaligned pointer access Using std::array seems to solve the problem.
* engine: Use JS_InitWithFailureDiagnostic instead of JS_InitPhilip Chimento2022-08-071-6/+10
| | | | | | | No difference between these two, except that JS_InitWithFailureDiagnostic returns a descriptive message if it fails, which JS_Init ignores. So, in the rare case that it fails, we abort while printing the descriptive message instead of just "Could not initialize JavaScript".
* deprecation: Refer to TextDecoder in ByteArray toString messagePhilip Chimento2022-08-071-2/+1
| | | | | Instead of recommending to call ByteArray.toString(), we should recommend using TextDecoder to convert Uint8Array to a string.
* js: Update IWYU comments for jsapi.hPhilip Chimento2022-08-072-2/+2
| | | | | Since more functions will move out of jsapi.h in the future, it'll be useful to know why exactly we are including it.
* js: Remove Gjs::maybe_get_private()Philip Chimento2022-08-072-15/+1
| | | | | | This function was necessary in SpiderMonkey 91, but now the same functionality is part of the SpiderMonkey API. There is no longer any need to define our own.
* js: Replace JSFreeOp with JS::GCContextEvan Welsh2022-08-072-2/+4
| | | | In particular, in finalize operations.
* js: Add JSTracer* argument to JS_UpdateWeakPointerAfterGC()Evan Welsh2022-08-071-4/+5
| | | | | This has some cascade effects on the signatures of other methods, since we now need to pass the JSTracer in.
* js: Adapt to new JS::SafelyInitialized APIEvan Welsh2022-08-071-2/+2
| | | | See: https://hg.mozilla.org/mozilla-central/rev/551bd2292b5c9722f77f4501191a32a605a9f89b
* js: Adapt to new JS::PropertyKey APIEvan Welsh2022-08-073-7/+7
| | | | See: https://bugzilla.mozilla.org/show_bug.cgi?id=1754405
* engine: Adjust JS engine options for mozjs102Evan Welsh2022-08-071-6/+1
| | | | All of these options are always enabled in mozjs102.
* js: Various functions moved out of jsapi.hPhilip Chimento2022-08-0716-16/+50
| | | | | | | | | | | - js/CallAndConstruct.h: Now contains JS::Call, JS::Construct, and related - js/Debug.h: Already existed, but now contains JS_DefineDebuggerObject - js/GlobalObject.h: Now contains JS::CurrentGlobalOrNull - js/PropertyAndElement.h: Now contains APIs for getting, setting, and defining properties, as well as array elements - js/ScriptPrivate.h: Now contains JS::GetScriptPrivate/SetScriptPrivate - js/Stack.h: Now contains APIs that have to do with the call stack
* js: Replace class private pointers with reserved slotsPhilip Chimento2022-08-063-4/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | JS::GetPrivate() and JS::SetPrivate() are going away in SpiderMonkey 102. The replacement is to stuff the pointer into a JS::PrivateValue and store it in an object's reserved slot. This is a change we can make prior to the switch. With SpiderMonkey 102, we are intended to use JS::GetMaybePtrFromReservedSlot() to retrieve the pointer. This function doesn't exist in SpiderMonkey 91, but it is a small inline function that we can open-code in jsapi-util.h. In most of the cases, we can encapsulate this access into three methods of CWrapperPointerOps: has_private(), init_private(), and unset_private(). (Retrieving the pointer was already encapsulated by the various for_js() methods.) This provides better safety anyway, because in init_private() we can enforce that there was no pointer already set. We define that reserved slot 0 is always the private pointer. BoxedInstance already used slot 0 for something else, so that moves to slot 1. Based on Evan's commit from the mozjs102 branch. Co-authored-by: Evan Welsh <contact@evanwelsh.com>
* global: Combine compilation and execution in bootstratpPhilip Chimento2022-08-061-5/+1
| | | | | | | I think the compilation and execution were previously split because the API for doing both with UTF-8 source didn't work. However, it works now. This is a good time to fix this workaround because JS::CloneAndExecuteScript() is disappearing in mozjs102.
* js: Use JS::PropertyKey::isVoidEvan Welsh2022-08-061-3/+3
| | | | | | | JSID_VOID is going away in mozjs102. The replacement is the isVoid() method of JS::PropertyKey. See: https://bugzilla.mozilla.org/show_bug.cgi?id=1754405
* CI: Add missing files to IWYU scriptPhilip Chimento2022-07-265-31/+39
| | | | | | | internal.cpp and text-encoding.cpp hadn't been added to IWYU (it's really annoying that globs won't work there, we should really find a way around that) so they were never checked by IWYU. Add them and update their headers.
* maint: Bring headers in line with IWYU 0.18Philip Chimento2022-07-257-13/+7
| | | | | | As with every release, IWYU's algorithms have slightly changed, and some bugs have been fixed meaning we can remove some workarounds from the postprocessing script; unfortunately other bugs have appeared as well.
* Merge branch 'use-vector-for-closures' into 'master'Philip Chimento2022-07-251-1/+0
|\ | | | | | | | | | | | | object: Use std::vector to hold Objects GClosure's Closes #485 See merge request GNOME/gjs!758
| * object: Use std::vector to hold Objects GClosure'sMarco Trevisan (Treviño)2022-06-141-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We used a std::forward list to hold closure pointers in Object's to avoid adding a vector when not needed, but these structures are terribly slow as already pointed out in [1], and demonstrated even way poorer performances when testing signal connections (see [2], #485 and !758), so get rid of them and just use vectors everywhere which can boost performances up to 95% in our tests. This implies some more memory usage for each object, as we can't use a std::vector without the size member since C++11, but I think it's still better, given that size of std::forward_list is still bigger when with only two closures/vfuncs added (as each element requires two pointers). Fixes: #485 [1] https://github.com/3v1n0/stl-containers-benchmarks [2] https://gitlab.gnome.org/3v1n0/gjs/-/snippets/3608
* | maint: Fix IWYU includes in files that previously failedPhilip Chimento2022-07-246-0/+7
|/ | | | | | | | | | | | Due to the bug fixed by the previous commit, many files' includes had gotten out of sync. This fixes all of the IWYU complaints. We need to add some lines to the mapping file, either due to an IWYU upgrade or changes in the header files; I'm not sure. It's annoying that we have to list all the glib/*.h files separately, but that is for two reasons: there is no glob for glib/* that can leave out <glib/gstdio.h> and other public GLib headers; and glib/galloca.h should redirect to the system alloca.h.
* jsapi-util-strings: Ignore locale to compute the upper case of a charMarco Trevisan (Treviño)2022-04-282-3/+1
| | | | | | | | | | | | We used to compute camel-case name of properties using toupper(), however this is locale-dependent, while in this case we want to be sure that we're only using ASCII values. This is particularly problematic in Turkish (and maybe other locales) because there 'i'.toLocaleUpperCase() is 'İ', that is definitely not an ASCII char, causing problems to with our generated properties. See: https://github.com/micheleg/dash-to-dock/issues/1687
* profiler: Align types in function definition with header fileEvan Miller2022-03-181-2/+2
| | | | | Same gint64/int64_t type mismatch on Darwin (long vs long long) as the previous commit.
* Merge branch 'verbose-object-print-output' into 'master'Philip Chimento2022-03-063-118/+2
|\ | | | | | | | | | | | | Verbose object print output Closes #107 See merge request GNOME/gjs!587
| * print: Connect up prettyPrint() to Console.interact() and log()Philip Chimento2022-02-253-118/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It makes sense for the prettyPrint() function to be written in JS, but it does need to be called internally in Console.interact() which is written in C++. Therefore, create a slot on the global object in which to store the prettyPrint() function, which can be retrieved when needing to call the function from internal code. Console.interact() no longer needs to use gjs_value_debug_string(), so that code and its dependencies can be removed. Also pass the arguments of log() and logError() through prettyPrint(). This enables the work from #107.
* | Merge branch 'ewlsh/march-maintenance' into 'master'Philip Chimento2022-03-062-6/+8
|\ \ | | | | | | | | | | | | March maintenance See merge request GNOME/gjs!736
| * | context: Log JavaScript errors in bootstrap code prior to exitingEvan Welsh2022-03-051-3/+6
| | |
| * | module: Replace leftover call to FinishDynamicModuleImport_NoTLAEvan Welsh2022-03-051-3/+2
| |/
* | jsapi-util: Fix non-flat string messagePhilip Chimento2022-03-031-1/+2
|/ | | | | | | Bizarrely, if we construct ostringstream with a string already in it, the default behaviour is to start overwriting characters at the start when later inserting more text into the stream. If we don't want that, we have to construct it with the 'advance to end' flag.