[gnome-maps/wip/mattiasb/dont_forin_traverse_arrays: 2/3] Don't traverse arrays with for..in-loops
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mattiasb/dont_forin_traverse_arrays: 2/3] Don't traverse arrays with for..in-loops
- Date: Fri, 17 Feb 2017 22:10:14 +0000 (UTC)
commit c5f7d11da9e7835130ecad7d5e0b1ef06eb93aff
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Fri Feb 17 02:01:07 2017 +0100
Don't traverse arrays with for..in-loops
Traversing arrays with for .. in-loops can have unexpected consequences.
In short: never do that, use Array.prototype.forEach or for..of-loops
instead.
https://bugzilla.gnome.org/show_bug.cgi?id=778800
src/checkInDialog.js | 5 ++---
src/osmConnection.js | 9 ++++-----
src/shapeLayer.js | 3 +--
src/utils.js | 8 ++++----
4 files changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/src/checkInDialog.js b/src/checkInDialog.js
index 02a42ba..61134a4 100644
--- a/src/checkInDialog.js
+++ b/src/checkInDialog.js
@@ -162,9 +162,8 @@ const CheckInDialog = new Lang.Class({
if (!Application.checkInManager.hasCheckIn)
this.response(Response.FAILURE_CHECKIN_DISABLED);
else if (this._account) {
- for (let i in accounts) {
- let account = accounts[i];
- if (this._account.get_account().id === accounts[i].get_account().id)
+ for (let account of accounts) {
+ if (this._account.get_account().id === account.get_account().id)
return;
}
diff --git a/src/osmConnection.js b/src/osmConnection.js
index 39d4e17..8270cb9 100644
--- a/src/osmConnection.js
+++ b/src/osmConnection.js
@@ -398,9 +398,9 @@ const OSMConnection = new Lang.Class({
return null;
let cookieParts = cookie.split(';');
- for (let index in cookieParts) {
- let kvPair = cookieParts[index].trim();
- let kv = kvPair.split('=');
+ for (let cookiePart of cookieParts) {
+ let kvPair = cookiePart.trim().split('=');
+ let kv = kvPair;
if (kv.length !== 2) {
continue;
@@ -418,8 +418,7 @@ const OSMConnection = new Lang.Class({
let regex = /.*authenticity_token.*value=\"([^\"]+)\".*/;
let lines = messageBody.split('\n');
- for (let i in lines) {
- let line = lines[i];
+ for (let line of lines) {
let match = line.match(regex);
if (match && match.length === 2)
diff --git a/src/shapeLayer.js b/src/shapeLayer.js
index b6b3a8e..0cd6477 100644
--- a/src/shapeLayer.js
+++ b/src/shapeLayer.js
@@ -26,8 +26,7 @@ const SUPPORTED_TYPES = [];
function newFromFile(file, mapView) {
let contentType = Gio.content_type_guess(file.get_uri(), null)[0];
- for (let i in SUPPORTED_TYPES) {
- let layerClass = SUPPORTED_TYPES[i];
+ for (let layerClass of SUPPORTED_TYPES) {
if (layerClass.mimeTypes.indexOf(contentType) > -1) {
return new layerClass({ file: file, mapView: mapView });
}
diff --git a/src/utils.js b/src/utils.js
index f9c7151..1e29dbe 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -371,13 +371,13 @@ function uriSchemeSupported(scheme) {
let apps = Gio.AppInfo.get_all();
let prefix = 'x-scheme-handler/';
- for (let i in apps) {
- let types = apps[i].get_supported_types();
+ for (let app of apps) {
+ let types = app.get_supported_types();
if (!types)
continue;
- for (let j in types) {
- if (types[j].replace(prefix, '') === scheme)
+ for (let type of types) {
+ if (type.replace(prefix, '') === scheme)
return true;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]