summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2023-02-20 06:51:40 +0000
committerPhilip Chimento <philip.chimento@gmail.com>2023-02-20 06:51:40 +0000
commit92f7a45d5201d7d938116e8d450e50f2d93a88ae (patch)
tree7dd6f4a898ea0ec1fb2850b273e697e180799b2f
parent0795a3d38c7f417c65f04a6cf336118d3cc71d62 (diff)
parent2079e0ed79df6549a02310b1d8f183f983d2caa9 (diff)
downloadgjs-92f7a45d5201d7d938116e8d450e50f2d93a88ae.tar.gz
Merge branch 'december-maintenance' into 'master'
December maintenance See merge request GNOME/gjs!820
-rw-r--r--gi/arg-cache.cpp4
-rw-r--r--gi/function.cpp13
-rw-r--r--installed-tests/js/meson.build61
-rw-r--r--installed-tests/js/testCairo.js4
-rw-r--r--installed-tests/js/testGIMarshalling.js7
-rw-r--r--installed-tests/js/testRegress.js2
-rw-r--r--meson.build15
-rw-r--r--modules/esm/console.js162
-rw-r--r--modules/script/_bootstrap/debugger.js4
9 files changed, 109 insertions, 163 deletions
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index 5274aead..eb8e9724 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -1081,7 +1081,9 @@ bool FlagsIn::in(JSContext* cx, GjsFunctionCallState*, GIArgument* arg,
return false;
if ((uint64_t(number) & m_mask) != uint64_t(number)) {
- gjs_throw(cx, "%" PRId64 " is not a valid value for flags argument %s",
+ gjs_throw(cx,
+ "0x%" G_GINT64_MODIFIER
+ "x is not a valid value for flags argument %s",
number, m_arg_name);
return false;
}
diff --git a/gi/function.cpp b/gi/function.cpp
index c9f8b1f3..e6672e05 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -679,6 +679,19 @@ bool GjsCallbackTrampoline::initialize() {
g_assert(is_valid());
g_assert(!m_closure);
+ GITypeInfo return_type;
+ g_callable_info_load_return_type(m_info, &return_type);
+ GITypeTag return_tag = g_type_info_get_tag(&return_type);
+ if (g_callable_info_get_caller_owns(m_info) == GI_TRANSFER_NOTHING &&
+ (return_tag == GI_TYPE_TAG_FILENAME ||
+ return_tag == GI_TYPE_TAG_UTF8)) {
+ gjs_throw(context(),
+ "%s %s returns a transfer-none string. This is not supported "
+ "(https://gitlab.gnome.org/GNOME/gjs/-/issues/519)",
+ m_is_vfunc ? "VFunc" : "Callback", m_info.name());
+ return false;
+ }
+
/* Analyze param types and directions, similarly to
* init_cached_function_data */
int n_param_types = g_callable_info_get_n_args(m_info);
diff --git a/installed-tests/js/meson.build b/installed-tests/js/meson.build
index 567e5cc7..7e8f4acb 100644
--- a/installed-tests/js/meson.build
+++ b/installed-tests/js/meson.build
@@ -32,7 +32,7 @@ if gi.type_name() == 'internal'
gi_tests_include = gi_subproject.get_variable('test_regress_incdirs')
skip_warnlib = true
else
- gidatadir = gi.get_pkgconfig_variable('gidatadir')
+ gidatadir = gi.get_variable(pkgconfig: 'gidatadir')
gi_tests = gidatadir / 'tests'
regress_sources = [gi_tests / 'regress.c', gi_tests / 'regress.h']
warnlib_sources = [gi_tests / 'warnlib.c', gi_tests / 'warnlib.h']
@@ -154,10 +154,6 @@ if not get_option('skip_gtk_tests')
'GObjectDestructionAccess',
'LegacyGtk',
]
-
- if have_gtk4
- jasmine_tests += 'Gtk4'
- endif
endif
installed_js_tests_dir = installed_tests_execdir / 'js'
@@ -202,31 +198,40 @@ if get_option('installed_tests')
install_subdir('modules', install_dir: installed_js_tests_dir)
endif
-# testGDBus.js is separate, because it can be skipped, and during build should
-# be run using dbus-run-session
+# testGDBus.js and testGtk4.js are separate, because they can be skipped, and
+# during build should be run using dbus-run-session
-if not get_option('skip_dbus_tests')
- test_file = files('testGDBus.js')
- bus_config = files('../../test/test-bus.conf')
- test('GDBus', dbus_run_session,
- args: ['--config-file', bus_config, '--', minijasmine, test_file],
- env: tests_environment, protocol: 'tap', suite: 'dbus')
+dbus_tests = ['GDBus']
+if have_gtk4 and not get_option('skip_gtk_tests')
+ # FIXME: find out why GTK4 tries to acquire a message bus
+ dbus_tests += 'Gtk4'
endif
-gdbus_test_description_subst = {
- 'name': 'testGDBus.js',
- 'installed_tests_execdir': installed_tests_execdir,
-}
-gdbus_test_description = configure_file(
- configuration: gdbus_test_description_subst,
- input: '../minijasmine.test.in', output: 'testGDBus.test',
- install: get_option('installed_tests'),
- install_dir: installed_tests_metadir)
+bus_config = files('../../test/test-bus.conf')
+foreach test : dbus_tests
+ test_file = files('test@0@.js'.format(test))
-if get_option('installed_tests')
- install_data('matchers.js', 'testGDBus.js',
- install_dir: installed_js_tests_dir)
-endif
+ if not get_option('skip_dbus_tests')
+ test(test, dbus_run_session,
+ args: ['--config-file', bus_config, '--', minijasmine, test_file],
+ env: tests_environment, protocol: 'tap', suite: 'dbus')
+ endif
+
+ dbus_test_description_subst = {
+ 'name': 'test@0@.js'.format(test),
+ 'installed_tests_execdir': installed_tests_execdir,
+ }
+ dbus_test_description = configure_file(
+ configuration: dbus_test_description_subst,
+ input: '../minijasmine.test.in',
+ output: 'test@0@.test'.format(test),
+ install: get_option('installed_tests'),
+ install_dir: installed_tests_metadir)
+
+ if get_option('installed_tests')
+ install_data(test_file, install_dir: installed_js_tests_dir)
+ endif
+endforeach
# tests using ES modules are also separate because they need an extra
# minijasmine flag
@@ -265,3 +270,7 @@ foreach test : modules_tests
install_data(test_file, install_dir: installed_js_tests_dir)
endif
endforeach
+
+if get_option('installed_tests')
+ install_data('matchers.js', install_dir: installed_js_tests_dir)
+endif
diff --git a/installed-tests/js/testCairo.js b/installed-tests/js/testCairo.js
index e9ede59f..786bf2a2 100644
--- a/installed-tests/js/testCairo.js
+++ b/installed-tests/js/testCairo.js
@@ -115,8 +115,8 @@ describe('Cairo', function () {
yAdvance: 0,
});
expect(cr.textExtents('trailing spaces ')).toEqual({
- xBearing: 0,
- yBearing: -8,
+ xBearing: jasmine.any(Number),
+ yBearing: jasmine.any(Number),
width: jasmine.any(Number),
height: jasmine.any(Number),
xAdvance: jasmine.any(Number),
diff --git a/installed-tests/js/testGIMarshalling.js b/installed-tests/js/testGIMarshalling.js
index 97f8d542..2140f67b 100644
--- a/installed-tests/js/testGIMarshalling.js
+++ b/installed-tests/js/testGIMarshalling.js
@@ -1258,9 +1258,10 @@ let VFuncTester = GObject.registerClass(class VFuncTester extends GIMarshallingT
return i + 4;
}
- vfunc_method_str_arg_out_ret(s) {
- return [`Called with ${s}`, 41];
- }
+ // https://gitlab.gnome.org/GNOME/gjs/-/issues/519
+ // vfunc_method_str_arg_out_ret(s) {
+ // return [`Called with ${s}`, 41];
+ // }
vfunc_method_with_default_implementation(i) {
this.int = i + 2;
diff --git a/installed-tests/js/testRegress.js b/installed-tests/js/testRegress.js
index 60753a54..7e4f8bb8 100644
--- a/installed-tests/js/testRegress.js
+++ b/installed-tests/js/testRegress.js
@@ -1570,7 +1570,7 @@ describe('Life, the Universe and Everything', function () {
expect(callback).toHaveBeenCalled();
});
- it('null simple callback', function () {
+ it(`null ${type} callback`, function () {
expect(() => Regress[`test_${type}_callback`](null)).not.toThrow();
});
});
diff --git a/meson.build b/meson.build
index 0b34a5be..4e34dafd 100644
--- a/meson.build
+++ b/meson.build
@@ -14,7 +14,6 @@ project('gjs', 'cpp', 'c', version: '1.75.1', license: ['MIT', 'LGPL2+'],
api_version = '1.0'
api_name = '@0@-@1@'.format(meson.project_name(), api_version)
-fs = import('fs')
gnome = import('gnome')
pkg = import('pkgconfig')
@@ -661,7 +660,7 @@ tests_environment.set('G_DEBUG', 'fatal-warnings,fatal-criticals')
tests_locale = 'N/A'
if cxx.get_argument_syntax() != 'msvc'
- result = run_command('build/choose-tests-locale.sh')
+ result = run_command('build/choose-tests-locale.sh', check: false)
if result.returncode() == 0
tests_locale = result.stdout().strip()
tests_environment.set('LC_ALL', tests_locale)
@@ -771,14 +770,14 @@ libdir = get_option('libdir')
datadir = get_option('datadir')
summary({
'prefix': prefix,
- 'bindir': fs.is_absolute(bindir) ? bindir : prefix / bindir,
- 'libdir': fs.is_absolute(libdir) ? libdir : prefix / libdir,
- 'datadir': fs.is_absolute(datadir) ? datadir : prefix / datadir,
+ 'bindir': prefix / bindir,
+ 'libdir': prefix / libdir,
+ 'datadir': prefix / datadir,
}, section: 'Directories')
locations = []
foreach dep: [ffi, glib, gi, spidermonkey, readline, sysprof_capture]
if dep.type_name() == 'pkgconfig'
- locations += 'in @0@'.format(dep.get_pkgconfig_variable('prefix'))
+ locations += 'in @0@'.format(dep.get_variable(pkgconfig: 'prefix'))
else
locations += dep.type_name()
endif
@@ -806,11 +805,11 @@ summary({
'Skip GTK tests': get_option('skip_gtk_tests'),
'Extra debug logs': get_option('verbose_logs'),
'Precompiled headers': get_option('b_pch'),
-}, section: 'Build options')
+}, section: 'Build options', bool_yn: true)
summary({
'Cairo module': build_cairo,
'Use readline for input': build_readline,
'Profiler (Linux only)': build_profiler,
'Dtrace debugging': get_option('dtrace'),
'Systemtap debugging': get_option('systemtap'),
-}, section: 'Optional features')
+}, section: 'Optional features', bool_yn: true)
diff --git a/modules/esm/console.js b/modules/esm/console.js
index a3e9ada3..74a34666 100644
--- a/modules/esm/console.js
+++ b/modules/esm/console.js
@@ -4,14 +4,6 @@
import GLib from 'gi://GLib';
import GjsPrivate from 'gi://GjsPrivate';
-const sLogger = Symbol('Logger');
-const sPrinter = Symbol('Printer');
-const sFormatter = Symbol('Formatter');
-const sGroupIndentation = Symbol('GroupIndentation');
-const sTimeLabels = Symbol('Time Labels');
-const sCountLabels = Symbol('Count Labels');
-const sLogDomain = Symbol('Log Domain');
-
const DEFAULT_LOG_DOMAIN = 'Gjs-Console';
// A line-by-line implementation of https://console.spec.whatwg.org/.
@@ -66,45 +58,14 @@ function formatOptimally(item) {
return JSON.stringify(item, null, 4);
}
-const propertyAttributes = {
- writable: true,
- enumerable: false,
- configurable: true,
-};
-
-/**
- * @typedef ConsoleInternalProps
- * @property {string} [sGroupIndentation]
- * @property {Record<string, number>} [sCountLabels]
- * @property {Record<string, number>} [sTimeLabels]
- * @property {string} [sLogDomain]
- */
-
/**
* Implementation of the WHATWG Console object.
- *
- * @implements {ConsoleInternalProps}
*/
-// @ts-expect-error Console does not actually implement ConsoleInternalProps,
-// once private class fields are merged we will remove the interface.
class Console {
- constructor() {
- // Redefine the internal functions as non-enumerable.
- Object.defineProperties(this, {
- [sLogger]: {
- ...propertyAttributes,
- value: this[sLogger].bind(this),
- },
- [sFormatter]: {
- ...propertyAttributes,
- value: this[sFormatter].bind(this),
- },
- [sPrinter]: {
- ...propertyAttributes,
- value: this[sPrinter].bind(this),
- },
- });
- }
+ #groupIndentation = '';
+ #countLabels = {};
+ #timeLabels = {};
+ #logDomain = DEFAULT_LOG_DOMAIN;
get [Symbol.toStringTag]() {
return 'Console';
@@ -137,7 +98,7 @@ class Console {
const first = data.shift();
data.unshift(`${message}: ${first}`);
}
- this[sLogger]('assert', data);
+ this.#logger('assert', data);
}
/**
@@ -150,7 +111,7 @@ class Console {
* @returns {void}
*/
clear() {
- this[sGroupIndentation] = '';
+ this.#groupIndentation = '';
GjsPrivate.clear_terminal();
}
@@ -160,7 +121,7 @@ class Console {
* @param {...any} data formatting substitutions, if applicable
*/
debug(...data) {
- this[sLogger]('debug', data);
+ this.#logger('debug', data);
}
/**
@@ -171,7 +132,7 @@ class Console {
* @param {...any} data formatting substitutions, if applicable
*/
error(...data) {
- this[sLogger]('error', data);
+ this.#logger('error', data);
}
/**
@@ -180,7 +141,7 @@ class Console {
* @param {...any} data formatting substitutions, if applicable
*/
info(...data) {
- this[sLogger]('info', data);
+ this.#logger('info', data);
}
/**
@@ -189,7 +150,7 @@ class Console {
* @param {...any} data formatting substitutions, if applicable
*/
log(...data) {
- this[sLogger]('log', data);
+ this.#logger('log', data);
}
// 1.1.7 table(tabularData, properties)
@@ -205,8 +166,7 @@ class Console {
if (data.length === 0)
data = ['Trace'];
- const {[sLogger]: Logger} = this;
- Logger('trace', data);
+ this.#logger('trace', data);
}
/**
@@ -216,8 +176,7 @@ class Console {
* @returns {void}
*/
warn(...data) {
- const {[sLogger]: Logger} = this;
- Logger('warn', data);
+ this.#logger('warn', data);
}
/**
@@ -227,8 +186,7 @@ class Console {
*/
dir(item, options) {
const object = formatGenerically(item);
-
- this[sPrinter]('dir', [object], options);
+ this.#printer('dir', [object], options);
}
/**
@@ -251,11 +209,11 @@ class Console {
* @returns {void}
*/
count(label) {
- this[sCountLabels][label] = this[sCountLabels][label] ?? 0;
- const count = ++this[sCountLabels][label];
+ this.#countLabels[label] ??= 0;
+ const count = ++this.#countLabels[label];
const concat = `${label}: ${count}`;
- this[sLogger]('count', [concat]);
+ this.#logger('count', [concat]);
}
/**
@@ -263,14 +221,11 @@ class Console {
* @returns {void}
*/
countReset(label) {
- const {[sPrinter]: Printer} = this;
-
- const count = this[sCountLabels][label];
-
+ const count = this.#countLabels[label];
if (typeof count !== 'number')
- Printer('reportWarning', [`No count found for label: '${label}'.`]);
+ this.#printer('reportWarning', [`No count found for label: '${label}'.`]);
else
- this[sCountLabels][label] = 0;
+ this.#countLabels[label] = 0;
}
// 1.3 Grouping functions
@@ -281,11 +236,8 @@ class Console {
* @returns {void}
*/
group(...data) {
- const {[sLogger]: Logger} = this;
-
- Logger('group', data);
-
- this[sGroupIndentation] += ' ';
+ this.#logger('group', data);
+ this.#groupIndentation += ' ';
}
/**
@@ -304,7 +256,7 @@ class Console {
* @returns {void}
*/
groupEnd() {
- this[sGroupIndentation] = this[sGroupIndentation].slice(0, -2);
+ this.#groupIndentation = this.#groupIndentation.slice(0, -2);
}
// 1.4 Timing functions
@@ -316,7 +268,7 @@ class Console {
* @returns {void}
*/
time(label) {
- this[sTimeLabels][label] = GLib.get_monotonic_time();
+ this.#timeLabels[label] = GLib.get_monotonic_time();
}
/**
@@ -329,12 +281,10 @@ class Console {
* @returns {void}
*/
timeLog(label, ...data) {
- const {[sPrinter]: Printer} = this;
-
- const startTime = this[sTimeLabels][label];
+ const startTime = this.#timeLabels[label];
if (typeof startTime !== 'number') {
- Printer('reportWarning', [
+ this.#printer('reportWarning', [
`No time log found for label: '${label}'.`,
]);
} else {
@@ -342,7 +292,7 @@ class Console {
const concat = `${label}: ${durationMs.toFixed(3)} ms`;
data.unshift(concat);
- Printer('timeLog', data);
+ this.#printer('timeLog', data);
}
}
@@ -355,20 +305,19 @@ class Console {
* @returns {void}
*/
timeEnd(label) {
- const {[sPrinter]: Printer} = this;
- const startTime = this[sTimeLabels][label];
+ const startTime = this.#timeLabels[label];
if (typeof startTime !== 'number') {
- Printer('reportWarning', [
+ this.#printer('reportWarning', [
`No time log found for label: '${label}'.`,
]);
} else {
- delete this[sTimeLabels][label];
+ delete this.#timeLabels[label];
const durationMs = (GLib.get_monotonic_time() - startTime) / 1000;
const concat = `${label}: ${durationMs.toFixed(3)} ms`;
- Printer('timeEnd', [concat]);
+ this.#printer('timeEnd', [concat]);
}
}
@@ -408,14 +357,14 @@ class Console {
* @returns {void}
*/
setLogDomain(logDomain) {
- this[sLogDomain] = String(logDomain);
+ this.#logDomain = String(logDomain);
}
/**
* @returns {string}
*/
get logDomain() {
- return this[sLogDomain];
+ return this.#logDomain;
}
// 2. Supporting abstract operations
@@ -433,27 +382,25 @@ class Console {
* @param {unknown[]} args the arguments to pass to the printer
* @returns {void}
*/
- [sLogger](logLevel, args) {
- const {[sFormatter]: Formatter, [sPrinter]: Printer} = this;
-
+ #logger(logLevel, args) {
if (args.length === 0)
return;
const [first, ...rest] = args;
if (rest.length === 0) {
- Printer(logLevel, [first]);
+ this.#printer(logLevel, [first]);
return undefined;
}
// If first does not contain any format specifiers, don't call Formatter
if (typeof first !== 'string' || !hasFormatSpecifiers(first)) {
- Printer(logLevel, args);
+ this.#printer(logLevel, args);
return undefined;
}
// Otherwise, perform print the result of Formatter.
- Printer(logLevel, Formatter([first, ...rest]));
+ this.#printer(logLevel, this.#formatter([first, ...rest]));
return undefined;
}
@@ -465,9 +412,7 @@ class Console {
* @param {[string, ...any[]]} args an array of format strings followed by
* their arguments
*/
- [sFormatter](args) {
- const {[sFormatter]: Formatter} = this;
-
+ #formatter(args) {
// The initial formatting string is the first arg
let target = args[0];
@@ -529,7 +474,7 @@ class Console {
if (result.length === 1)
return result;
- return Formatter(result);
+ return this.#formatter(result);
}
/**
@@ -554,7 +499,7 @@ class Console {
* printer
* @returns {void}
*/
- [sPrinter](logLevel, args, options) {
+ #printer(logLevel, args, options) {
let severity;
switch (logLevel) {
@@ -605,7 +550,7 @@ class Console {
})
.join(' ');
- let formattedOutput = this[sGroupIndentation] + output;
+ let formattedOutput = this.#groupIndentation + output;
const extraFields = {};
let stackTrace = options?.stackTrace;
@@ -623,10 +568,10 @@ class Console {
if (logLevel === 'trace') {
if (stackTrace?.length) {
formattedOutput += `\n${stackTrace.map(s =>
- `${this[sGroupIndentation]}${s}`).join('\n')}`;
+ `${this.#groupIndentation}${s}`).join('\n')}`;
} else {
formattedOutput +=
- `\n${this[sGroupIndentation]}No trace available`;
+ `\n${this.#groupIndentation}No trace available`;
}
}
@@ -646,7 +591,7 @@ class Console {
}
}
- GLib.log_structured(this[sLogDomain], severity, {
+ GLib.log_structured(this.#logDomain, severity, {
MESSAGE: formattedOutput,
...extraFields,
...options?.fields ?? {},
@@ -654,27 +599,6 @@ class Console {
}
}
-Object.defineProperties(Console.prototype, {
- [sGroupIndentation]: {
- ...propertyAttributes,
- value: '',
- },
- [sCountLabels]: {
- ...propertyAttributes,
- /** @type {Record<string, number>} */
- value: {},
- },
- [sTimeLabels]: {
- ...propertyAttributes,
- /** @type {Record<string, number>} */
- value: {},
- },
- [sLogDomain]: {
- ...propertyAttributes,
- value: DEFAULT_LOG_DOMAIN,
- },
-});
-
const console = new Console();
/**
diff --git a/modules/script/_bootstrap/debugger.js b/modules/script/_bootstrap/debugger.js
index c25893e0..e57d6c3c 100644
--- a/modules/script/_bootstrap/debugger.js
+++ b/modules/script/_bootstrap/debugger.js
@@ -69,9 +69,7 @@ function debuggeeValueToString(dv, style = {pretty: options.pretty}) {
if (style.noerror)
return [dvrepr, undefined];
- const substyle = {};
- Object.assign(substyle, style);
- substyle.noerror = true;
+ const substyle = {...style, noerror: true};
return [dvrepr, debuggeeValueToString(str.throw, substyle)];
}