Skip to content
Permalink
Browse files

Use plain 'for' loops instead of 'for in' loops on arrays

  • Loading branch information
Will Mitchell authored and wakamoleguy committed May 21, 2013
1 parent d141864 commit d7c3c9ceb6405caa3b4f11f67ab7a629d179078d

Some generated files are not rendered by default. Learn more.

Large diffs are not rendered by default.

@@ -375,8 +375,9 @@ Call_ID = word ( "@" word )? {
// CONTACT

Contact = ( STAR / (contact_param (COMMA contact_param)*) ) {
var idx;
for (idx in data.multi_header) {
var idx, length;
length = data.multi_header.length;
for (idx = 0; idx < length; idx++) {
if (data.multi_header[idx].parsed === null) {
data = null;
break;
@@ -621,8 +622,9 @@ option_tag = token
// RECORD-ROUTE

Record_Route = rec_route (COMMA rec_route)* {
var idx;
for (idx in data.multi_header) {
var idx, length;
length = data.multi_header.length;
for (idx = 0; idx < length; idx++) {
if (data.multi_header[idx].parsed === null) {
data = null;
break;
@@ -46,7 +46,7 @@ function getHeader(data, headerStart) {
}

function parseHeader(message, data, headerStart, headerEnd) {
var header, idx, parsed,
var header, idx, length, parsed,
hcolonIndex = data.indexOf(':', headerStart),
headerName = data.substring(headerStart, hcolonIndex).trim(),
headerValue = data.substring(hcolonIndex + 1, headerEnd).trim();
@@ -91,7 +91,8 @@ function parseHeader(message, data, headerStart, headerEnd) {
parsed = undefined;
}

for(idx in parsed) {
length = parsed.length;
for (idx = 0; idx < length; idx++) {
header = parsed[idx];
message.addHeader('record-route', headerValue.substring(header.possition, header.offset));
message.headers['Record-Route'][message.countHeader('record-route')-1].parsed = header.parsed;
@@ -113,7 +114,8 @@ function parseHeader(message, data, headerStart, headerEnd) {
parsed = undefined;
}

for(idx in parsed) {
length = parsed.length;
for (idx = 0; idx < length; idx++) {
header = parsed[idx];
message.addHeader('contact', headerValue.substring(header.possition, header.offset));
message.headers['Contact'][message.countHeader('contact')-1].parsed = header.parsed;
@@ -41,7 +41,7 @@ RTCSession = function(ua) {
this.ua = ua;
this.status = C.STATUS_NULL;
this.dialog = null;
this.earlyDialogs = [];
this.earlyDialogs = {};
this.rtcMediaHandler = null;

// Session Timers
@@ -105,17 +105,20 @@ RTCMediaHandler.prototype = {
* @param {Function} onSuccess Fired when there are no more ICE candidates
*/
init: function(constraints) {
var idx, server, scheme, url,
var idx, length, server, scheme, url,
self = this,
servers = [];
servers = [],
config = this.session.ua.configuration;

for (idx in this.session.ua.configuration.stun_servers) {
server = this.session.ua.configuration.stun_servers[idx];
length = config.stun_servers.length;
for (idx = 0; idx < length; idx++) {
server = config.stun_servers[idx];
servers.push({'url': server});
}

for (idx in this.session.ua.configuration.turn_servers) {
server = this.session.ua.configuration.turn_servers[idx];
length = config.turn_servers.length;
for (idx = 0; idx < length; idx++) {
server = config.turn_servers[idx];
url = server.server;
scheme = url.substr(0, url.indexOf(':'));
servers.push({
@@ -103,14 +103,15 @@ OutgoingRequest.prototype = {

msg += this.method + ' ' + this.ruri + ' SIP/2.0\r\n';

for(header in this.headers) {
for(idx in this.headers[header]) {
for (header in this.headers) {
length = this.headers[header].length;
for (idx = 0; idx < length; idx++) {
msg += header + ': ' + this.headers[header][idx] + '\r\n';
}
}

length = this.extraHeaders.length;
for(idx=0; idx < length; idx++) {
for (idx = 0; idx < length; idx++) {
msg += this.extraHeaders[idx] +'\r\n';
}

@@ -208,15 +209,16 @@ IncomingMessage.prototype = {
* @returns {Array} Array with all the headers of the specified name.
*/
getHeaderAll: function(name) {
var idx,
var idx, length,
header = this.headers[JsSIP.Utils.headerize(name)],
result = [];

if(!header) {
return [];
}

for(idx in header) {
length = header.length;
for (idx = 0; idx < length; idx++) {
result.push(header[idx].raw);
}

@@ -369,7 +371,7 @@ IncomingRequest.prototype.reply = function(code, reason, extraHeaders, body, onS
response += 'CSeq: ' + this.cseq + ' ' + this.method + '\r\n';

length = extraHeaders.length;
for(idx=0; idx < length; idx++) {
for (idx = 0; idx < length; idx++) {
response += extraHeaders[idx] +'\r\n';
}

@@ -291,13 +291,14 @@ UA.prototype.getCredentials = function(request) {
*/
UA.prototype.onTransportClosed = function(transport) {
// Run _onTransportError_ callback on every client transaction using _transport_
var type, idx,
var type, idx, length,
client_transactions = ['nict', 'ict', 'nist', 'ist'];

transport.server.status = JsSIP.Transport.C.STATUS_DISCONNECTED;
console.log(LOG_PREFIX +'connection state set to '+ JsSIP.Transport.C.STATUS_DISCONNECTED);

for(type in client_transactions) {
length = client_transactions.length;
for (type = 0; type < length; type++) {
for(idx in this.transactions[client_transactions[type]]) {
this.transactions[client_transactions[type]][idx].onTransportError();
}
@@ -563,10 +564,11 @@ UA.prototype.findDialog = function(request) {
*/
UA.prototype.getNextWsServer = function() {
// Order servers by weight
var idx, ws_server,
var idx, length, ws_server,
candidates = [];

for (idx in this.configuration.ws_servers) {
length = this.configuration.ws_servers.length;
for (idx = 0; idx < length; idx++) {
ws_server = this.configuration.ws_servers[idx];

if (ws_server.status === JsSIP.Transport.C.STATUS_ERROR) {
@@ -603,12 +605,13 @@ UA.prototype.closeSessionsOnTransportError = function() {
};

UA.prototype.recoverTransport = function(ua) {
var idx, k, nextRetry, count, server;
var idx, length, k, nextRetry, count, server;

ua = ua || this;
count = ua.transportRecoverAttempts;

for (idx in ua.configuration.ws_servers) {
length = ua.configuration.ws_servers.length;
for (idx = 0; idx < length; idx++) {
ua.configuration.ws_servers[idx].status = 0;
}

@@ -902,7 +905,7 @@ UA.configuration_check = {
},

ws_servers: function(ws_servers) {
var idx, url;
var idx, length, url;

/* Allow defining ws_servers parameter as:
* String: "host"
@@ -913,7 +916,8 @@ UA.configuration_check = {
if (typeof ws_servers === 'string') {
ws_servers = [{ws_uri: ws_servers}];
} else if (ws_servers instanceof Array) {
for(idx in ws_servers) {
length = ws_servers.length;
for (idx = 0; idx < length; idx++) {
if (typeof ws_servers[idx] === 'string'){
ws_servers[idx] = {ws_uri: ws_servers[idx]};
}
@@ -926,7 +930,8 @@ UA.configuration_check = {
return false;
}

for (idx in ws_servers) {
length = ws_servers.length;
for (idx = 0; idx < length; idx++) {
if (!ws_servers[idx].ws_uri) {
console.error(LOG_PREFIX +'missing "ws_uri" attribute in ws_servers parameter');
return;
@@ -1057,15 +1062,16 @@ UA.configuration_check = {
},

stun_servers: function(stun_servers) {
var idx, stun_server;
var idx, length, stun_server;

if (typeof stun_servers === 'string') {
stun_servers = [stun_servers];
} else if (!(stun_servers instanceof Array)) {
return;
}

for (idx in stun_servers) {
length = stun_servers.length;
for (idx = 0; idx < length; idx++) {
stun_server = stun_servers[idx];
if (!(/^stuns?:/.test(stun_server))) {
stun_server = 'stun:' + stun_server;
@@ -1087,15 +1093,16 @@ UA.configuration_check = {
},

turn_servers: function(turn_servers) {
var idx, turn_server;
var idx, length, turn_server;

if (turn_servers instanceof Array) {
// Do nothing
} else {
turn_servers = [turn_servers];
}

for (idx in turn_servers) {
length = turn_servers.length;
for (idx = 0; idx < length; idx++) {
turn_server = turn_servers[idx];
if (!turn_server.server || !turn_server.username || !turn_server.password) {
return;
@@ -149,10 +149,11 @@ Utils= {
'Www-Authenticate': 'WWW-Authenticate'
},
name = string.toLowerCase().replace(/_/g,'-').split('-'),
hname = '', part;
hname = '',
parts = name.length, part;

for (part in name) {
if (part !== '0') {
for (part = 0; part < parts; part++) {
if (part !== 0) {
hname +='-';
}
hname += name[part].charAt(0).toUpperCase()+name[part].substring(1);

0 comments on commit d7c3c9c

Please sign in to comment.
You can’t perform that action at this time.