r91347 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91346‎ | r91347 | r91348 >
Date:09:09, 2 July 2011
Author:hartman
Status:resolved (Comments)
Tags:
Comment:
Correct for in loops on arrays.

Reported in bug 29106. Patch by Michael M.
Modified paths:
  • /trunk/extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js (modified) (history)
  • /trunk/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js
@@ -230,8 +230,8 @@
231231 tests++;
232232 }
233233 if ( window.console !== undefined ) {
234 - for ( message in messages ) {
235 - console.log( messages[message] );
 234+ for ( var i = 0; i < messages.length; i++ ) {
 235+ console.log( messages[i] );
236236 }
237237 }
238238 $(this)
Index: trunk/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js
@@ -9,7 +9,7 @@
1010 api : {
1111 addToToolbar : function( context, data ) {
1212
13 - var smooth = true, type;
 13+ var smooth = true, type, i;
1414
1515 for ( type in data ) {
1616 switch ( type ) {
@@ -93,9 +93,9 @@
9494 var $table = context.modules.toolbar.$toolbar.find(
9595 'div[rel=' + data.section + '].section ' + 'div[rel=' + data.page + '].page table'
9696 );
97 - for ( var row in data[type] ) {
 97+ for ( i = 0; i < data.rows.length; i++ ) {
9898 // Row
99 - $table.append( $.wikiEditor.modules.toolbar.fn.buildRow( context, data[type][row] ) );
 99+ $table.append( $.wikiEditor.modules.toolbar.fn.buildRow( context, data.rows[i] ) );
100100 }
101101 smooth = false;
102102 break;
@@ -107,11 +107,11 @@
108108 'div[rel=' + data.section + '].section ' + 'div[rel=' + data.page + '].page div'
109109 );
110110 var actions = $characters.data( 'actions' );
111 - for ( var character in data[type] ) {
 111+ for ( i = 0; data.character.length; i++ ) {
112112 // Character
113113 $characters
114114 .append(
115 - $( $.wikiEditor.modules.toolbar.fn.buildCharacter( data[type][character], actions ) )
 115+ $( $.wikiEditor.modules.toolbar.fn.buildCharacter( data.characters[i], actions ) )
116116 .mousedown( function( e ) {
117117 context.fn.saveCursorAndScrollTop();
118118 // No dragging!
@@ -321,8 +321,8 @@
322322 },
323323 buildTool : function( context, id, tool ) {
324324 if ( 'filters' in tool ) {
325 - for ( var filter in tool.filters ) {
326 - if ( $( tool.filters[filter] ).size() === 0 ) {
 325+ for ( var i = 0; i < tool.filters.length; i++ ) {
 326+ if ( $( tool.filters[i] ).size() === 0 ) {
327327 return null;
328328 }
329329 }
@@ -470,6 +470,7 @@
471471 } );
472472 },
473473 buildPage : function( context, id, page ) {
 474+ var html;
474475 var $page = $( '<div/>' ).attr( {
475476 'class' : 'page page-' + id,
476477 'rel' : id
@@ -477,14 +478,14 @@
478479 switch ( page.layout ) {
479480 case 'table':
480481 $page.addClass( 'page-table' );
481 - var html =
 482+ html =
482483 '<table cellpadding=0 cellspacing=0 ' + 'border=0 width="100%" class="table table-' + id + '">';
483484 if ( 'headings' in page ) {
484485 html += $.wikiEditor.modules.toolbar.fn.buildHeading( context, page.headings );
485486 }
486487 if ( 'rows' in page ) {
487 - for ( var row in page.rows ) {
488 - html += $.wikiEditor.modules.toolbar.fn.buildRow( context, page.rows[row] );
 488+ for ( var i = 0; i < page.rows.length; i++ ) {
 489+ html += $.wikiEditor.modules.toolbar.fn.buildRow( context, page.rows[i] );
489490 }
490491 }
491492 $page.html( html );
@@ -500,7 +501,7 @@
501502 $characters.attr( 'dir', page.direction );
502503 }
503504 if ( 'characters' in page ) {
504 - var html = '';
 505+ html = '';
505506 for ( var i = 0; i < page.characters.length; i++ ) {
506507 html += $.wikiEditor.modules.toolbar.fn.buildCharacter( page.characters[i], actions );
507508 }
@@ -530,8 +531,8 @@
531532 },
532533 buildHeading : function( context, headings ) {
533534 var html = '<tr>';
534 - for ( var heading in headings ) {
535 - html += '<th>' + $.wikiEditor.autoMsg( headings[heading], ['html', 'text'] ) + '</th>';
 535+ for ( var i = 0; i< headings.length; i++ ) {
 536+ html += '<th>' + $.wikiEditor.autoMsg( headings[i], ['html', 'text'] ) + '</th>';
536537 }
537538 return html;
538539 },

Follow-up revisions

RevisionCommit summaryAuthorDate
r91349Adding quotes for the [rel=] stuff, since this broke one test....hartman09:17, 2 July 2011
r91684One more fix for the for in loops....hartman20:54, 7 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89616Extension:WikiEditor Code quality, JSHint validation and JSPERF...krinkle23:18, 6 June 2011
r90845Bug #29106: Patch from Michael M. to address JS legacy globals in wikiEditormah19:25, 26 June 2011
r91342* Fix broken post call to api in side-to-side diffs...hartman08:46, 2 July 2011
r91343Clean up some global var leaking in WikiEditor toolbar...hartman08:54, 2 July 2011

Comments

#Comment by Schnark (talk | contribs)   07:37, 7 July 2011

Somehow there slipped some mistake in: Line 110 should be

for ( i = 0; i < data.characters.length; i++ ) {

The i < and the s are missing.

Status & tagging log