summaryrefslogtreecommitdiff
path: root/modules
Commit message (Collapse)AuthorAgeFilesLines
* esm: Improve startup time by delaying imports of native and GI modulesPhilip Chimento2023-03-043-23/+17
| | | | | | | | | | | | | | | | | | | | | | By avoiding using import.meta.importSync() and imports.gi at the top level of modules that we import during the bootstrap process, we speed up the execution of a blank file by 15%, because we don't need to go into any of the GI typelib machinery. Now, the only modules imported at startup are _print, _encoding, _timers, and console, in order to provide public global APIs. I measured the 15% speedup with `perf stat -r 10 -B`. I also used Meson's measurements of the test suite to see a noticeable effect: for example, running the CommandLine test (which starts many instances of GJS) goes goes from 5.4 to 4.9 seconds. The cost of importing these modules is instead paid at the first time they're used. This assumes that it's nearly zero cost to import the modules a second time, because they're cached. In addition, this should make debugging easier because you don't get a big log spew of importing GLib if your script doesn't import GLib.
* gi: Roll back change to imports.gi.versions object if gi.require() failsPhilip Chimento2023-03-041-6/+13
| | | | | If something like gi.require('GLib', '1.75') fails, then we don't want the faulty version number remaining on the imports.gi.versions object.
* GLib: Remove circular dependency between GLib and ByteArrayPhilip Chimento2023-03-041-8/+5
| | | | | ByteArray.fromString() is already defined by _byteArrayNative and re-exported; while ByteArray.toGBytes() just calls new GLib.Bytes anyway.
* Gio: Use proper default priority on async generatorsMarco Trevisan (Treviño)2023-02-281-3/+4
| | | | Gio.DEFAULT_PRIORITY is undefined given that's exposed by GLib instead.
* Gio: Add support for initializing a DBus Proxy via a promiseMarco Trevisan (Treviño)2023-02-201-1/+17
| | | | | | | | | Add a newAsync() static method to DBus proxy wrappers, that returns a promise that allows to initialize a proxy object asynchronously, keeping around all the wrappers as expected, and allowing to use nicer try/catch syntax. (Edited from Gio.makeProxyPromise to a static method by Philip)
* Introduce runAsync() to run main loops without blocking module resolutionEvan Welsh2023-02-202-0/+15
| | | | | | | | | | | | | | | 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
* signals: Simulate GObject's connect_after behavior on signalsMarco Trevisan (Treviño)2023-02-192-3/+33
| | | | | | | GObject signals have a connect_after function that we don't have in the gjs core signals, while it can be useful in some situations. So introduce it.
* debugger: Use spread syntax to override style propertyPhilip Chimento2023-02-191-3/+1
| | | | | This was previously done with a slightly circuitous call to Object.assign(); it can be done more readably with spread syntax.
* console: Use private fields and methodsPhilip Chimento2023-02-191-119/+43
| | | | | | This is a modernization of the console module. (I'm a bit surprised that the methods still work when transferred as own properties to the global console object, but apparently they do.)
* debugger: Support Symbol valuesPhilip Chimento2023-01-011-1/+5
| | | | | | | | | | | We get this for free already for Symbol primitive values and Symbol property keys and values, due to it being supported in the pretty-printer. For the 'keys' command, we need to start using Object.getOwnPropertySymbols() to get the Symbol property keys. While we are at it, switch from using Object.keys() which only gives enumerable string/number property keys, to Object.getOwnPropertyNames(), in order to be able to debug non-enumerable properties as well.
* print: Format Symbol property keysPhilip Chimento2023-01-011-1/+10
| | | | | Introduce a new property key formatter which formats a Symbol property key in brackets.
* print: Pretty-print formatting for SymbolsPhilip Chimento2023-01-011-0/+22
| | | | | | | This formats Symbols as the source text with which they should be able to be constructed. It makes a distinction between registered symbols (created with Symbol.for()), well-known symbols (always existing), and regular symbols (created with Symbol()).
* print: Refactor check for nonstandard toString in pretty-printPhilip Chimento2023-01-011-11/+15
| | | | | | In the pretty-printer, if an object or a function has has its toString() method overridden, the overridden toString() is preferred. Refactor this check slightly so that we can put more cases in the switch statement.
* signals: Fix bugs when multiple handlers are connected and disconnect is calledEvan Welsh2022-11-301-3/+8
|
* cairo-surface: Add finish() and flush()tuberry2022-11-211-1/+50
| | | | closes #515
* cairo-context: Use GjsAutoCppPointer of doubles instead of vectorMarco Trevisan (Treviño)2022-11-191-5/+7
|
* signals: Cleanup the signal connections when all the ids are removedMarco Trevisan (Treviño)2022-11-161-1/+4
|
* signals: Keep name in signal connections object for faster disconnectionMarco Trevisan (Treviño)2022-11-161-2/+4
| | | | | | Having the connection name in both objects we can be faster at disconnecting the connections as we can just remove the id from the target array.
* signals: Keep a set of signal IDs by name to speedup signal emissionMarco Trevisan (Treviño)2022-11-161-8/+16
| | | | | | | | Use dicts and array lookups to emit signals instead of iterating through them. Using native Map() and Set() would have been better, but performances are worse.
* signals: Use a Dict to associate connection IDs to objectsMarco Trevisan (Treviño)2022-11-161-14/+14
| | | | | | | | | We often reference connection IDs, so now we can use a more optimized native way to handle connections without having to iterate them all the times. This could have been implemented using the newer Map() object, but sadly it's still way slower than using normal objects.
* maint: Update includes to match new version of IWYUPhilip Chimento2022-11-151-1/+0
|
* Minor fixes of cairo enum definitionsVítor Vasconcellos2022-11-081-2/+3
|
* signals: Modernize codeMarco Trevisan (Treviño)2022-11-021-64/+38
| | | | Use some more modern JS features to get the same quickly.
* console: Pass CODE information to structured warning logsMarco Trevisan (Treviño)2022-11-021-1/+2
| | | | | In case the log is severe enough it's better to fill such information by default.
* console: Also use formatters for console.traceMarco Trevisan (Treviño)2022-11-021-10/+17
| | | | | | Just fetch the error trace at printer function so that we can just use this at lower level without requiring explicitly using the printer when using trace()
* console: Include CODE file, function and line in structured loggingMarco Trevisan (Treviño)2022-11-021-0/+18
| | | | | This is what GLib does all the times for C code, in JS we can easily do it as well as we have traces, for now do it only for console.trace().
* console: Write the whole stack trace when using console.trace()Marco Trevisan (Treviño)2022-11-021-4/+9
| | | | Also ensure this in a test
* console: Ensure that PrintOptions fields are included in the structured logMarco Trevisan (Treviño)2022-11-021-0/+1
|
* console: Use more const variables when possibleMarco Trevisan (Treviño)2022-11-021-5/+5
|
* console: Add missing description to warn()Marco Trevisan (Treviño)2022-11-021-0/+2
|
* Make GInputStream iterable and async iterableSonny Piers2022-11-021-0/+34
|
* Update ESLint toolingSonny Piers2022-11-021-11/+11
|
* Gio: allow D-Bus implementations to return pre-packed variantsAndy Holmes2022-11-021-1/+3
| | | | | | When a D-Bus implementation returns a value from a getter, check if it is variant matching the expected property signature. If it is, skip packing a new variant and just return the value.
* GObject: Handle versions of GLib without GBindingGroupPhilip Chimento2022-11-011-3/+5
| | | | | | We don't require GLib 2.72 for anything else, so it makes sense to conditionally define the override for GObject.BindingGroup.bind_full(). If GLib is too old then the override (and its tests) are skipped.
* docs: Fix Enumerator typoPhilip Chimento2022-10-291-1/+1
|
* console: Fix setjmp warningsPhilip Chimento2022-10-291-3/+3
| | | | | | | | | | | These variables now generate warnings that they "might be clobbered by 'longjmp' or 'vfork'". Declaring them volatile prevents this. As per https://stackoverflow.com/a/2105840/172999, the C99 standard says "the values of objects of automatic storage duration that are local to the function containing the invocation of the corresponding setjmp macro that do not have volatile-qualified type and have been changed between the setjmp invocation and longjmp call are indeterminate."
* Merge branch 'promisify-gdbus-async-init' into 'master'Philip Chimento2022-10-291-13/+3
|\ | | | | | | | | | | | | Gio: Promisify GDBusProxy.init_async by default Closes #494 See merge request GNOME/gjs!790
| * Gio: Simplify init_async usage by always using a promiseMarco Trevisan (Treviño)2022-08-101-13/+2
| | | | | | | | | | The function is defined as a so we can just rely on promise syntax to handle the results.
| * Gio: Promisify GDBusProxy.init_async by defaultMarco Trevisan (Treviño)2022-08-101-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some code may promisify it after that it has been overridden, this means that when called we may not use the original method correctly as the function won't have the arguments set anymore and thus its length will be 0, causing the assumption included in commit 58840261 not to be true anymore. Since the function is already a wrapper, we can safely override it to be a promise and then override it again. Allowing code simplifications and being more future-proof, when all the async functions will be promises by default. Fixes: #494
* | GObject: Ensure that static methods are accessible from a subtypeMarco Trevisan (Treviño)2022-10-291-0/+2
| | | | | | | | It makes sense to be able to use a static method even from a subtype
* | GLib: override GThread functionsAndy Holmes2022-08-281-0/+23
|/ | | | | These are almost entirely unusable from GJS and the few functions that don't crash outright shouldn't be called by user code.
* Gio: Add overrides for File.set_attribute and FileInfo.set_attributePhilip Chimento2022-08-081-0/+61
| | | | | | | | | These functions can crash if used from JS, because they take a raw pointer. Add an override that calls the appropriate type-safe method instead, on a best-effort basis; not all of these exist. In any case, the crashes should be prevented. Closes: #496
* js: Update IWYU comments for jsapi.hPhilip Chimento2022-08-073-3/+3
| | | | | 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-4/+4
| | | | | | 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-076-21/+19
| | | | In particular, in finalize operations.
* js: Various functions moved out of jsapi.hPhilip Chimento2022-08-075-3/+9
| | | | | | | | | | | - 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
* Merge branch 'FileEnumator-iterator' into 'master'Philip Chimento2022-08-071-0/+60
|\ | | | | | | | | Make GFileEnumerator iterable and async iterable See merge request GNOME/gjs!784
| * Make GFileEnumerator iterable and async iterableSonny Piers2022-08-071-0/+60
| |
* | js: Replace class private pointers with reserved slotsPhilip Chimento2022-08-065-22/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | cairo-context: Move $dispose() implementation inside CairoContext classPhilip Chimento2022-08-061-7/+2
| | | | | | | | | | | | Access to the wrapper object's cairo_t* is currently not encapsulated, but it will be if we move from JS::SetPrivate to reserved slots. So, this method needs to be part of the class.