GNOME Shell 扩展的猴子补丁后,this.parent 是意外的
After GNOME Shell extension's monkey-patching, this.parent is unexpected
对于raise-activated GNOME Shell 3.16 extension I'm trying to monkey-patch the AppSwitcherPopup._finish
method. Like the original,补丁版本调用this.parent
:
function _modifiedFinish(timestamp) {
// ...monkey-patched code...
this.parent(timestamp);
}
function enable() {
_originalFinish = AltTab.AppSwitcherPopup.prototype._finish;
AltTab.AppSwitcherPopup.prototype._finish = _modifiedFinish;
}
但我在控制台中得到了这个堆栈跟踪(来自 运行 gnome-shell --replace
):
(gnome-shell:24452): Gjs-WARNING **: JS ERROR: TypeError: The method '_keyReleaseEvent' is not on the superclass
_parent@resource:///org/gnome/gjs/modules/lang.js:129
_modifiedFinish@/home/lastorset/.local/share/gnome-shell/extensions/Alt_Tab_Mod_Only_Raise_Activated_Window@dsboger.com.br/extension.js:34
SwitcherPopup<._keyReleaseEvent@resource:///org/gnome/shell/ui/switcherPopup.js:199
wrapper@resource:///org/gnome/gjs/modules/lang.js:169
在这种情况下,SwitcherPopup._keyReleaseEvent
正在调用this
,this
应该是AppSwitcherPopup
子类的一个实例.我相信 this.parent
打补丁后应该是一样的——为什么现在要尝试调用调用者?就此而言,为什么不成功?
我查找了生成 this.parent
的 GJS code,但我不太清楚缺少什么。
在深入研究之后,我找到了修复它的方法。在GJS class 模型中, parent
函数实际上是在寻找方法所有者的superclass 以便调用同名方法。看起来每个 GJS class 都有一个设置 _owner
的 wrapFunction 助手。我用它来修补函数:
AltTab.AppSwitcherPopup.prototype._finish = AltTab.AppSwitcherPopup.wrapFunction('_finish', _modifiedFinish);
对于raise-activated GNOME Shell 3.16 extension I'm trying to monkey-patch the AppSwitcherPopup._finish
method. Like the original,补丁版本调用this.parent
:
function _modifiedFinish(timestamp) {
// ...monkey-patched code...
this.parent(timestamp);
}
function enable() {
_originalFinish = AltTab.AppSwitcherPopup.prototype._finish;
AltTab.AppSwitcherPopup.prototype._finish = _modifiedFinish;
}
但我在控制台中得到了这个堆栈跟踪(来自 运行 gnome-shell --replace
):
(gnome-shell:24452): Gjs-WARNING **: JS ERROR: TypeError: The method '_keyReleaseEvent' is not on the superclass
_parent@resource:///org/gnome/gjs/modules/lang.js:129
_modifiedFinish@/home/lastorset/.local/share/gnome-shell/extensions/Alt_Tab_Mod_Only_Raise_Activated_Window@dsboger.com.br/extension.js:34
SwitcherPopup<._keyReleaseEvent@resource:///org/gnome/shell/ui/switcherPopup.js:199
wrapper@resource:///org/gnome/gjs/modules/lang.js:169
在这种情况下,SwitcherPopup._keyReleaseEvent
正在调用this
,this
应该是AppSwitcherPopup
子类的一个实例.我相信 this.parent
打补丁后应该是一样的——为什么现在要尝试调用调用者?就此而言,为什么不成功?
我查找了生成 this.parent
的 GJS code,但我不太清楚缺少什么。
在深入研究之后,我找到了修复它的方法。在GJS class 模型中, parent
函数实际上是在寻找方法所有者的superclass 以便调用同名方法。看起来每个 GJS class 都有一个设置 _owner
的 wrapFunction 助手。我用它来修补函数:
AltTab.AppSwitcherPopup.prototype._finish = AltTab.AppSwitcherPopup.wrapFunction('_finish', _modifiedFinish);