Add a hack to block calls to certain introspected functions
This is useful for keeping people from using methods that only fail in certain circumstances, by making them fail in all circumstances instead. https://bugzilla.gnome.org/show_bug.cgi?id=618918
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
|
||||
const Shell = imports.gi.Shell;
|
||||
const St = imports.gi.St;
|
||||
const Gettext_gtk20 = imports.gettext.domain('gtk20');
|
||||
|
||||
@ -28,8 +29,34 @@ function _patchContainerClass(containerClass) {
|
||||
};
|
||||
}
|
||||
|
||||
_patchContainerClass(St.BoxLayout);
|
||||
_patchContainerClass(St.Table);
|
||||
// Replace @method with something that throws an error instead
|
||||
function _blockMethod(method, replacement, reason) {
|
||||
let match = method.match(/^(.+)\.([^.]+)$/);
|
||||
if (!match)
|
||||
throw new Error('Bad method name "' + method + '"');
|
||||
let proto = 'imports.gi.' + match[1] + '.prototype';
|
||||
let property = match[2];
|
||||
|
||||
if (!global.set_property_mutable(proto, property, true))
|
||||
throw new Error('Bad method name "' + method + '"');
|
||||
|
||||
// eval() is evil in general, but we know it's safe here since
|
||||
// set_property_mutable() would have failed if proto was
|
||||
// malformed.
|
||||
let node = eval(proto);
|
||||
|
||||
let msg = 'Do not use "' + method + '".';
|
||||
if (replacement)
|
||||
msg += ' Use "' + replacement + '" instead.';
|
||||
if (reason)
|
||||
msg += ' (' + reason + ')';
|
||||
|
||||
node[property] = function() {
|
||||
throw new Error(msg);
|
||||
};
|
||||
|
||||
global.set_property_mutable(proto, property, false);
|
||||
}
|
||||
|
||||
function init() {
|
||||
Tweener.init();
|
||||
@ -39,4 +66,20 @@ function init() {
|
||||
if (Gettext_gtk20.gettext('default:LTR') == 'default:RTL') {
|
||||
St.Widget.set_default_direction(St.TextDirection.RTL);
|
||||
}
|
||||
|
||||
_patchContainerClass(St.BoxLayout);
|
||||
_patchContainerClass(St.Table);
|
||||
|
||||
_blockMethod('Clutter.Event.get_state', 'Shell.get_event_state',
|
||||
'gjs\'s handling of Clutter.ModifierType is broken. See bug 597292.');
|
||||
_blockMethod('Gdk.Display.get_pointer', 'global.get_pointer',
|
||||
'gjs\'s handling of Gdk.ModifierType is broken. See bug 597292.');
|
||||
_blockMethod('Gdk.Window.get_pointer', 'global.get_pointer',
|
||||
'gjs\'s handling of Gdk.ModifierType is broken. See bug 597292.');
|
||||
|
||||
// Now close the back door to prevent extensions from trying to
|
||||
// abuse it. We can't actually delete it since
|
||||
// Shell.Global.prototype itself is read-only.
|
||||
global.set_property_mutable('imports.gi.Shell.Global.prototype', 'set_property_mutable', true);
|
||||
Shell.Global.prototype.set_property_mutable = undefined;
|
||||
}
|
||||
|
Reference in New Issue
Block a user