diff options
author | Philip Chimento <philip.chimento@gmail.com> | 2022-08-09 05:09:58 +0000 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2022-08-09 05:09:58 +0000 |
commit | 0bf046114c38468f55ebc1c04cbab2e41b39c230 (patch) | |
tree | 41faada3e58b236eade80d53fb8d12395bd5ec76 | |
parent | 580dec7522a11b8f14d2af554be249fe0b2b069b (diff) | |
parent | 5bbfb173bde45e03a7eaee8c7df6ae572e552d3f (diff) | |
download | gjs-0bf046114c38468f55ebc1c04cbab2e41b39c230.tar.gz |
Merge branch 'july-maintenance' into 'master'
July maintenance
See merge request GNOME/gjs!786
-rw-r--r-- | doc/Modules.md | 18 | ||||
-rw-r--r-- | gjs/deprecation.cpp | 3 | ||||
-rw-r--r-- | gjs/engine.cpp | 16 | ||||
-rwxr-xr-x | test/test-ci.sh | 5 |
4 files changed, 25 insertions, 17 deletions
diff --git a/doc/Modules.md b/doc/Modules.md index 1e575519..38492271 100644 --- a/doc/Modules.md +++ b/doc/Modules.md @@ -99,7 +99,7 @@ drawingArea.connect("draw", (widget, cr) => { **Import with `const Format = imports.format;`** -The format import is mostly obsolete, providing `vprintf()`, `printf()` and `format()`. Native [template literals][template-literals] should be preferred now, except in few situations like Gettext (See [Bug #50920][bug-50920]). +The format import is mostly obsolete, providing `vprintf()`, `printf()` and `format()`. Native [template literals][template-literals] should be preferred now, except in few situations like Gettext (See [Bug #60027][bug-60027]). ```js let foo = "Pi"; @@ -109,21 +109,27 @@ let baz = Math.PI; // Using native template literals (Output: Pi to 2 decimal points: 3.14) `${foo} to ${bar*2} decimal points: ${baz.toFixed(bar*2)}` -// Applying format() to the string prototype const Format = imports.format; -String.prototype.format = Format.format; // Using format() (Output: Pi to 2 decimal points: 3.14) +Format.format.call("%s to %d decimal points: %.2f", foo, bar * 2, baz); + +// Applying format() to the string prototype (this is the old way, but +// is often considered bad practice now, especially in GNOME Shell +// extensions where other extensions might overwrite it. +// Consider not doing this!) +String.prototype.format = Format.format; "%s to %d decimal points: %.2f".format(foo, bar*2, baz); // Using format() with Gettext -_("%d:%d").format(11, 59); -Gettext.ngettext("I have %d apple", "I have %d apples", num).format(num); +Format.format.call(_("%d:%d"), 11, 59); +Format.format.call( + Gettext.ngettext("I have %d apple", "I have %d apples", num), num); ``` [template-literals]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals -[bug-50920]: https://savannah.gnu.org/bugs/?50920 +[bug-60027]: https://savannah.gnu.org/bugs/?60027 ## [Gettext](https://gitlab.gnome.org/GNOME/gjs/blob/HEAD/modules/script/gettext.js) diff --git a/gjs/deprecation.cpp b/gjs/deprecation.cpp index c0382d59..ca034d9f 100644 --- a/gjs/deprecation.cpp +++ b/gjs/deprecation.cpp @@ -34,8 +34,7 @@ const char* messages[] = { "this would have interpreted the bytes of the array as a string, but that " "is nonstandard. In the future this will return the bytes as " "comma-separated digits. For the time being, the old behavior has been " - "preserved, but please fix your code anyway to explicitly call ByteArray" - ".toString(array).\n" + "preserved, but please fix your code anyway to use TextDecoder.\n" "(Note that array.toString() may have been called implicitly.)", // DeprecatedGObjectProperty: diff --git a/gjs/engine.cpp b/gjs/engine.cpp index d0f05e7d..a8e867a7 100644 --- a/gjs/engine.cpp +++ b/gjs/engine.cpp @@ -89,10 +89,13 @@ LPVOID lpvReserved) { switch (fdwReason) { - case DLL_PROCESS_ATTACH: - gjs_dll = hinstDLL; - gjs_is_inited = JS_Init(); - break; + case DLL_PROCESS_ATTACH: { + gjs_dll = hinstDLL; + const char* reason = JS_InitWithFailureDiagnostic(); + if (reason) + g_error("Could not initialize JavaScript: %s", reason); + gjs_is_inited = true; + } break; case DLL_THREAD_DETACH: JS_ShutDown (); @@ -110,8 +113,9 @@ LPVOID lpvReserved) class GjsInit { public: GjsInit() { - if (!JS_Init()) - g_error("Could not initialize Javascript"); + const char* reason = JS_InitWithFailureDiagnostic(); + if (reason) + g_error("Could not initialize JavaScript: %s", reason); } ~GjsInit() { diff --git a/test/test-ci.sh b/test/test-ci.sh index dd61e17e..58918b7c 100755 --- a/test/test-ci.sh +++ b/test/test-ci.sh @@ -39,6 +39,8 @@ do_Get_Upstream_Base () { # should probably be rebased. git remote add upstream https://gitlab.gnome.org/GNOME/gjs.git || \ git remote set-url upstream https://gitlab.gnome.org/GNOME/gjs.git + # $CI_MERGE_REQUEST_TARGET_BRANCH_NAME is only defined if we’re running in a + # merge request pipeline; fall back to $CI_DEFAULT_BRANCH otherwise. base_branch="${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}" if ! git fetch --shallow-since="28 days ago" --no-tags upstream "$base_branch"; then echo "Main branch doesn't have history in the past 28 days, fetching " @@ -51,9 +53,6 @@ do_Get_Upstream_Base () { # Work out the newest common ancestor between the detached HEAD that this CI # job has checked out, and the upstream target branch (which will typically # be `upstream/master` or `upstream/gnome-nn`). - # - # $CI_MERGE_REQUEST_TARGET_BRANCH_NAME is only defined if we’re running in a - # merge request pipeline; fall back to $CI_DEFAULT_BRANCH otherwise. newest_common_ancestor_sha=$(git merge-base ci-upstream-base-branch HEAD) if test -z "$newest_common_ancestor_sha"; then echo "Couldn’t find common ancestor with the upstream main branch. This" |