зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1283186 - Only print error instead of throwing when a key shortcut is invalid. r=bgrins
This commit is contained in:
Родитель
569e667c08
Коммит
43a3ab0728
|
@ -122,7 +122,8 @@ KeyShortcuts.parseElectronKey = function (window, str) {
|
|||
} else if (mod === "Shift") {
|
||||
shortcut.shift = true;
|
||||
} else {
|
||||
throw new Error("Unsupported modifier: " + mod);
|
||||
console.error("Unsupported modifier:", mod, "from key:", str);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +143,8 @@ KeyShortcuts.parseElectronKey = function (window, str) {
|
|||
// Used only to stringify the shortcut
|
||||
shortcut.keyCodeString = key;
|
||||
} else {
|
||||
throw new Error("Unsupported key: " + key);
|
||||
console.error("Unsupported key:", key);
|
||||
return null;
|
||||
}
|
||||
|
||||
return shortcut;
|
||||
|
@ -220,6 +222,10 @@ KeyShortcuts.prototype = {
|
|||
}
|
||||
if (!this.keys.has(key)) {
|
||||
let shortcut = KeyShortcuts.parseElectronKey(this.window, key);
|
||||
// The key string is wrong and we were unable to compute the key shortcut
|
||||
if (!shortcut) {
|
||||
return;
|
||||
}
|
||||
this.keys.set(key, shortcut);
|
||||
}
|
||||
this.eventEmitter.on(key, listener);
|
||||
|
|
|
@ -18,6 +18,7 @@ add_task(function* () {
|
|||
yield testAltModifier(shortcuts);
|
||||
yield testCommandOrControlModifier(shortcuts);
|
||||
yield testCtrlModifier(shortcuts);
|
||||
yield testInvalidShortcutString(shortcuts);
|
||||
shortcuts.destroy();
|
||||
|
||||
yield testTarget();
|
||||
|
@ -362,3 +363,13 @@ function testTarget() {
|
|||
|
||||
shortcuts.destroy();
|
||||
}
|
||||
|
||||
function testInvalidShortcutString(shortcuts) {
|
||||
info("Test wrong shortcut string");
|
||||
|
||||
let shortcut = KeyShortcuts.parseElectronKey(window, "Cmmd+F");
|
||||
ok(!shortcut, "Passing a invalid shortcut string should return a null object");
|
||||
|
||||
shortcuts.on("Cmmd+F", function () {});
|
||||
ok(true, "on() shouldn't throw when passing invalid shortcut string");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче