Skip to content

Commit 9a6b329

Browse files
author
Andrey Zaytsev
committed
Fix iteration on arrays
Sometimes Array.prototype is patched, "for in" works incorrect in that case - it iterates custom props from prototype. To fix this issue regular "for" with counter should be used instead.
1 parent bf43217 commit 9a6b329

14 files changed

Lines changed: 176 additions & 176 deletions

build/ableplayer.dist.js

Lines changed: 57 additions & 57 deletions
Large diffs are not rendered by default.

build/ableplayer.js

Lines changed: 57 additions & 57 deletions
Large diffs are not rendered by default.

build/ableplayer.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/buildplayer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@
533533
radioName = this.mediaId + '-' + popup + '-choice';
534534
if (popup === 'prefs') {
535535
prefCats = this.getPreferencesGroups();
536-
for (j in prefCats) {
536+
for (j = 0; j < prefCats.length; j++) {
537537
trackItem = $('<li></li>');
538538
prefCat = prefCats[j];
539539
if (prefCat === 'captions') {
@@ -582,7 +582,7 @@
582582
this.prefsPopup.append(trackList);
583583
}
584584
else {
585-
for (j in tracks) {
585+
for (j = 0; j < tracks.length; j++) {
586586
trackItem = $('<li></li>');
587587
track = tracks[j];
588588
radioId = this.mediaId + '-' + popup + '-' + j;
@@ -1205,7 +1205,7 @@
12051205

12061206
// combine left and right controls arrays for future reference
12071207
this.controls = [];
1208-
for (var sec in controlLayout) {
1208+
for (var sec in controlLayout) if (controlLayout.hasOwnProperty(sec)) {
12091209
this.controls = this.controls.concat(controlLayout[sec]);
12101210
}
12111211

scripts/caption.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
else {
111111
cues = [];
112112
}
113-
for (c in cues) {
113+
for (c = 0; c < cues.length; c++) {
114114
if ((cues[c].start <= now) && (cues[c].end > now)) {
115115
thisCaption = c;
116116
break;
@@ -161,40 +161,40 @@
161161
var result = [];
162162

163163
var flattenComponent = function (component) {
164-
var result = [];
164+
var result = [], ii;
165165
if (component.type === 'string') {
166166
result.push(component.value);
167167
}
168168
else if (component.type === 'v') {
169169
result.push('(' + component.value + ')');
170-
for (var ii in component.children) {
170+
for (ii = 0; ii < component.children.length; ii++) {
171171
result.push(flattenComponent(component.children[ii]));
172172
}
173173
}
174174
else if (component.type === 'i') {
175175
result.push('<em>');
176-
for (var ii in component.children) {
176+
for (ii = 0; ii < component.children.length; ii++) {
177177
result.push(flattenComponent(component.children[ii]));
178178
}
179179
result.push('</em>');
180180
}
181181
else if (component.type === 'b') {
182182
result.push('<strong>');
183-
for (var ii in component.children) {
183+
for (ii = 0; ii < component.children.length; ii++) {
184184
result.push(flattenComponent(component.children[ii]));
185185
}
186186
result.push('</strong>');
187187
}
188188
else {
189-
for (var ii in component.children) {
189+
for (ii = 0; ii < component.children.length; ii++) {
190190
result.push(flattenComponent(component.children[ii]));
191191
}
192192
}
193193
return result.join('');
194-
}
194+
};
195195

196196
if (typeof cue.components !== 'undefined') {
197-
for (var ii in cue.components.children) {
197+
for (var ii = 0; ii < cue.components.children.length; ii++) {
198198
result.push(flattenComponent(cue.components.children[ii]));
199199
}
200200
}

scripts/chapters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
}
6868
if (cues.length > 0) {
6969
$chaptersList = $('<ul>');
70-
for (c in cues) {
70+
for (c = 0; c < cues.length; c++) {
7171
thisChapter = c;
7272
$chapterItem = $('<li></li>');
7373
$chapterButton = $('<button>',{
@@ -150,7 +150,7 @@
150150
var chapters, i, thisChapterIndex, chapterLabel;
151151

152152
chapters = this.selectedChapters.cues;
153-
for (i in chapters) {
153+
for (i = 0; i < chapters.length; i++) {
154154
if ((chapters[i].start <= now) && (chapters[i].end > now)) {
155155
thisChapterIndex = i;
156156
break;

scripts/control.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,25 +1470,25 @@
14701470
var i, captions, descriptions, chapters, meta;
14711471

14721472
// Captions
1473-
for (i in this.captions) {
1473+
for (i = 0; i < this.captions.length; i++) {
14741474
if (this.captions[i].language === language) {
14751475
captions = this.captions[i];
14761476
}
14771477
}
14781478
// Chapters
1479-
for (i in this.chapters) {
1479+
for (i = 0; i < this.chapters.length; i++) {
14801480
if (this.chapters[i].language === language) {
14811481
chapters = this.chapters[i];
14821482
}
14831483
}
14841484
// Descriptions
1485-
for (var i in this.descriptions) {
1485+
for (i = 0; i < this.descriptions.length; i++) {
14861486
if (this.descriptions[i].language === language) {
14871487
descriptions = this.descriptions[i];
14881488
}
14891489
}
14901490
// Metadata
1491-
for (var i in this.meta) {
1491+
for (i = 0; i < this.meta.length; i++) {
14921492
if (this.meta[i].language === language) {
14931493
meta = this.meta[i];
14941494
}

scripts/description.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@
237237
result.push(component.value);
238238
}
239239
else {
240-
for (var ii in component.children) {
240+
for (var ii = 0; ii < component.children.length; ii++) {
241241
result.push(flattenComponentForDescription(component.children[ii]));
242242
}
243243
}
244244
return result.join('');
245-
}
245+
};
246246

247247
var cues;
248248
if (this.selectedDescriptions) {
@@ -254,7 +254,7 @@
254254
else {
255255
cues = [];
256256
}
257-
for (d in cues) {
257+
for (d = 0; d < cues.length; d++) {
258258
if ((cues[d].start <= now) && (cues[d].end > now)) {
259259
thisDescription = d;
260260
break;

scripts/dragdrop.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@
178178
});
179179

180180
// add a popup menu
181-
var $popup = this.createPopup(windowName);
182-
var $optionList = $('<ul></ul>');
183-
var radioName = this.mediaId + '-' + windowName + '-choice';
181+
$popup = this.createPopup(windowName);
182+
$optionList = $('<ul></ul>');
183+
radioName = this.mediaId + '-' + windowName + '-choice';
184184

185-
var options = [];
185+
options = [];
186186
options.push({
187187
'name': 'move',
188188
'label': this.tt.windowMove
@@ -191,17 +191,17 @@
191191
'name': 'resize',
192192
'label': this.tt.windowResize
193193
});
194-
for (var i in options) {
195-
var $optionItem = $('<li></li>');
196-
var option = options[i];
197-
var radioId = radioName + '-' + i;
198-
var $radioButton = $('<input>',{
194+
for (i = 0; i < options.length; i++) {
195+
$optionItem = $('<li></li>');
196+
option = options[i];
197+
radioId = radioName + '-' + i;
198+
$radioButton = $('<input>',{
199199
'type': 'radio',
200200
'val': option.name,
201201
'name': radioName,
202202
'id': radioId
203203
});
204-
var $radioLabel = $('<label>',{
204+
$radioLabel = $('<label>',{
205205
'for': radioId
206206
});
207207
$radioLabel.text(option.label);

scripts/initialize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@
343343

344344
// inject each of the hidden forms that will be accessed from the Preferences popup menu
345345
prefsGroups = thisObj.getPreferencesGroups();
346-
for (i in prefsGroups) {
346+
for (i = 0; i < prefsGroups.length; i++) {
347347
thisObj.injectPrefsForm(prefsGroups[i]);
348348
}
349349
thisObj.setupPopups();

0 commit comments

Comments
 (0)