signalTracker: Correctly guard against invalid GObject.ConnectFlags

We considered any ConnectFlag value major than SWAPPED as invalid, while
it's technically not fully true as we need to ensure that the passed
value is respecting the whole flags mask.
In fact, per se SWAPPED|AFTER (> SWAPPED) is a valid value (even if we
don't support the AFTER value).

But this makes the check more future-proof.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2366>
This commit is contained in:
Marco Trevisan (Treviño) 2022-07-06 17:55:46 +02:00
parent ad0f11f024
commit 371da8d394

View File

@ -184,16 +184,18 @@ function connectObject(thisObj, ...args) {
return [signalName, handler, 0, arg, ...rest]; return [signalName, handler, 0, arg, ...rest];
const flags = arg; const flags = arg;
if (flags > GObject.ConnectFlags.SWAPPED) let flagsMask = 0;
Object.values(GObject.ConnectFlags).forEach(v => (flagsMask |= v));
if (!(flags & flagsMask))
throw new Error(`Invalid flag value ${flags}`); throw new Error(`Invalid flag value ${flags}`);
if (flags === GObject.ConnectFlags.SWAPPED) if (flags & GObject.ConnectFlags.SWAPPED)
throw new Error('Swapped signals are not supported'); throw new Error('Swapped signals are not supported');
return [signalName, handler, flags, ...rest]; return [signalName, handler, flags, ...rest];
}; };
const connectSignal = (emitter, signalName, handler, flags) => { const connectSignal = (emitter, signalName, handler, flags) => {
const isGObject = emitter instanceof GObject.Object; const isGObject = emitter instanceof GObject.Object;
const func = flags === GObject.ConnectFlags.AFTER && isGObject const func = (flags & GObject.ConnectFlags.AFTER) && isGObject
? 'connect_after' ? 'connect_after'
: 'connect'; : 'connect';
const emitterProto = isGObject const emitterProto = isGObject