Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/keySelector.js

Issue 5695444839563264: Issue 1434 - Remove some non-standard JS usage from buildtools. (Closed)
Patch Set: Created Sept. 24, 2014, 1:31 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/prefs.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/keySelector.js
===================================================================
--- a/lib/keySelector.js
+++ b/lib/keySelector.js
@@ -88,49 +88,63 @@ KeySelector.prototype =
let keyCode = key.getAttribute("keycode");
if (keyCode && "DOM_" + keyCode.toUpperCase() in Ci.nsIDOMKeyEvent)
keyData.code = Ci.nsIDOMKeyEvent["DOM_" + keyCode.toUpperCase()];
if (!keyData.char && !keyData.code)
continue;
- let keyModifiers = key.getAttribute("modifiers");
- if (keyModifiers)
- for each (let modifier in keyModifiers.toUpperCase().match(/\w+/g))
+ let modifiers = key.getAttribute("modifiers");
+ modifiers = modifiers ? modifiers.toUpperCase().match(/\w+/g) : null;
Wladimir Palant 2014/11/17 20:05:17 If you are doing it this way, why not use [] inste
+ if (modifiers)
+ {
+ for (let modifier of modifiers)
+ {
if (modifier in validModifiers)
keyData[validModifiers[modifier]] = true;
+ }
+ }
let canonical = [keyData.shift, keyData.meta, keyData.alt, keyData.control, keyData.char || keyData.code].join(" ");
this._existingShortcuts[canonical] = true;
}
},
/**
* Selects a keyboard shortcut variant that isn't already taken,
* parses it into an object.
*/
selectKey: function(/**String*/ variants) /**Object*/
{
- for each (let variant in variants.split(/\s*,\s*/))
+ variants = variants.split(/\s*,\s*/);
+ if (!variants)
Wladimir Palant 2014/11/17 20:05:17 This condition can never be true - String.split()
+ return null;
+
+ for (let variant of variants)
{
if (!variant)
continue;
let keyData =
{
shift: false,
meta: false,
alt: false,
control: false,
char: null,
code: null,
codeName: null
};
- for each (let part in variant.toUpperCase().split(/\s+/))
+
+ variant = variant.toUpperCase().split(/\s+/);
+ if (!variant)
Wladimir Palant 2014/11/17 20:05:17 Same here, this if block is pointless.
+ continue;
+
+ for (let part of variant)
{
if (part in validModifiers)
keyData[validModifiers[part]] = true;
else if (part.length == 1)
keyData.char = part;
else if ("DOM_VK_" + part in Ci.nsIDOMKeyEvent)
{
keyData.code = Ci.nsIDOMKeyEvent["DOM_VK_" + part];
« no previous file with comments | « no previous file | lib/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld