[Pkg-javascript-commits] [pdf.js] 78/141: Fixes lint warning W004 in src/core

David Prévot taffit at moszumanska.debian.org
Sat Apr 19 22:40:32 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit df91acf23951ced605f9020291532d6171e9de19
Author: Tim van der Meij <timvandermeij at gmail.com>
Date:   Mon Apr 7 23:42:54 2014 +0200

    Fixes lint warning W004 in src/core
---
 src/core/bidi.js           |  57 +++----
 src/core/chunked_stream.js |  29 ++--
 src/core/cmap.js           |  13 +-
 src/core/crypto.js         |   2 +-
 src/core/evaluator.js      | 104 +++++++------
 src/core/font_renderer.js  | 120 +++++++--------
 src/core/fonts.js          | 360 ++++++++++++++++++++++++---------------------
 src/core/image.js          |  45 +++---
 src/core/jbig2.js          | 105 +++++++------
 src/core/jpx.js            | 163 ++++++++++----------
 src/core/obj.js            |  10 +-
 src/core/parser.js         |   6 +-
 src/core/pattern.js        |   5 +-
 src/core/stream.js         |  90 ++++++------
 14 files changed, 593 insertions(+), 516 deletions(-)

diff --git a/src/core/bidi.js b/src/core/bidi.js
index 39a15bd..a5aee27 100644
--- a/src/core/bidi.js
+++ b/src/core/bidi.js
@@ -77,7 +77,6 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
   }
 
   function findUnequal(arr, start, value) {
-    var j;
     for (var j = start, jj = arr.length; j < jj; ++j) {
       if (arr[j] != value) {
         return j;
@@ -164,7 +163,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
     types.length = 0;
     var numBidi = 0;
 
-    for (var i = 0; i < strLength; ++i) {
+    var i, ii;
+    for (i = 0; i < strLength; ++i) {
       chars[i] = str.charAt(i);
 
       var charCode = str.charCodeAt(i);
@@ -204,7 +204,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
     }
 
     var levels = [];
-    for (var i = 0; i < strLength; ++i) {
+    for (i = 0; i < strLength; ++i) {
       levels[i] = startLevel;
     }
 
@@ -221,7 +221,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
      start of the level run, it will get the type of sor.
      */
     var lastType = sor;
-    for (var i = 0; i < strLength; ++i) {
+    for (i = 0; i < strLength; ++i) {
       if (types[i] == 'NSM') {
         types[i] = lastType;
       } else {
@@ -234,9 +234,10 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
      first strong type (R, L, AL, or sor) is found.  If an AL is found, change
      the type of the European number to Arabic number.
      */
-    var lastType = sor;
-    for (var i = 0; i < strLength; ++i) {
-      var t = types[i];
+    lastType = sor;
+    var t;
+    for (i = 0; i < strLength; ++i) {
+      t = types[i];
       if (t == 'EN') {
         types[i] = (lastType == 'AL') ? 'AN' : 'EN';
       } else if (t == 'R' || t == 'L' || t == 'AL') {
@@ -247,8 +248,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
     /*
      W3. Change all ALs to R.
      */
-    for (var i = 0; i < strLength; ++i) {
-      var t = types[i];
+    for (i = 0; i < strLength; ++i) {
+      t = types[i];
       if (t == 'AL') {
         types[i] = 'R';
       }
@@ -259,7 +260,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
      European number. A single common separator between two numbers of the same
      type changes to that type:
      */
-    for (var i = 1; i < strLength - 1; ++i) {
+    for (i = 1; i < strLength - 1; ++i) {
       if (types[i] == 'ES' && types[i - 1] == 'EN' && types[i + 1] == 'EN') {
         types[i] = 'EN';
       }
@@ -273,17 +274,18 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
      W5. A sequence of European terminators adjacent to European numbers changes
      to all European numbers:
      */
-    for (var i = 0; i < strLength; ++i) {
+    for (i = 0; i < strLength; ++i) {
       if (types[i] == 'EN') {
         // do before
-        for (var j = i - 1; j >= 0; --j) {
+        var j;
+        for (j = i - 1; j >= 0; --j) {
           if (types[j] != 'ET') {
             break;
           }
           types[j] = 'EN';
         }
         // do after
-        for (var j = i + 1; j < strLength; --j) {
+        for (j = i + 1; j < strLength; --j) {
           if (types[j] != 'ET') {
             break;
           }
@@ -295,8 +297,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
     /*
      W6. Otherwise, separators and terminators change to Other Neutral:
      */
-    for (var i = 0; i < strLength; ++i) {
-      var t = types[i];
+    for (i = 0; i < strLength; ++i) {
+      t = types[i];
       if (t == 'WS' || t == 'ES' || t == 'ET' || t == 'CS') {
         types[i] = 'ON';
       }
@@ -307,9 +309,9 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
      first strong type (R, L, or sor) is found. If an L is found,  then change
      the type of the European number to L.
      */
-    var lastType = sor;
-    for (var i = 0; i < strLength; ++i) {
-      var t = types[i];
+    lastType = sor;
+    for (i = 0; i < strLength; ++i) {
+      t = types[i];
       if (t == 'EN') {
         types[i] = ((lastType == 'L') ? 'L' : 'EN');
       } else if (t == 'R' || t == 'L') {
@@ -323,7 +325,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
      numbers are treated as though they were R. Start-of-level-run (sor) and
      end-of-level-run (eor) are used at level run boundaries.
      */
-    for (var i = 0; i < strLength; ++i) {
+    for (i = 0; i < strLength; ++i) {
       if (types[i] == 'ON') {
         var end = findUnequal(types, i + 1, 'ON');
         var before = sor;
@@ -351,7 +353,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
     /*
      N2. Any remaining neutrals take the embedding direction.
      */
-    for (var i = 0; i < strLength; ++i) {
+    for (i = 0; i < strLength; ++i) {
       if (types[i] == 'ON') {
         types[i] = e;
       }
@@ -364,8 +366,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
      I2. For all characters with an odd (right-to-left) embedding direction,
      those of type L, EN or AN go up one level.
      */
-    for (var i = 0; i < strLength; ++i) {
-      var t = types[i];
+    for (i = 0; i < strLength; ++i) {
+      t = types[i];
       if (isEven(levels[i])) {
         if (t == 'R') {
           levels[i] += 1;
@@ -401,8 +403,9 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
     // find highest level & lowest odd level
     var highestLevel = -1;
     var lowestOddLevel = 99;
-    for (var i = 0, ii = levels.length; i < ii; ++i) {
-      var level = levels[i];
+    var level;
+    for (i = 0, ii = levels.length; i < ii; ++i) {
+      level = levels[i];
       if (highestLevel < level) {
         highestLevel = level;
       }
@@ -412,10 +415,10 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
     }
 
     // now reverse between those limits
-    for (var level = highestLevel; level >= lowestOddLevel; --level) {
+    for (level = highestLevel; level >= lowestOddLevel; --level) {
       // find segments to reverse
       var start = -1;
-      for (var i = 0, ii = levels.length; i < ii; ++i) {
+      for (i = 0, ii = levels.length; i < ii; ++i) {
         if (levels[i] < level) {
           if (start >= 0) {
             reverseValues(chars, start, i);
@@ -449,7 +452,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
 
     // Finally, return string
     var result = '';
-    for (var i = 0, ii = chars.length; i < ii; ++i) {
+    for (i = 0, ii = chars.length; i < ii; ++i) {
       var ch = chars[i];
       if (ch != '<' && ch != '>') {
         result += ch;
diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js
index 216301f..b82f26d 100644
--- a/src/core/chunked_stream.js
+++ b/src/core/chunked_stream.js
@@ -69,10 +69,11 @@ var ChunkedStream = (function ChunkedStreamClosure() {
       var chunkSize = this.chunkSize;
       var beginChunk = Math.floor(begin / chunkSize);
       var endChunk = Math.floor((end - 1) / chunkSize) + 1;
+      var curChunk;
 
-      for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
-        if (!(chunk in this.loadedChunks)) {
-          this.loadedChunks[chunk] = true;
+      for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
+        if (!(curChunk in this.loadedChunks)) {
+          this.loadedChunks[curChunk] = true;
           ++this.numChunksLoaded;
         }
       }
@@ -109,13 +110,14 @@ var ChunkedStream = (function ChunkedStreamClosure() {
     },
 
     nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
-      for (var chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
+      var chunk, n;
+      for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
         if (!(chunk in this.loadedChunks)) {
           return chunk;
         }
       }
       // Wrap around to beginning
-      for (var chunk = 0; chunk < beginChunk; ++chunk) {
+      for (chunk = 0; chunk < beginChunk; ++chunk) {
         if (!(chunk in this.loadedChunks)) {
           return chunk;
         }
@@ -314,8 +316,9 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
       var requestId = this.currRequestId++;
 
       var chunksNeeded;
+      var i, ii;
       this.chunksNeededByRequest[requestId] = chunksNeeded = {};
-      for (var i = 0, ii = chunks.length; i < ii; i++) {
+      for (i = 0, ii = chunks.length; i < ii; i++) {
         if (!this.stream.hasChunk(chunks[i])) {
           chunksNeeded[chunks[i]] = true;
         }
@@ -346,7 +349,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
 
       var groupedChunksToRequest = this.groupChunks(chunksToRequest);
 
-      for (var i = 0; i < groupedChunksToRequest.length; ++i) {
+      for (i = 0; i < groupedChunksToRequest.length; ++i) {
         var groupedChunk = groupedChunksToRequest[i];
         var begin = groupedChunk.beginChunk * this.chunkSize;
         var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
@@ -445,14 +448,14 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
       }
 
       var loadedRequests = [];
-      for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
-
+      var i, requestId;
+      for (chunk = beginChunk; chunk < endChunk; ++chunk) {
         // The server might return more chunks than requested
         var requestIds = this.requestsByChunk[chunk] || [];
         delete this.requestsByChunk[chunk];
 
-        for (var i = 0; i < requestIds.length; ++i) {
-          var requestId = requestIds[i];
+        for (i = 0; i < requestIds.length; ++i) {
+          requestId = requestIds[i];
           var chunksNeeded = this.chunksNeededByRequest[requestId];
           if (chunk in chunksNeeded) {
             delete chunksNeeded[chunk];
@@ -486,8 +489,8 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
         }
       }
 
-      for (var i = 0; i < loadedRequests.length; ++i) {
-        var requestId = loadedRequests[i];
+      for (i = 0; i < loadedRequests.length; ++i) {
+        requestId = loadedRequests[i];
         var callback = this.callbacksByRequest[requestId];
         delete this.callbacksByRequest[requestId];
         if (callback) {
diff --git a/src/core/cmap.js b/src/core/cmap.js
index a88667f..f195290 100644
--- a/src/core/cmap.js
+++ b/src/core/cmap.js
@@ -451,6 +451,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
 
       var ucs2DataSize = 1;
       var subitemsCount = stream.readNumber();
+      var i;
       switch (type) {
         case 0: // codespacerange
           stream.readHex(start, dataSize);
@@ -458,7 +459,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
           addHex(end, start, dataSize);
           cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
                                  hexToInt(end, dataSize));
-          for (var i = 1; i < subitemsCount; i++) {
+          for (i = 1; i < subitemsCount; i++) {
             incHex(end, dataSize);
             stream.readHexNumber(start, dataSize);
             addHex(start, end, dataSize);
@@ -474,7 +475,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
           addHex(end, start, dataSize);
           code = stream.readNumber();
           // undefined range, skipping
-          for (var i = 1; i < subitemsCount; i++) {
+          for (i = 1; i < subitemsCount; i++) {
             incHex(end, dataSize);
             stream.readHexNumber(start, dataSize);
             addHex(start, end, dataSize);
@@ -488,7 +489,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
           stream.readHex(char, dataSize);
           code = stream.readNumber();
           cMap.mapOne(hexToInt(char, dataSize), String.fromCharCode(code));
-          for (var i = 1; i < subitemsCount; i++) {
+          for (i = 1; i < subitemsCount; i++) {
             incHex(char, dataSize);
             if (!sequence) {
               stream.readHexNumber(tmp, dataSize);
@@ -505,7 +506,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
           code = stream.readNumber();
           cMap.mapRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
                         String.fromCharCode(code));
-          for (var i = 1; i < subitemsCount; i++) {
+          for (i = 1; i < subitemsCount; i++) {
             incHex(end, dataSize);
             if (!sequence) {
               stream.readHexNumber(start, dataSize);
@@ -525,7 +526,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
           stream.readHex(charCode, dataSize);
           cMap.mapOne(hexToInt(char, ucs2DataSize),
                       hexToStr(charCode, dataSize));
-          for (var i = 1; i < subitemsCount; i++) {
+          for (i = 1; i < subitemsCount; i++) {
             incHex(char, ucs2DataSize);
             if (!sequence) {
               stream.readHexNumber(tmp, ucs2DataSize);
@@ -546,7 +547,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
           cMap.mapRange(hexToInt(start, ucs2DataSize),
                         hexToInt(end, ucs2DataSize),
                         hexToStr(charCode, dataSize));
-          for (var i = 1; i < subitemsCount; i++) {
+          for (i = 1; i < subitemsCount; i++) {
             incHex(end, ucs2DataSize);
             if (!sequence) {
               stream.readHexNumber(start, ucs2DataSize);
diff --git a/src/core/crypto.js b/src/core/crypto.js
index dca99a0..eb5d534 100644
--- a/src/core/crypto.js
+++ b/src/core/crypto.js
@@ -505,7 +505,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
         hashData[i++] = fileId[j];
       }
       cipher = new ARCFourCipher(encryptionKey);
-      var checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
+      checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
       n = encryptionKey.length;
       var derivedKey = new Uint8Array(n), k;
       for (j = 1; j <= 19; ++j) {
diff --git a/src/core/evaluator.js b/src/core/evaluator.js
index 936cc18..88e7881 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -53,12 +53,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
 
       var nodes = [resources];
       while (nodes.length) {
+        var key;
         var node = nodes.shift();
         // First check the current resources for blend modes.
         var graphicStates = node.get('ExtGState');
         if (isDict(graphicStates)) {
           graphicStates = graphicStates.getAll();
-          for (var key in graphicStates) {
+          for (key in graphicStates) {
             var graphicState = graphicStates[key];
             var bm = graphicState['BM'];
             if (isName(bm) && bm.name !== 'Normal') {
@@ -72,7 +73,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
           continue;
         }
         xObjects = xObjects.getAll();
-        for (var key in xObjects) {
+        for (key in xObjects) {
           var xObject = xObjects[key];
           if (!isStream(xObject)) {
             continue;
@@ -144,6 +145,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
       }
 
       var imageMask = (dict.get('ImageMask', 'IM') || false);
+      var imgData, args;
       if (imageMask) {
         // This depends on a tmpCanvas being filled with the
         // current fillStyle, such that processing the pixel
@@ -159,10 +161,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
         var canTransfer = image instanceof DecodeStream;
         var inverseDecode = (!!decode && decode[0] > 0);
 
-        var imgData = PDFImage.createMask(imgArray, width, height,
-                                          canTransfer, inverseDecode);
+        imgData = PDFImage.createMask(imgArray, width, height,
+                                      canTransfer, inverseDecode);
         imgData.cached = true;
-        var args = [imgData];
+        args = [imgData];
         operatorList.addOp(OPS.paintImageMaskXObject, args);
         if (cacheKey) {
           cache.key = cacheKey;
@@ -183,7 +185,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
                                     inline, null, null);
         // We force the use of RGBA_32BPP images here, because we can't handle
         // any other kind.
-        var imgData = imageObj.createImageData(/* forceRGBA = */ true);
+        imgData = imageObj.createImageData(/* forceRGBA = */ true);
         operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
         return;
       }
@@ -193,7 +195,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
       var uniquePrefix = (this.uniquePrefix || '');
       var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
       operatorList.addDependency(objId);
-      var args = [objId, w, h];
+      args = [objId, w, h];
 
       if (!softMask && !mask && image instanceof JpegStream &&
           image.isNativelySupported(this.xref, resources)) {
@@ -511,10 +513,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
       var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
 
       var promise = new LegacyPromise();
-      var operation;
+      var operation, i, ii;
       while ((operation = preprocessor.read())) {
         var args = operation.args;
         var fn = operation.fn;
+        var shading;
 
         switch (fn) {
           case OPS.setStrokeColorN:
@@ -537,10 +540,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
                 args = [];
                 continue;
               } else if (typeNum == SHADING_PATTERN) {
-                var shading = dict.get('Shading');
+                shading = dict.get('Shading');
                 var matrix = dict.get('Matrix');
-                var pattern = Pattern.parseShading(shading, matrix, xref,
-                                                   resources);
+                pattern = Pattern.parseShading(shading, matrix, xref,
+                                               resources);
                 args = pattern.getIR();
               } else {
                 error('Unkown PatternType ' + typeNum);
@@ -609,7 +612,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
           case OPS.showSpacedText:
             var arr = args[0];
             var arrLength = arr.length;
-            for (var i = 0; i < arrLength; ++i) {
+            for (i = 0; i < arrLength; ++i) {
               if (isString(arr[i])) {
                 arr[i] = this.handleText(arr[i], stateManager.state);
               }
@@ -635,7 +638,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
               error('No shading resource found');
             }
 
-            var shading = shadingRes.get(args[0].name);
+            shading = shadingRes.get(args[0].name);
             if (!shading) {
               error('No shading object found');
             }
@@ -665,7 +668,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
 
       // Some PDFs don't close all restores inside object/form.
       // Closing those for them.
-      for (var i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
+      for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
         operatorList.addOp(OPS.restore, []);
       }
 
@@ -874,17 +877,18 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
           case OPS.showSpacedText:
             var items = args[0];
             var textChunk = newTextChunk();
+            var offset;
             for (var j = 0, jj = items.length; j < jj; j++) {
               if (typeof items[j] === 'string') {
                 buildTextGeometry(items[j], textChunk);
               } else {
                 var val = items[j] / 1000;
                 if (!textState.font.vertical) {
-                  var offset = -val * textState.fontSize * textState.textHScale;
+                  offset = -val * textState.fontSize * textState.textHScale;
                   textState.translateTextMatrix(offset, 0);
                   textChunk.width += offset;
                 } else {
-                  var offset = -val * textState.fontSize;
+                  offset = -val * textState.fontSize;
                   textState.translateTextMatrix(0, offset);
                   textChunk.height += offset;
                 }
@@ -1023,8 +1027,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
       // differences to be merged in here not require us to hold on to it.
       var differences = [];
       var baseEncodingName = null;
+      var encoding;
       if (dict.has('Encoding')) {
-        var encoding = dict.get('Encoding');
+        encoding = dict.get('Encoding');
         if (isDict(encoding)) {
           baseEncodingName = encoding.get('BaseEncoding');
           baseEncodingName = (isName(baseEncodingName) ?
@@ -1059,9 +1064,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
       if (baseEncodingName) {
         properties.defaultEncoding = Encodings[baseEncodingName].slice();
       } else {
-        var encoding = (properties.type === 'TrueType' ?
-                        Encodings.WinAnsiEncoding :
-                        Encodings.StandardEncoding);
+        encoding = (properties.type === 'TrueType' ?
+                    Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
         // The Symbolic attribute can be misused for regular fonts
         // Heuristic: we have to check if the font is a standard one also
         if (!!(properties.flags & FontFlags.Symbolic)) {
@@ -1130,21 +1134,22 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
       var defaultWidth = 0;
       var glyphsVMetrics = [];
       var defaultVMetrics;
+      var i, ii, j, jj, start, code, widths;
       if (properties.composite) {
         defaultWidth = dict.get('DW') || 1000;
 
-        var widths = dict.get('W');
+        widths = dict.get('W');
         if (widths) {
-          for (var i = 0, ii = widths.length; i < ii; i++) {
-            var start = widths[i++];
-            var code = xref.fetchIfRef(widths[i]);
+          for (i = 0, ii = widths.length; i < ii; i++) {
+            start = widths[i++];
+            code = xref.fetchIfRef(widths[i]);
             if (isArray(code)) {
-              for (var j = 0, jj = code.length; j < jj; j++) {
+              for (j = 0, jj = code.length; j < jj; j++) {
                 glyphsWidths[start++] = code[j];
               }
             } else {
               var width = widths[++i];
-              for (var j = start; j <= code; j++) {
+              for (j = start; j <= code; j++) {
                 glyphsWidths[j] = width;
               }
             }
@@ -1156,16 +1161,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
           defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
           vmetrics = dict.get('W2');
           if (vmetrics) {
-            for (var i = 0, ii = vmetrics.length; i < ii; i++) {
-              var start = vmetrics[i++];
-              var code = xref.fetchIfRef(vmetrics[i]);
+            for (i = 0, ii = vmetrics.length; i < ii; i++) {
+              start = vmetrics[i++];
+              code = xref.fetchIfRef(vmetrics[i]);
               if (isArray(code)) {
-                for (var j = 0, jj = code.length; j < jj; j++) {
+                for (j = 0, jj = code.length; j < jj; j++) {
                   glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
                 }
               } else {
                 var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
-                for (var j = start; j <= code; j++) {
+                for (j = start; j <= code; j++) {
                   glyphsVMetrics[j] = vmetric;
                 }
               }
@@ -1174,10 +1179,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
         }
       } else {
         var firstChar = properties.firstChar;
-        var widths = dict.get('Widths');
+        widths = dict.get('Widths');
         if (widths) {
-          var j = firstChar;
-          for (var i = 0, ii = widths.length; i < ii; i++) {
+          j = firstChar;
+          for (i = 0, ii = widths.length; i < ii; i++) {
             glyphsWidths[j++] = widths[i];
           }
           defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
@@ -1376,7 +1381,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
             (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
                                              FontFlags.Nonsymbolic);
 
-          var properties = {
+          properties = {
             type: type.name,
             name: baseFontName,
             widths: metrics.widths,
@@ -1441,7 +1446,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
         }
       }
 
-      var properties = {
+      properties = {
         type: type.name,
         name: fontName.name,
         subtype: subtype,
@@ -1683,7 +1688,7 @@ var EvalState = (function EvalStateClosure() {
   return EvalState;
 })();
 
-var EvaluatorPreprocessor = (function EvaluatorPreprocessor() {
+var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
   // Specifies properties for each command
   //
   // If variableArgs === true: [0, `numArgs`] expected
@@ -1937,7 +1942,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
       var maxX = 0;
       var map = [], maxLineHeight = 0;
       var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
-      for (var q = 0; q < count; q++) {
+      var q;
+      for (q = 0; q < count; q++) {
         var transform = argsArray[j + (q << 2) + 1];
         var img = argsArray[j + (q << 2) + 2][0];
         if (currentX + img.width > MAX_WIDTH) {
@@ -1959,7 +1965,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
       var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
       var imgData = new Uint8Array(imgWidth * imgHeight * 4);
       var imgRowSize = imgWidth << 2;
-      for (var q = 0; q < count; q++) {
+      for (q = 0; q < count; q++) {
         var data = argsArray[j + (q << 2) + 2][0].data;
         // copy image by lines and extends pixels into padding
         var rowSize = map[q].w << 2;
@@ -2003,7 +2009,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
 
       var fnArray = context.fnArray, argsArray = context.argsArray;
       var j = context.currentOperation - 3, i = j + 4;
-      var ii = fnArray.length;
+      var ii = fnArray.length, q;
 
       for (; i < ii && fnArray[i - 4] === fnArray[i]; i++) {}
       var count = (i - j) >> 2;
@@ -2014,12 +2020,13 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
       }
 
       var isSameImage = false;
+      var transformArgs;
       if (argsArray[j + 1][1] === 0 && argsArray[j + 1][2] === 0) {
         i = j + 4;
         isSameImage = true;
-        for (var q = 1; q < count; q++, i += 4) {
+        for (q = 1; q < count; q++, i += 4) {
           var prevTransformArgs = argsArray[i - 3];
-          var transformArgs = argsArray[i + 1];
+          transformArgs = argsArray[i + 1];
           if (argsArray[i - 2][0] !== argsArray[i + 2][0] ||
               prevTransformArgs[0] !== transformArgs[0] ||
               prevTransformArgs[1] !== transformArgs[1] ||
@@ -2039,8 +2046,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
         count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
         var positions = new Float32Array(count * 2);
         i = j + 1;
-        for (var q = 0; q < count; q++) {
-          var transformArgs = argsArray[i];
+        for (q = 0; q < count; q++) {
+          transformArgs = argsArray[i];
           positions[(q << 1)] = transformArgs[4];
           positions[(q << 1) + 1] = transformArgs[5];
           i += 4;
@@ -2055,8 +2062,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
       } else {
         count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
         var images = [];
-        for (var q = 0; q < count; q++) {
-          var transformArgs = argsArray[j + (q << 2) + 1];
+        for (q = 0; q < count; q++) {
+          transformArgs = argsArray[j + (q << 2) + 1];
           var maskParams = argsArray[j + (q << 2) + 2][0];
           images.push({ data: maskParams.data, width: maskParams.width,
                         height: maskParams.height,
@@ -2083,6 +2090,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
         return;
       }
       var ii = fnArray.length;
+      var transformArgs;
       for (; i + 3 < ii && fnArray[i - 4] === fnArray[i]; i += 4) {
         if (fnArray[i - 3] !== fnArray[i + 1] ||
             fnArray[i - 2] !== fnArray[i + 2] ||
@@ -2093,7 +2101,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
           break; // different image
         }
         var prevTransformArgs = argsArray[i - 3];
-        var transformArgs = argsArray[i + 1];
+        transformArgs = argsArray[i + 1];
         if (prevTransformArgs[0] !== transformArgs[0] ||
             prevTransformArgs[1] !== transformArgs[1] ||
             prevTransformArgs[2] !== transformArgs[2] ||
@@ -2110,7 +2118,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
       var positions = new Float32Array(count * 2);
       i = j + 1;
       for (var q = 0; q < count; q++) {
-        var transformArgs = argsArray[i];
+        transformArgs = argsArray[i];
         positions[(q << 1)] = transformArgs[4];
         positions[(q << 1) + 1] = transformArgs[5];
         i += 4;
diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js
index 117f510..ebaacc3 100644
--- a/src/core/font_renderer.js
+++ b/src/core/font_renderer.js
@@ -33,22 +33,23 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
     var offset = (getUshort(data, start + 2) === 1 ?
                   getLong(data, start + 8) : getLong(data, start + 16));
     var format = getUshort(data, start + offset);
+    var length, ranges, p, i;
     if (format === 4) {
-      var length = getUshort(data, start + offset + 2);
+      length = getUshort(data, start + offset + 2);
       var segCount = getUshort(data, start + offset + 6) >> 1;
-      var p = start + offset + 14;
-      var ranges = [];
-      for (var i = 0; i < segCount; i++, p += 2) {
+      p = start + offset + 14;
+      ranges = [];
+      for (i = 0; i < segCount; i++, p += 2) {
         ranges[i] = {end: getUshort(data, p)};
       }
       p += 2;
-      for (var i = 0; i < segCount; i++, p += 2) {
+      for (i = 0; i < segCount; i++, p += 2) {
         ranges[i].start = getUshort(data, p);
       }
-      for (var i = 0; i < segCount; i++, p += 2) {
+      for (i = 0; i < segCount; i++, p += 2) {
         ranges[i].idDelta = getUshort(data, p);
       }
-      for (var i = 0; i < segCount; i++, p += 2) {
+      for (i = 0; i < segCount; i++, p += 2) {
         var idOffset = getUshort(data, p);
         if (idOffset === 0) {
           continue;
@@ -61,11 +62,11 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
       }
       return ranges;
     } else if (format === 12) {
-      var length = getLong(data, start + offset + 4);
+      length = getLong(data, start + offset + 4);
       var groups = getLong(data, start + offset + 12);
-      var p = start + offset + 16;
-      var ranges = [];
-      for (var i = 0; i < groups; i++) {
+      p = start + offset + 16;
+      ranges = [];
+      for (i = 0; i < groups; i++) {
         ranges.push({
           start: getLong(data, p),
           end: getLong(data, p + 4),
@@ -151,12 +152,13 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
     var yMin = ((code[i + 4] << 24) | (code[i + 5] << 16)) >> 16;
     var xMax = ((code[i + 6] << 24) | (code[i + 7] << 16)) >> 16;
     var yMax = ((code[i + 8] << 24) | (code[i + 9] << 16)) >> 16;
+    var flags;
+    var x = 0, y = 0;
     i += 10;
     if (numberOfContours < 0) {
       // composite glyph
-      var x = 0, y = 0;
       do {
-        var flags = (code[i] << 8) | code[i + 1];
+        flags = (code[i] << 8) | code[i + 1];
         var glyphIndex = (code[i + 2] << 8) | code[i + 3];
         i += 4;
         var arg1, arg2;
@@ -201,7 +203,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
     } else {
       // simple glyph
       var endPtsOfContours = [];
-      for (var j = 0; j < numberOfContours; j++) {
+      var j, jj;
+      for (j = 0; j < numberOfContours; j++) {
         endPtsOfContours.push((code[i] << 8) | code[i + 1]);
         i += 2;
       }
@@ -210,7 +213,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
       var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
       var points = [];
       while (points.length < numberOfPoints) {
-        var flags = code[i++], repeat = 1;
+        flags = code[i++];
+        var repeat = 1;
         if ((flags & 0x08)) {
           repeat += code[i++];
         }
@@ -218,8 +222,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
           points.push({flags: flags});
         }
       }
-      var x = 0, y = 0;
-      for (var j = 0; j < numberOfPoints; j++) {
+      for (j = 0; j < numberOfPoints; j++) {
         switch (points[j].flags & 0x12) {
           case 0x00:
             x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
@@ -234,7 +237,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
         }
         points[j].x = x;
       }
-      for (var j = 0; j < numberOfPoints; j++) {
+      for (j = 0; j < numberOfPoints; j++) {
         switch (points[j].flags & 0x24) {
           case 0x00:
             y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
@@ -251,7 +254,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
       }
 
       var startPoint = 0;
-      for (var i = 0; i < numberOfContours; i++) {
+      for (i = 0; i < numberOfContours; i++) {
         var endPoint = endPtsOfContours[i];
         // contours might have implicit points, which is located in the middle
         // between two neighboring off-curve points
@@ -272,7 +275,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
           contour.push(p);
         }
         moveTo(contour[0].x, contour[0].y);
-        for (var j = 1, jj = contour.length; j < jj; j++) {
+        for (j = 1, jj = contour.length; j < jj; j++) {
           if ((contour[j].flags & 1)) {
             lineTo(contour[j].x, contour[j].y);
           } else if ((contour[j + 1].flags & 1)){
@@ -311,6 +314,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
       while (i < code.length) {
         var stackClean = false;
         var v = code[i++];
+        var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
         switch (v) {
           case 1: // hstem
             stems += stack.length >> 1;
@@ -356,15 +360,15 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
             break;
           case 8: // rrcurveto
             while (stack.length > 0) {
-              var xa = x + stack.shift(), ya = y + stack.shift();
-              var xb = xa + stack.shift(), yb = ya + stack.shift();
+              xa = x + stack.shift(); ya = y + stack.shift();
+              xb = xa + stack.shift(); yb = ya + stack.shift();
               x = xb + stack.shift(); y = yb + stack.shift();
               bezierCurveTo(xa, ya, xb, yb, x, y);
             }
             break;
           case 10: // callsubr
-            var n = stack.pop() + font.subrsBias;
-            var subrCode = font.subrs[n];
+            n = stack.pop() + font.subrsBias;
+            subrCode = font.subrs[n];
             if (subrCode) {
               parse(subrCode);
             }
@@ -375,44 +379,44 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
             v = code[i++];
             switch (v) {
               case 34: // flex
-                var xa = x + stack.shift();
-                var xb = xa + stack.shift(), y1 = y + stack.shift();
+                xa = x + stack.shift();
+                xb = xa + stack.shift(); y1 = y + stack.shift();
                 x = xb + stack.shift();
                 bezierCurveTo(xa, y, xb, y1, x, y1);
-                var xa = x + stack.shift();
-                var xb = xa + stack.shift();
+                xa = x + stack.shift();
+                xb = xa + stack.shift();
                 x = xb + stack.shift();
                 bezierCurveTo(xa, y1, xb, y, x, y);
                 break;
               case 35: // flex
-                var xa = x + stack.shift(), ya = y + stack.shift();
-                var xb = xa + stack.shift(), yb = ya + stack.shift();
+                xa = x + stack.shift(); ya = y + stack.shift();
+                xb = xa + stack.shift(); yb = ya + stack.shift();
                 x = xb + stack.shift(); y = yb + stack.shift();
                 bezierCurveTo(xa, ya, xb, yb, x, y);
-                var xa = x + stack.shift(), ya = y + stack.shift();
-                var xb = xa + stack.shift(), yb = ya + stack.shift();
+                xa = x + stack.shift(); ya = y + stack.shift();
+                xb = xa + stack.shift(); yb = ya + stack.shift();
                 x = xb + stack.shift(); y = yb + stack.shift();
                 bezierCurveTo(xa, ya, xb, yb, x, y);
                 stack.pop(); // fd
                 break;
               case 36: // hflex1
-                var xa = x + stack.shift(), y1 = y + stack.shift();
-                var xb = xa + stack.shift(), y2 = y1 + stack.shift();
+                xa = x + stack.shift(); y1 = y + stack.shift();
+                xb = xa + stack.shift(); y2 = y1 + stack.shift();
                 x = xb + stack.shift();
                 bezierCurveTo(xa, y1, xb, y2, x, y2);
-                var xa = x + stack.shift();
-                var xb = xa + stack.shift(), y3 = y2 + stack.shift();
+                xa = x + stack.shift();
+                xb = xa + stack.shift(); y3 = y2 + stack.shift();
                 x = xb + stack.shift();
                 bezierCurveTo(xa, y2, xb, y3, x, y);
                 break;
               case 37: // flex1
                 var x0 = x, y0 = y;
-                var xa = x + stack.shift(), ya = y + stack.shift();
-                var xb = xa + stack.shift(), yb = ya + stack.shift();
+                xa = x + stack.shift(); ya = y + stack.shift();
+                xb = xa + stack.shift(); yb = ya + stack.shift();
                 x = xb + stack.shift(); y = yb + stack.shift();
                 bezierCurveTo(xa, ya, xb, yb, x, y);
-                var xa = x + stack.shift(), ya = y + stack.shift();
-                var xb = xa + stack.shift(), yb = ya + stack.shift();
+                xa = x + stack.shift(); ya = y + stack.shift();
+                xb = xa + stack.shift(); yb = ya + stack.shift();
                 x = xb; y = yb;
                 if (Math.abs(x - x0) > Math.abs(y - y0)) {
                   x += stack.shift();
@@ -474,8 +478,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
             break;
           case 24: // rcurveline
             while (stack.length > 2) {
-              var xa = x + stack.shift(), ya = y + stack.shift();
-              var xb = xa + stack.shift(), yb = ya + stack.shift();
+              xa = x + stack.shift(); ya = y + stack.shift();
+              xb = xa + stack.shift(); yb = ya + stack.shift();
               x = xb + stack.shift(); y = yb + stack.shift();
               bezierCurveTo(xa, ya, xb, yb, x, y);
             }
@@ -489,8 +493,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
               y += stack.shift();
               lineTo(x, y);
             }
-            var xa = x + stack.shift(), ya = y + stack.shift();
-            var xb = xa + stack.shift(), yb = ya + stack.shift();
+            xa = x + stack.shift(); ya = y + stack.shift();
+            xb = xa + stack.shift(); yb = ya + stack.shift();
             x = xb + stack.shift(); y = yb + stack.shift();
             bezierCurveTo(xa, ya, xb, yb, x, y);
             break;
@@ -499,8 +503,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
               x += stack.shift();
             }
             while (stack.length > 0) {
-              var xa = x, ya = y + stack.shift();
-              var xb = xa + stack.shift(), yb = ya + stack.shift();
+              xa = x; ya = y + stack.shift();
+              xb = xa + stack.shift(); yb = ya + stack.shift();
               x = xb; y = yb + stack.shift();
               bezierCurveTo(xa, ya, xb, yb, x, y);
             }
@@ -510,8 +514,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
               y += stack.shift();
             }
             while (stack.length > 0) {
-              var xa = x + stack.shift(), ya = y;
-              var xb = xa + stack.shift(), yb = ya + stack.shift();
+              xa = x + stack.shift(); ya = y;
+              xb = xa + stack.shift(); yb = ya + stack.shift();
               x = xb + stack.shift(); y = yb;
               bezierCurveTo(xa, ya, xb, yb, x, y);
             }
@@ -521,16 +525,16 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
             i += 2;
             break;
           case 29: // callgsubr
-            var n = stack.pop() + font.gsubrsBias;
-            var subrCode = font.gsubrs[n];
+            n = stack.pop() + font.gsubrsBias;
+            subrCode = font.gsubrs[n];
             if (subrCode) {
               parse(subrCode);
             }
             break;
           case 30: // vhcurveto
             while (stack.length > 0) {
-              var xa = x, ya = y + stack.shift();
-              var xb = xa + stack.shift(), yb = ya + stack.shift();
+              xa = x; ya = y + stack.shift();
+              xb = xa + stack.shift(); yb = ya + stack.shift();
               x = xb + stack.shift();
               y = yb + (stack.length === 1 ? stack.shift() : 0);
               bezierCurveTo(xa, ya, xb, yb, x, y);
@@ -538,8 +542,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
                 break;
               }
 
-              var xa = x + stack.shift(), ya = y;
-              var xb = xa + stack.shift(), yb = ya + stack.shift();
+              xa = x + stack.shift(); ya = y;
+              xb = xa + stack.shift(); yb = ya + stack.shift();
               y = yb + stack.shift();
               x = xb + (stack.length === 1 ? stack.shift() : 0);
               bezierCurveTo(xa, ya, xb, yb, x, y);
@@ -547,8 +551,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
             break;
           case 31: // hvcurveto
             while (stack.length > 0) {
-              var xa = x + stack.shift(), ya = y;
-              var xb = xa + stack.shift(), yb = ya + stack.shift();
+              xa = x + stack.shift(); ya = y;
+              xb = xa + stack.shift(); yb = ya + stack.shift();
               y = yb + stack.shift();
               x = xb + (stack.length === 1 ? stack.shift() : 0);
               bezierCurveTo(xa, ya, xb, yb, x, y);
@@ -556,8 +560,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
                 break;
               }
 
-              var xa = x, ya = y + stack.shift();
-              var xb = xa + stack.shift(), yb = ya + stack.shift();
+              xa = x; ya = y + stack.shift();
+              xb = xa + stack.shift(); yb = ya + stack.shift();
               x = xb + stack.shift();
               y = yb + (stack.length === 1 ? stack.shift() : 0);
               bezierCurveTo(xa, ya, xb, yb, x, y);
diff --git a/src/core/fonts.js b/src/core/fonts.js
index 3da4cae..4d21a50 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -2148,6 +2148,7 @@ var Glyph = (function GlyphClosure() {
  */
 var Font = (function FontClosure() {
   function Font(name, file, properties) {
+    var charCode;
 
     this.name = name;
     this.loadedName = properties.loadedName;
@@ -2187,7 +2188,7 @@ var Font = (function FontClosure() {
     this.toFontChar = [];
 
     if (properties.type == 'Type3') {
-      for (var charCode = 0; charCode < 256; charCode++) {
+      for (charCode = 0; charCode < 256; charCode++) {
         this.toFontChar[charCode] = (this.differences[charCode] ||
                                      properties.defaultEncoding[charCode]);
       }
@@ -2231,7 +2232,7 @@ var Font = (function FontClosure() {
         this.toUnicode = map;
       } else if (/Symbol/i.test(fontName)) {
         var symbols = Encodings.SymbolSetEncoding;
-        for (var charCode in symbols) {
+        for (charCode in symbols) {
           var fontChar = GlyphsUnicode[symbols[charCode]];
           if (!fontChar) {
             continue;
@@ -2240,13 +2241,13 @@ var Font = (function FontClosure() {
         }
       } else if (isStandardFont) {
         this.toFontChar = [];
-        for (var charCode in properties.defaultEncoding) {
+        for (charCode in properties.defaultEncoding) {
           var glyphName = properties.differences[charCode] ||
                           properties.defaultEncoding[charCode];
           this.toFontChar[charCode] = GlyphsUnicode[glyphName];
         }
       } else {
-        for (var charCode in this.toUnicode) {
+        for (charCode in this.toUnicode) {
           this.toFontChar[charCode] = this.toUnicode[charCode].charCodeAt(0);
         }
       }
@@ -2516,7 +2517,8 @@ var Font = (function FontClosure() {
                '\x00\x01' + // encodingID
                string32(4 + numTables * 8); // start of the table record
 
-    for (var i = ranges.length - 1; i >= 0; --i) {
+    var i, ii, j, jj;
+    for (i = ranges.length - 1; i >= 0; --i) {
       if (ranges[i][0] <= 0xFFFF) { break; }
     }
     var bmpLength = i + 1;
@@ -2538,16 +2540,17 @@ var Font = (function FontClosure() {
     var idRangeOffsets = '';
     var glyphsIds = '';
     var bias = 0;
-
-    for (var i = 0, ii = bmpLength; i < ii; i++) {
-      var range = ranges[i];
-      var start = range[0];
-      var end = range[1];
+    
+    var range, start, end, codes;
+    for (i = 0, ii = bmpLength; i < ii; i++) {
+      range = ranges[i];
+      start = range[0];
+      end = range[1];
       startCount += string16(start);
       endCount += string16(end);
-      var codes = range[2];
+      codes = range[2];
       var contiguous = true;
-      for (var j = 1, jj = codes.length; j < jj; ++j) {
+      for (j = 1, jj = codes.length; j < jj; ++j) {
         if (codes[j] !== codes[j - 1] + 1) {
           contiguous = false;
           break;
@@ -2560,7 +2563,7 @@ var Font = (function FontClosure() {
         idDeltas += string16(0);
         idRangeOffsets += string16(offset);
 
-        for (var j = 0, jj = codes.length; j < jj; ++j) {
+        for (j = 0, jj = codes.length; j < jj; ++j) {
           glyphsIds += string16(codes[j]);
         }
       } else {
@@ -2594,14 +2597,14 @@ var Font = (function FontClosure() {
               string32(4 + numTables * 8 +
                        4 + format314.length); // start of the table record
       format31012 = '';
-      for (var i = 0, ii = ranges.length; i < ii; i++) {
-        var range = ranges[i];
-        var start = range[0];
-        var codes = range[2];
+      for (i = 0, ii = ranges.length; i < ii; i++) {
+        range = ranges[i];
+        start = range[0];
+        codes = range[2];
         var code = codes[0];
-        for (var j = 1, jj = codes.length; j < jj; ++j) {
+        for (j = 1, jj = codes.length; j < jj; ++j) {
           if (codes[j] !== codes[j - 1] + 1) {
-            var end = range[0] + j - 1;
+            end = range[0] + j - 1;
             format31012 += string32(start) + // startCharCode
                            string32(end) + // endCharCode
                            string32(code); // startGlyphID
@@ -2793,11 +2796,12 @@ var Font = (function FontClosure() {
     // Mac want 1-byte per character strings while Windows want
     // 2-bytes per character, so duplicate the names table
     var stringsUnicode = [];
-    for (var i = 0, ii = strings.length; i < ii; i++) {
-      var str = proto[1][i] || strings[i];
+    var i, ii, j, jj, str;
+    for (i = 0, ii = strings.length; i < ii; i++) {
+      str = proto[1][i] || strings[i];
 
       var strBufUnicode = [];
-      for (var j = 0, jj = str.length; j < jj; j++) {
+      for (j = 0, jj = str.length; j < jj; j++) {
         strBufUnicode.push(string16(str.charCodeAt(j)));
       }
       stringsUnicode.push(strBufUnicode.join(''));
@@ -2816,10 +2820,10 @@ var Font = (function FontClosure() {
 
     // Build the name records field
     var strOffset = 0;
-    for (var i = 0, ii = platforms.length; i < ii; i++) {
+    for (i = 0, ii = platforms.length; i < ii; i++) {
       var strs = names[i];
-      for (var j = 0, jj = strs.length; j < jj; j++) {
-        var str = strs[j];
+      for (j = 0, jj = strs.length; j < jj; j++) {
+        str = strs[j];
         var nameRecord =
           platforms[i] + // platform ID
           encodings[i] + // encoding ID
@@ -2901,6 +2905,7 @@ var Font = (function FontClosure() {
        * PDF spec
        */
       function readCmapTable(cmap, font, isSymbolicFont) {
+        var segment;
         var start = (font.start ? font.start : 0) + cmap.offset;
         font.pos = start;
 
@@ -2957,10 +2962,11 @@ var Font = (function FontClosure() {
 
         var hasShortCmap = false;
         var mappings = [];
+        var j, glyphId;
 
         // TODO(mack): refactor this cmap subtable reading logic out
         if (format === 0) {
-          for (var j = 0; j < 256; j++) {
+          for (j = 0; j < 256; j++) {
             var index = font.getByte();
             if (!index) {
               continue;
@@ -2991,7 +2997,7 @@ var Font = (function FontClosure() {
 
           var offsetsCount = 0;
           for (segIndex = 0; segIndex < segCount; segIndex++) {
-            var segment = segments[segIndex];
+            segment = segments[segIndex];
             var rangeOffset = font.getUint16();
             if (!rangeOffset) {
               segment.offsetIndex = -1;
@@ -3005,22 +3011,24 @@ var Font = (function FontClosure() {
           }
 
           var offsets = [];
-          for (var j = 0; j < offsetsCount; j++) {
+          for (j = 0; j < offsetsCount; j++) {
             offsets.push(font.getUint16());
           }
 
           for (segIndex = 0; segIndex < segCount; segIndex++) {
-            var segment = segments[segIndex];
-            var start = segment.start, end = segment.end;
-            var delta = segment.delta, offsetIndex = segment.offsetIndex;
+            segment = segments[segIndex];
+            start = segment.start;
+            var end = segment.end;
+            var delta = segment.delta;
+            offsetIndex = segment.offsetIndex;
 
-            for (var j = start; j <= end; j++) {
+            for (j = start; j <= end; j++) {
               if (j == 0xFFFF) {
                 continue;
               }
 
-              var glyphId = (offsetIndex < 0 ?
-                             j : offsets[offsetIndex + j - start]);
+              glyphId = (offsetIndex < 0 ?
+                         j : offsets[offsetIndex + j - start]);
               glyphId = (glyphId + delta) & 0xFFFF;
               if (glyphId === 0) {
                 continue;
@@ -3042,8 +3050,8 @@ var Font = (function FontClosure() {
 
           var glyphs = [];
           var ids = [];
-          for (var j = 0; j < entryCount; j++) {
-            var glyphId = font.getUint16();
+          for (j = 0; j < entryCount; j++) {
+            glyphId = font.getUint16();
             var charCode = firstCode + j;
 
             mappings.push({
@@ -3059,7 +3067,7 @@ var Font = (function FontClosure() {
         mappings.sort(function (a, b) {
           return a.charCode - b.charCode;
         });
-        for (var i = 1; i < mappings.length; i++) {
+        for (i = 1; i < mappings.length; i++) {
           if (mappings[i - 1].charCode === mappings[i].charCode) {
             mappings.splice(i, 1);
             i--;
@@ -3099,13 +3107,14 @@ var Font = (function FontClosure() {
         var numMissing = numOfSidebearings -
           ((metrics.length - numOfMetrics * 4) >> 1);
 
+        var i, ii;
         if (numMissing > 0) {
           font.pos = (font.start ? font.start : 0) + metrics.offset;
           var entries = '';
-          for (var i = 0, ii = metrics.length; i < ii; i++) {
+          for (i = 0, ii = metrics.length; i < ii; i++) {
             entries += String.fromCharCode(font.getByte());
           }
-          for (var i = 0; i < numMissing; i++) {
+          for (i = 0; i < numMissing; i++) {
             entries += '\x00\x00';
           }
           metrics.data = stringToArray(entries);
@@ -3126,8 +3135,8 @@ var Font = (function FontClosure() {
           return glyf.length;
         }
 
-        var j = 10, flagsCount = 0;
-        for (var i = 0; i < contoursCount; i++) {
+        var i, j = 10, flagsCount = 0;
+        for (i = 0; i < contoursCount; i++) {
           var endPoint = (glyf[j] << 8) | glyf[j + 1];
           flagsCount = endPoint + 1;
           j += 2;
@@ -3139,7 +3148,7 @@ var Font = (function FontClosure() {
         var instructionsEnd = j;
         // validating flags
         var coordinatesLength = 0;
-        for (var i = 0; i < flagsCount; i++) {
+        for (i = 0; i < flagsCount; i++) {
           var flag = glyf[j++];
           if (flag & 0xC0) {
             // reserved flags must be zero, cleaning up
@@ -3270,7 +3279,8 @@ var Font = (function FontClosure() {
         var startOffset = itemDecode(locaData, 0);
         var writeOffset = 0;
         itemEncode(locaData, 0, writeOffset);
-        for (var i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
+        var i, j;
+        for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
           var endOffset = itemDecode(locaData, j);
           if (endOffset > oldGlyfDataLength &&
               ((oldGlyfDataLength + 3) & ~3) === endOffset) {
@@ -3297,7 +3307,7 @@ var Font = (function FontClosure() {
           // to have single glyph with one point
           var simpleGlyph = new Uint8Array(
             [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
-          for (var i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
+          for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
             itemEncode(locaData, j, simpleGlyph.length);
           }
           glyf.data = simpleGlyph;
@@ -3331,6 +3341,8 @@ var Font = (function FontClosure() {
 
         var glyphNames;
         var valid = true;
+        var i;
+
         switch (version) {
           case 0x00010000:
             glyphNames = MacStandardGlyphOrdering;
@@ -3342,7 +3354,7 @@ var Font = (function FontClosure() {
               break;
             }
             var glyphNameIndexes = [];
-            for (var i = 0; i < numGlyphs; ++i) {
+            for (i = 0; i < numGlyphs; ++i) {
               var index = font.getUint16();
               if (index >= 32768) {
                 valid = false;
@@ -3357,13 +3369,13 @@ var Font = (function FontClosure() {
             while (font.pos < end) {
               var stringLength = font.getByte();
               var string = '';
-              for (var i = 0; i < stringLength; ++i) {
+              for (i = 0; i < stringLength; ++i) {
                 string += String.fromCharCode(font.getByte());
               }
               customNames.push(string);
             }
             glyphNames = [];
-            for (var i = 0; i < numGlyphs; ++i) {
+            for (i = 0; i < numGlyphs; ++i) {
               var j = glyphNameIndexes[i];
               if (j < 258) {
                 glyphNames.push(MacStandardGlyphOrdering[j]);
@@ -3399,7 +3411,9 @@ var Font = (function FontClosure() {
         var stringsStart = font.getUint16();
         var records = [];
         var NAME_RECORD_LENGTH = 12;
-        for (var i = 0; i < numRecords &&
+        var i, ii;
+
+        for (i = 0; i < numRecords &&
                         font.pos + NAME_RECORD_LENGTH <= end; i++) {
           var r = {
             platform: font.getUint16(),
@@ -3415,7 +3429,7 @@ var Font = (function FontClosure() {
             records.push(r);
           }
         }
-        for (var i = 0, ii = records.length; i < ii; i++) {
+        for (i = 0, ii = records.length; i < ii; i++) {
           var record = records[i];
           var pos = start + stringsStart + record.offset;
           if (pos + record.length > end) {
@@ -3452,7 +3466,7 @@ var Font = (function FontClosure() {
 
       function sanitizeTTProgram(table, ttContext) {
         var data = table.data;
-        var i = 0, n, lastEndf = 0, lastDeff = 0;
+        var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
         var stack = [];
         var callstack = [];
         var functionsCalled = [];
@@ -3468,7 +3482,7 @@ var Font = (function FontClosure() {
             if (inFDEF || inELSE) {
               i += n;
             } else {
-              for (var j = 0; j < n; j++) {
+              for (j = 0; j < n; j++) {
                 stack.push(data[i++]);
               }
             }
@@ -3477,8 +3491,8 @@ var Font = (function FontClosure() {
             if (inFDEF || inELSE) {
               i += n * 2;
             } else {
-              for (var j = 0; j < n; j++) {
-                var b = data[i++];
+              for (j = 0; j < n; j++) {
+                b = data[i++];
                 stack.push((b << 8) | data[i++]);
               }
             }
@@ -3487,7 +3501,7 @@ var Font = (function FontClosure() {
             if (inFDEF || inELSE) {
               i += n;
             } else {
-              for (var j = 0; j < n; j++) {
+              for (j = 0; j < n; j++) {
                 stack.push(data[i++]);
               }
             }
@@ -3496,15 +3510,15 @@ var Font = (function FontClosure() {
             if (inFDEF || inELSE) {
               i += n * 2;
             } else {
-              for (var j = 0; j < n; j++) {
-                var b = data[i++];
+              for (j = 0; j < n; j++) {
+                b = data[i++];
                 stack.push((b << 8) | data[i++]);
               }
             }
           } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
             if (!inFDEF && !inELSE) {
               // collecting inforamtion about which functions are used
-              var funcId = stack[stack.length - 1];
+              funcId = stack[stack.length - 1];
               ttContext.functionsUsed[funcId] = true;
               if (funcId in ttContext.functionsStackDeltas) {
                 stack.length += ttContext.functionsStackDeltas[funcId];
@@ -3512,7 +3526,7 @@ var Font = (function FontClosure() {
                          functionsCalled.indexOf(funcId) < 0) {
                 callstack.push({data: data, i: i, stackTop: stack.length - 1});
                 functionsCalled.push(funcId);
-                var pc = ttContext.functionsDefined[funcId];
+                pc = ttContext.functionsDefined[funcId];
                 if (!pc) {
                   warn('TT: CALL non-existent function');
                   ttContext.hintsValid = false;
@@ -3530,20 +3544,20 @@ var Font = (function FontClosure() {
             inFDEF = true;
             // collecting inforamtion about which functions are defined
             lastDeff = i;
-            var funcId = stack.pop();
+            funcId = stack.pop();
             ttContext.functionsDefined[funcId] = {data: data, i: i};
           } else if (op === 0x2D) { // ENDF - end of function
             if (inFDEF) {
               inFDEF = false;
               lastEndf = i;
             } else {
-              var pc = callstack.pop();
+              pc = callstack.pop();
               if (!pc) {
                 warn('TT: ENDF bad stack');
                 ttContext.hintsValid = false;
                 return;
               }
-              var funcId = functionsCalled.pop();
+              funcId = functionsCalled.pop();
               data = pc.data;
               i = pc.i;
               ttContext.functionsStackDeltas[funcId] =
@@ -3636,13 +3650,14 @@ var Font = (function FontClosure() {
         if (content.length > 1) {
           // concatenating the content items
           var newLength = 0;
-          for (var j = 0, jj = content.length; j < jj; j++) {
+          var j, jj;
+          for (j = 0, jj = content.length; j < jj; j++) {
             newLength += content[j].length;
           }
           newLength = (newLength + 3) & ~3;
           var result = new Uint8Array(newLength);
           var pos = 0;
-          for (var j = 0, jj = content.length; j < jj; j++) {
+          for (j = 0, jj = content.length; j < jj; j++) {
             result.set(content[j], pos);
             pos += content[j].length;
           }
@@ -3684,11 +3699,13 @@ var Font = (function FontClosure() {
 
       var header = readOpenTypeHeader(font);
       var numTables = header.numTables;
+      var cff, cffFile;
 
       var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
                      hmtx: null, maxp: null, name: null, post: null };
+      var table, tableData;
       for (var i = 0; i < numTables; i++) {
-        var table = readTableEntry(font);
+        table = readTableEntry(font);
         if (VALID_TABLES.indexOf(table.tag) < 0) {
           continue; // skipping table if it's not a required or optional table
         }
@@ -3703,8 +3720,8 @@ var Font = (function FontClosure() {
         // OpenType font
         if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
           // no major tables: throwing everything at CFFFont
-          var cffFile = new Stream(tables['CFF '].data);
-          var cff = new CFFFont(cffFile, properties);
+          cffFile = new Stream(tables['CFF '].data);
+          cff = new CFFFont(cffFile, properties);
 
           return this.convert(name, cff, properties);
         }
@@ -3812,11 +3829,11 @@ var Font = (function FontClosure() {
         }
       }
 
-      var charCodeToGlyphId = [];
+      var charCodeToGlyphId = [], charCode;
       if (properties.type == 'CIDFontType2') {
         var cidToGidMap = properties.cidToGidMap || [];
         var cMap = properties.cMap.map;
-        for (var charCode in cMap) {
+        for (charCode in cMap) {
           charCode |= 0;
           var cid = cMap[charCode];
           assert(cid.length === 1, 'Max size of CID is 65,535');
@@ -3856,7 +3873,7 @@ var Font = (function FontClosure() {
               properties.baseEncodingName === 'WinAnsiEncoding') {
             baseEncoding = Encodings[properties.baseEncodingName];
           }
-          for (var charCode = 0; charCode < 256; charCode++) {
+          for (charCode = 0; charCode < 256; charCode++) {
             var glyphName;
             if (this.differences && charCode in this.differences) {
               glyphName = this.differences[charCode];
@@ -3878,7 +3895,7 @@ var Font = (function FontClosure() {
             }
 
             var found = false;
-            for (var i = 0; i < cmapMappingsLength; ++i) {
+            for (i = 0; i < cmapMappingsLength; ++i) {
               if (cmapMappings[i].charCode === unicodeOrCharCode) {
                 charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
                 found = true;
@@ -3888,7 +3905,7 @@ var Font = (function FontClosure() {
             if (!found && properties.glyphNames) {
               // Try to map using the post table. There are currently no known
               // pdfs that this fixes.
-              var glyphId = properties.glyphNames.indexOf(glyphName);
+              glyphId = properties.glyphNames.indexOf(glyphName);
               if (glyphId > 0) {
                 charCodeToGlyphId[charCode] = glyphId;
               }
@@ -3908,8 +3925,8 @@ var Font = (function FontClosure() {
           // associated glyph descriptions from the subtable'. This means
           // charcodes in the cmap will be single bytes, so no-op since
           // glyph.charCode & 0xFF === glyph.charCode
-          for (var i = 0; i < cmapMappingsLength; ++i) {
-            var charCode = cmapMappings[i].charCode & 0xFF;
+          for (i = 0; i < cmapMappingsLength; ++i) {
+            charCode = cmapMappings[i].charCode & 0xFF;
             charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
           }
         }
@@ -3958,9 +3975,9 @@ var Font = (function FontClosure() {
       if (!isTrueType) {
         try {
           // Trying to repair CFF file
-          var cffFile = new Stream(tables['CFF '].data);
+          cffFile = new Stream(tables['CFF '].data);
           var parser = new CFFParser(cffFile, properties);
-          var cff = parser.parse();
+          cff = parser.parse();
           var compiler = new CFFCompiler(cff);
           tables['CFF '].data = compiler.compile();
         } catch (e) {
@@ -3981,11 +3998,11 @@ var Font = (function FontClosure() {
       }
 
       // rewrite the tables but tweak offsets
-      for (var i = 0; i < numTables; i++) {
-        var table = tables[tablesNames[i]];
+      for (i = 0; i < numTables; i++) {
+        table = tables[tablesNames[i]];
         var data = [];
 
-        var tableData = table.data;
+        tableData = table.data;
         for (var j = 0, jj = tableData.length; j < jj; j++) {
           data.push(tableData[j]);
         }
@@ -3993,9 +4010,9 @@ var Font = (function FontClosure() {
       }
 
       // Add the table datas
-      for (var i = 0; i < numTables; i++) {
-        var table = tables[tablesNames[i]];
-        var tableData = table.data;
+      for (i = 0; i < numTables; i++) {
+        table = tables[tablesNames[i]];
+        tableData = table.data;
         ttf.file += bytesToString(new Uint8Array(tableData));
 
         // 4-byte aligned data
@@ -4030,15 +4047,15 @@ var Font = (function FontClosure() {
       var numGlyphs = font.numGlyphs;
 
       var seacs = font.seacs;
+      var charCode;
       if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
         var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
         var charset = font.getCharset();
         var charCodeToGlyphId = mapping;
         var toFontChar = newMapping.toFontChar;
-        var seacs = font.seacs;
         var seacMap = Object.create(null);
         var glyphIdToCharCode = Object.create(null);
-        for (var charCode in charCodeToGlyphId) {
+        for (charCode in charCodeToGlyphId) {
           glyphIdToCharCode[charCodeToGlyphId[charCode]] = charCode | 0;
         }
         for (var glyphId in seacs) {
@@ -4055,7 +4072,7 @@ var Font = (function FontClosure() {
             x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
             y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
           };
-          var charCode = glyphIdToCharCode[glyphId];
+          charCode = glyphIdToCharCode[glyphId];
           seacMap[charCode] = {
             baseFontCharCode: toFontChar[glyphIdToCharCode[baseGlyphId]],
             accentFontCharCode: toFontChar[glyphIdToCharCode[accentGlyphId]],
@@ -4151,10 +4168,11 @@ var Font = (function FontClosure() {
         'post': stringToArray(createPostTable(properties))
       };
 
-      for (var field in fields) {
+      var field;
+      for (field in fields) {
         createTableEntry(otf, field, fields[field]);
       }
-      for (var field in fields) {
+      for (field in fields) {
         var table = fields[field];
         otf.file += bytesToString(new Uint8Array(table));
       }
@@ -4184,15 +4202,16 @@ var Font = (function FontClosure() {
       // the differences array only contains adobe standard or symbol set names,
       // in pratice it seems better to always try to create a toUnicode
       // map based of the default encoding.
+      var toUnicode, charcode;
       if (!properties.composite /* is simple font */) {
-        var toUnicode = [];
+        toUnicode = [];
         var encoding = properties.defaultEncoding.slice();
         // Merge in the differences array.
         var differences = properties.differences;
-        for (var charcode in differences) {
+        for (charcode in differences) {
           encoding[charcode] = differences[charcode];
         }
-        for (var charcode in encoding) {
+        for (charcode in encoding) {
           // a) Map the character code to a character name.
           var glyphName = encoding[charcode];
           // b) Look up the character name in the Adobe Glyph List (see the
@@ -4234,8 +4253,8 @@ var Font = (function FontClosure() {
         var ucs2CMap = CMapFactory.create(ucs2CMapName,
           { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
         var cMap = properties.cMap;
-        var toUnicode = [];
-        for (var charcode in cMap.map) {
+        toUnicode = [];
+        for (charcode in cMap.map) {
           var cid = cMap.map[charcode];
           assert(cid.length === 1, 'Max size of CID is 65,535');
           // e) Map the CID obtained in step (a) according to the CMap obtained
@@ -4252,7 +4271,7 @@ var Font = (function FontClosure() {
       }
 
       // The viewer's choice, just use an identity map.
-      var toUnicode = [];
+      toUnicode = [];
       var firstChar = properties.firstChar, lastChar = properties.lastChar;
       for (var i = firstChar; i <= lastChar; i++) {
         toUnicode[i] = String.fromCharCode(i);
@@ -4313,7 +4332,7 @@ var Font = (function FontClosure() {
       if (this.cMap && charcode in this.cMap.map) {
         widthCode = this.cMap.map[charcode].charCodeAt(0);
       }
-      var width = this.widths[widthCode];
+      width = this.widths[widthCode];
       width = isNum(width) ? width : this.defaultWidth;
       var vmetric = this.vmetrics && this.vmetrics[widthCode];
 
@@ -4359,7 +4378,7 @@ var Font = (function FontClosure() {
 
     charsToGlyphs: function Font_charsToGlyphs(chars) {
       var charsCache = this.charsCache;
-      var glyphs;
+      var glyphs, glyph, charcode;
 
       // if we translated this string before, just grab it from the cache
       if (charsCache) {
@@ -4376,17 +4395,17 @@ var Font = (function FontClosure() {
 
       glyphs = [];
       var charsCacheKey = chars;
+      var i = 0, ii;
 
       if (this.cMap) {
-        var i = 0;
         // composite fonts have multi-byte strings convert the string from
         // single-byte to multi-byte
         while (i < chars.length) {
           var c = this.cMap.readCharCode(chars, i);
-          var charcode = c[0];
+          charcode = c[0];
           var length = c[1];
           i += length;
-          var glyph = this.charToGlyph(charcode);
+          glyph = this.charToGlyph(charcode);
           glyphs.push(glyph);
           // placing null after each word break charcode (ASCII SPACE)
           // Ignore occurences of 0x20 in multiple-byte codes.
@@ -4395,9 +4414,9 @@ var Font = (function FontClosure() {
           }
         }
       } else {
-        for (var i = 0, ii = chars.length; i < ii; ++i) {
-          var charcode = chars.charCodeAt(i);
-          var glyph = this.charToGlyph(charcode);
+        for (i = 0, ii = chars.length; i < ii; ++i) {
+          charcode = chars.charCodeAt(i);
+          glyph = this.charToGlyph(charcode);
           glyphs.push(glyph);
           if (charcode == 0x20) {
             glyphs.push(null);
@@ -4441,12 +4460,14 @@ var ErrorFont = (function ErrorFontClosure() {
  */
 function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
   var charCodeToGlyphId = Object.create(null);
+  var glyphId, charCode, baseEncoding;
+
   if (properties.baseEncodingName) {
     // If a valid base encoding name was used, the mapping is initialized with
     // that.
-    var baseEncoding = Encodings[properties.baseEncodingName];
-    for (var charCode = 0; charCode < baseEncoding.length; charCode++) {
-      var glyphId = glyphNames.indexOf(baseEncoding[charCode]);
+    baseEncoding = Encodings[properties.baseEncodingName];
+    for (charCode = 0; charCode < baseEncoding.length; charCode++) {
+      glyphId = glyphNames.indexOf(baseEncoding[charCode]);
       if (glyphId >= 0) {
         charCodeToGlyphId[charCode] = glyphId;
       }
@@ -4454,15 +4475,15 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
   } else if (!!(properties.flags & FontFlags.Symbolic)) {
     // For a symbolic font the encoding should be the fonts built-in
     // encoding.
-    for (var charCode in builtInEncoding) {
+    for (charCode in builtInEncoding) {
       charCodeToGlyphId[charCode] = builtInEncoding[charCode];
     }
   } else {
     // For non-symbolic fonts that don't have a base encoding the standard
     // encoding should be used.
-    var baseEncoding = Encodings.StandardEncoding;
-    for (var charCode = 0; charCode < baseEncoding.length; charCode++) {
-      var glyphId = glyphNames.indexOf(baseEncoding[charCode]);
+    baseEncoding = Encodings.StandardEncoding;
+    for (charCode = 0; charCode < baseEncoding.length; charCode++) {
+      glyphId = glyphNames.indexOf(baseEncoding[charCode]);
       if (glyphId >= 0) {
         charCodeToGlyphId[charCode] = glyphId;
       }
@@ -4472,9 +4493,9 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
   // Lastly, merge in the differences.
   var differences = properties.differences;
   if (differences) {
-    for (var charCode in differences) {
+    for (charCode in differences) {
       var glyphName = differences[charCode];
-      var glyphId = glyphNames.indexOf(glyphName);
+      glyphId = glyphNames.indexOf(glyphName);
       if (glyphId >= 0) {
         charCodeToGlyphId[charCode] = glyphId;
       }
@@ -4552,6 +4573,7 @@ var Type1CharString = (function Type1CharStringClosure() {
     convert: function Type1CharString_convert(encoded, subrs) {
       var count = encoded.length;
       var error = false;
+      var wx, sbx, subrNumber;
       for (var i = 0; i < count; i++) {
         var value = encoded[i];
         if (value < 32) {
@@ -4609,7 +4631,7 @@ var Type1CharString = (function Type1CharStringClosure() {
                 error = true;
                 break;
               }
-              var subrNumber = this.stack.pop();
+              subrNumber = this.stack.pop();
               error = this.convert(subrs[subrNumber], subrs);
               break;
             case 11: // return
@@ -4621,8 +4643,8 @@ var Type1CharString = (function Type1CharStringClosure() {
               }
               // To convert to type2 we have to move the width value to the
               // first part of the charstring and then use hmoveto with lsb.
-              var wx = this.stack.pop();
-              var sbx = this.stack.pop();
+              wx = this.stack.pop();
+              sbx = this.stack.pop();
               this.lsb = sbx;
               this.width = wx;
               this.stack.push(sbx);
@@ -4695,9 +4717,9 @@ var Type1CharString = (function Type1CharStringClosure() {
               // (dx, dy). The height argument will not be used for vmtx and
               // vhea tables reconstruction -- ignoring it.
               var wy = this.stack.pop();
-              var wx = this.stack.pop();
+              wx = this.stack.pop();
               var sby = this.stack.pop();
-              var sbx = this.stack.pop();
+              sbx = this.stack.pop();
               this.lsb = sbx;
               this.width = wx;
               this.stack.push(sbx, sby);
@@ -4717,7 +4739,7 @@ var Type1CharString = (function Type1CharStringClosure() {
                 error = true;
                 break;
               }
-              var subrNumber = this.stack.pop();
+              subrNumber = this.stack.pop();
               var numArgs = this.stack.pop();
               if (subrNumber === 0 && numArgs === 3) {
                 var flexArgs = this.stack.splice(this.stack.length - 17, 17);
@@ -4939,7 +4961,7 @@ var Type1Parser = (function Type1ParserClosure() {
           }
         }
       };
-      var token;
+      var token, length, data, lenIV, encoded;
       while ((token = this.getToken()) !== null) {
         if (token !== '/') {
           continue;
@@ -4963,12 +4985,11 @@ var Type1Parser = (function Type1ParserClosure() {
                 continue;
               }
               var glyph = this.getToken();
-              var length = this.readInt();
+              length = this.readInt();
               this.getToken(); // read in 'RD' or '-|'
-              var data = stream.makeSubStream(stream.pos, length);
-              var lenIV = program.properties.privateData['lenIV'];
-              var encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY,
-                                    lenIV);
+              data = stream.makeSubStream(stream.pos, length);
+              lenIV = program.properties.privateData['lenIV'];
+              encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
               // Skip past the required space and binary data.
               stream.skip(length);
               this.nextChar();
@@ -4987,12 +5008,11 @@ var Type1Parser = (function Type1ParserClosure() {
             this.getToken(); // read in 'array'
             while ((token = this.getToken()) === 'dup') {
               var index = this.readInt();
-              var length = this.readInt();
+              length = this.readInt();
               this.getToken(); // read in 'RD' or '-|'
-              var data = stream.makeSubStream(stream.pos, length);
-              var lenIV = program.properties.privateData['lenIV'];
-              var encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY,
-                                    lenIV);
+              data = stream.makeSubStream(stream.pos, length);
+              lenIV = program.properties.privateData['lenIV'];
+              encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
               // Skip past the required space and binary data.
               stream.skip(length);
               this.nextChar();
@@ -5039,8 +5059,8 @@ var Type1Parser = (function Type1ParserClosure() {
       }
 
       for (var i = 0; i < charstrings.length; i++) {
-        var glyph = charstrings[i].glyph;
-        var encoded = charstrings[i].encoded;
+        glyph = charstrings[i].glyph;
+        encoded = charstrings[i].encoded;
         var charString = new Type1CharString();
         var error = charString.convert(encoded, subrs);
         var output = charString.output;
@@ -5086,7 +5106,7 @@ var Type1Parser = (function Type1ParserClosure() {
               this.getToken(); // read in 'array'
 
               for (var j = 0; j < size; j++) {
-                var token = this.getToken();
+                token = this.getToken();
                 // skipping till first dup or def (e.g. ignoring for statement)
                 while (token !== 'dup' && token !== 'def') {
                   token = this.getToken();
@@ -5254,15 +5274,15 @@ Type1Font.prototype = {
 
   getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
     var charstrings = this.charstrings;
-    var glyphNames = ['.notdef'];
-    for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
+    var glyphNames = ['.notdef'], glyphId;
+    for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
       glyphNames.push(charstrings[glyphId].glyphName);
     }
     var encoding = properties.builtInEncoding;
     if (encoding) {
       var builtInEncoding = {};
       for (var charCode in encoding) {
-        var glyphId = glyphNames.indexOf(encoding[charCode]);
+        glyphId = glyphNames.indexOf(encoding[charCode]);
         if (glyphId >= 0) {
           builtInEncoding[charCode] = glyphId;
         }
@@ -5307,11 +5327,12 @@ Type1Font.prototype = {
 
     // Add a bunch of empty subrs to deal with the Type2 bias
     var type2Subrs = [];
-    for (var i = 0; i < bias; i++) {
+    var i;
+    for (i = 0; i < bias; i++) {
       type2Subrs.push([0x0B]);
     }
 
-    for (var i = 0; i < count; i++) {
+    for (i = 0; i < count; i++) {
       type2Subrs.push(type1Subrs[i]);
     }
 
@@ -5352,7 +5373,8 @@ Type1Font.prototype = {
 
     var count = glyphs.length;
     var charsetArray = [0];
-    for (var i = 0; i < count; i++) {
+    var i, ii;
+    for (i = 0; i < count; i++) {
       var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
       // TODO: Insert the string and correctly map it.  Previously it was
       // thought mapping names that aren't in the standard strings to .notdef
@@ -5367,7 +5389,7 @@ Type1Font.prototype = {
 
     var charStringsIndex = new CFFIndex();
     charStringsIndex.add([0x8B, 0x0E]); // .notdef
-    for (var i = 0; i < count; i++) {
+    for (i = 0; i < count; i++) {
       charStringsIndex.add(glyphs[i]);
     }
     cff.charStrings = charStringsIndex;
@@ -5390,7 +5412,7 @@ Type1Font.prototype = {
       'StdHW',
       'StdVW'
     ];
-    for (var i = 0, ii = fields.length; i < ii; i++) {
+    for (i = 0, ii = fields.length; i < ii; i++) {
       var field = fields[i];
       if (!properties.privateData.hasOwnProperty(field)) {
         continue;
@@ -5408,7 +5430,7 @@ Type1Font.prototype = {
     cff.topDict.privateDict = privateDict;
 
     var subrIndex = new CFFIndex();
-    for (var i = 0, ii = subrs.length; i < ii; i++) {
+    for (i = 0, ii = subrs.length; i < ii; i++) {
       subrIndex.add(subrs[i]);
     }
     privateDict.subrsIndex = subrIndex;
@@ -5447,12 +5469,13 @@ var CFFFont = (function CFFFontClosure() {
       var cff = this.cff;
       var charsets = cff.charset.charset;
       var charCodeToGlyphId = Object.create(null);
+      var glyphId;
 
       if (this.properties.composite) {
         if (this.cff.isCIDFont) {
           // If the font is actually a CID font then we should use the charset
           // to map CIDs to GIDs.
-          for (var glyphId = 0; glyphId < charsets.length; glyphId++) {
+          for (glyphId = 0; glyphId < charsets.length; glyphId++) {
             var cidString = String.fromCharCode(charsets[glyphId]);
             var charCode = this.properties.cMap.map.indexOf(cidString);
             charCodeToGlyphId[charCode] = glyphId;
@@ -5460,7 +5483,7 @@ var CFFFont = (function CFFFontClosure() {
         } else {
           // If it is NOT actually a CID font then CIDs should be mapped
           // directly to GIDs.
-          for (var glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
+          for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
             charCodeToGlyphId[glyphId] = glyphId;
           }
         }
@@ -5728,7 +5751,7 @@ var CFFParser = (function CFFParserClosure() {
       var operands = [];
       var entries = [];
 
-      var pos = 0;
+      pos = 0;
       var end = dict.length;
       while (pos < end) {
         var b = dict[pos];
@@ -5752,13 +5775,14 @@ var CFFParser = (function CFFParserClosure() {
       var offsets = [];
       var start = pos;
       var end = pos;
+      var i, ii;
 
       if (count !== 0) {
         var offsetSize = bytes[pos++];
         // add 1 for offset to determine size of last object
         var startPos = pos + ((count + 1) * offsetSize) - 1;
 
-        for (var i = 0, ii = count + 1; i < ii; ++i) {
+        for (i = 0, ii = count + 1; i < ii; ++i) {
           var offset = 0;
           for (var j = 0; j < offsetSize; ++j) {
             offset <<= 8;
@@ -5768,7 +5792,7 @@ var CFFParser = (function CFFParserClosure() {
         }
         end = offsets[count];
       }
-      for (var i = 0, ii = offsets.length - 1; i < ii; ++i) {
+      for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
         var offsetStart = offsets[i];
         var offsetEnd = offsets[i + 1];
         cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
@@ -5984,31 +6008,32 @@ var CFFParser = (function CFFParserClosure() {
       var start = pos;
       var format = bytes[pos++];
       var charset = ['.notdef'];
+      var id, count, i;
 
       // subtract 1 for the .notdef glyph
       length -= 1;
 
       switch (format) {
         case 0:
-          for (var i = 0; i < length; i++) {
-            var id = (bytes[pos++] << 8) | bytes[pos++];
+          for (i = 0; i < length; i++) {
+            id = (bytes[pos++] << 8) | bytes[pos++];
             charset.push(cid ? id : strings.get(id));
           }
           break;
         case 1:
           while (charset.length <= length) {
-            var id = (bytes[pos++] << 8) | bytes[pos++];
-            var count = bytes[pos++];
-            for (var i = 0; i <= count; i++) {
+            id = (bytes[pos++] << 8) | bytes[pos++];
+            count = bytes[pos++];
+            for (i = 0; i <= count; i++) {
               charset.push(cid ? id++ : strings.get(id++));
             }
           }
           break;
         case 2:
           while (charset.length <= length) {
-            var id = (bytes[pos++] << 8) | bytes[pos++];
-            var count = (bytes[pos++] << 8) | bytes[pos++];
-            for (var i = 0; i <= count; i++) {
+            id = (bytes[pos++] << 8) | bytes[pos++];
+            count = (bytes[pos++] << 8) | bytes[pos++];
+            for (i = 0; i <= count; i++) {
               charset.push(cid ? id++ : strings.get(id++));
             }
           }
@@ -6030,12 +6055,12 @@ var CFFParser = (function CFFParserClosure() {
       var bytes = this.bytes;
       var predefined = false;
       var hasSupplement = false;
-      var format;
+      var format, i, ii;
       var raw = null;
 
       function readSupplement() {
         var supplementsCount = bytes[pos++];
-        for (var i = 0; i < supplementsCount; i++) {
+        for (i = 0; i < supplementsCount; i++) {
           var code = bytes[pos++];
           var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
           encoding[code] = charset.indexOf(strings.get(sid));
@@ -6047,7 +6072,7 @@ var CFFParser = (function CFFParserClosure() {
         format = pos;
         var baseEncoding = pos ? Encodings.ExpertEncoding :
                                  Encodings.StandardEncoding;
-        for (var i = 0, ii = charset.length; i < ii; i++) {
+        for (i = 0, ii = charset.length; i < ii; i++) {
           var index = baseEncoding.indexOf(charset[i]);
           if (index != -1) {
             encoding[index] = i;
@@ -6055,11 +6080,11 @@ var CFFParser = (function CFFParserClosure() {
         }
       } else {
         var dataStart = pos;
-        var format = bytes[pos++];
+        format = bytes[pos++];
         switch (format & 0x7f) {
           case 0:
             var glyphsCount = bytes[pos++];
-            for (var i = 1; i <= glyphsCount; i++) {
+            for (i = 1; i <= glyphsCount; i++) {
               encoding[bytes[pos++]] = i;
             }
             break;
@@ -6067,7 +6092,7 @@ var CFFParser = (function CFFParserClosure() {
           case 1:
             var rangesCount = bytes[pos++];
             var gid = 1;
-            for (var i = 0; i < rangesCount; i++) {
+            for (i = 0; i < rangesCount; i++) {
               var start = bytes[pos++];
               var left = bytes[pos++];
               for (var j = start; j <= start + left; j++) {
@@ -6101,16 +6126,18 @@ var CFFParser = (function CFFParserClosure() {
       var bytes = this.bytes;
       var format = bytes[pos++];
       var fdSelect = [];
+      var i;
+
       switch (format) {
         case 0:
-          for (var i = 0; i < length; ++i) {
+          for (i = 0; i < length; ++i) {
             var id = bytes[pos++];
             fdSelect.push(id);
           }
           break;
         case 3:
           var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
-          for (var i = 0; i < rangesCount; ++i) {
+          for (i = 0; i < rangesCount; ++i) {
             var first = (bytes[pos++] << 8) | bytes[pos++];
             var fdIndex = bytes[pos++];
             var next = (bytes[pos] << 8) | bytes[pos + 1];
@@ -6570,7 +6597,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
         output.add(fdSelect);
         // It is unclear if the sub font dictionary can have CID related
         // dictionary keys, but the sanitizer doesn't like them so remove them.
-        var compiled = this.compileTopDicts(cff.fdArray, output.length, true);
+        compiled = this.compileTopDicts(cff.fdArray, output.length, true);
         topDictTracker.setEntryLocation('FDArray', [output.length], output);
         output.add(compiled.output);
         var fontDictTrackers = compiled.trackers;
@@ -6604,7 +6631,8 @@ var CFFCompiler = (function CFFCompilerClosure() {
       }
 
       var nibbles = '';
-      for (var i = 0, ii = value.length; i < ii; ++i) {
+      var i, ii;
+      for (i = 0, ii = value.length; i < ii; ++i) {
         var a = value[i];
         if (a === 'e') {
           nibbles += value[++i] === '-' ? 'c' : 'b';
@@ -6618,7 +6646,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
       }
       nibbles += (nibbles.length & 1) ? 'f' : 'ff';
       var out = [30];
-      for (var i = 0, ii = nibbles.length; i < ii; i += 2) {
+      for (i = 0, ii = nibbles.length; i < ii; i += 2) {
         out.push(parseInt(nibbles.substr(i, 2), 16));
       }
       return out;
@@ -6821,8 +6849,8 @@ var CFFCompiler = (function CFFCompilerClosure() {
 
       var data = [(count >> 8) & 0xFF, count & 0xff];
 
-      var lastOffset = 1;
-      for (var i = 0; i < count; ++i) {
+      var lastOffset = 1, i;
+      for (i = 0; i < count; ++i) {
         lastOffset += objects[i].length;
       }
 
@@ -6842,7 +6870,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
 
       // Add another offset after this one because we need a new offset
       var relativeOffset = 1;
-      for (var i = 0; i < count + 1; i++) {
+      for (i = 0; i < count + 1; i++) {
         if (offsetSize === 1) {
           data.push(relativeOffset & 0xFF);
         } else if (offsetSize === 2) {
@@ -6865,7 +6893,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
       }
       var offset = data.length;
 
-      for (var i = 0; i < count; i++) {
+      for (i = 0; i < count; i++) {
         // Notify the tracker where the object will be offset in the data.
         if (trackers[i]) {
           trackers[i].offset(data.length);
diff --git a/src/core/image.js b/src/core/image.js
index edc8443..19d867a 100644
--- a/src/core/image.js
+++ b/src/core/image.js
@@ -268,20 +268,20 @@ var PDFImage = (function PDFImageClosure() {
       var decodeMap = this.decode;
       var numComps = this.numComps;
 
-      var decodeAddends, decodeCoefficients;
       var decodeAddends = this.decodeAddends;
       var decodeCoefficients = this.decodeCoefficients;
       var max = (1 << bpc) - 1;
+      var i, ii;
 
       if (bpc === 1) {
         // If the buffer needed decode that means it just needs to be inverted.
-        for (var i = 0, ii = buffer.length; i < ii; i++) {
+        for (i = 0, ii = buffer.length; i < ii; i++) {
           buffer[i] = +!(buffer[i]);
         }
         return;
       }
       var index = 0;
-      for (var i = 0, ii = this.width * this.height; i < ii; i++) {
+      for (i = 0, ii = this.width * this.height; i < ii; i++) {
         for (var j = 0; j < numComps; j++) {
           buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
                                          decodeCoefficients[j], max);
@@ -308,10 +308,11 @@ var PDFImage = (function PDFImageClosure() {
       var rowComps = width * numComps;
 
       var max = (1 << bpc) - 1;
+      var i = 0, ii, buf;
 
       if (bpc === 1) {
         // Optimization for reading 1 bpc images.
-        var i = 0, buf, mask, loop1End, loop2End;
+        var mask, loop1End, loop2End;
         for (var j = 0; j < height; j++) {
           loop1End = i + (rowComps & ~7);
           loop2End = i + rowComps;
@@ -342,8 +343,9 @@ var PDFImage = (function PDFImageClosure() {
         }
       } else {
         // The general case that handles all other bpc values.
-        var bits = 0, buf = 0;
-        for (var i = 0, ii = length; i < ii; ++i) {
+        var bits = 0;
+        buf = 0;
+        for (i = 0, ii = length; i < ii; ++i) {
           if (i % rowComps === 0) {
             buf = 0;
             bits = 0;
@@ -367,11 +369,11 @@ var PDFImage = (function PDFImageClosure() {
                                                actualHeight, image) {
       var smask = this.smask;
       var mask = this.mask;
-      var alphaBuf;
+      var alphaBuf, sw, sh, i, ii, j;
 
       if (smask) {
-        var sw = smask.width;
-        var sh = smask.height;
+        sw = smask.width;
+        sh = smask.height;
         alphaBuf = new Uint8Array(sw * sh);
         smask.fillGrayBuffer(alphaBuf);
         if (sw != width || sh != height) {
@@ -380,14 +382,14 @@ var PDFImage = (function PDFImageClosure() {
         }
       } else if (mask) {
         if (mask instanceof PDFImage) {
-          var sw = mask.width;
-          var sh = mask.height;
+          sw = mask.width;
+          sh = mask.height;
           alphaBuf = new Uint8Array(sw * sh);
           mask.numComps = 1;
           mask.fillGrayBuffer(alphaBuf);
 
           // Need to invert values in rgbaBuf
-          for (var i = 0, ii = sw * sh; i < ii; ++i) {
+          for (i = 0, ii = sw * sh; i < ii; ++i) {
             alphaBuf[i] = 255 - alphaBuf[i];
           }
 
@@ -400,10 +402,10 @@ var PDFImage = (function PDFImageClosure() {
           // then they should be painted.
           alphaBuf = new Uint8Array(width * height);
           var numComps = this.numComps;
-          for (var i = 0, ii = width * height; i < ii; ++i) {
+          for (i = 0, ii = width * height; i < ii; ++i) {
             var opacity = 0;
             var imageOffset = i * numComps;
-            for (var j = 0; j < numComps; ++j) {
+            for (j = 0; j < numComps; ++j) {
               var color = image[imageOffset + j];
               var maskOffset = j * 2;
               if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
@@ -419,12 +421,12 @@ var PDFImage = (function PDFImageClosure() {
       }
 
       if (alphaBuf) {
-        for (var i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
+        for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
           rgbaBuf[j] = alphaBuf[i];
         }
       } else {
         // No mask.
-        for (var i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
+        for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
           rgbaBuf[j] = 255;
         }
       }
@@ -560,18 +562,19 @@ var PDFImage = (function PDFImageClosure() {
       var imgArray = this.getImageBytes(height * rowBytes);
 
       var comps = this.getComponents(imgArray);
+      var i, length;
 
       if (bpc === 1) {
         // inline decoding (= inversion) for 1 bpc images
-        var length = width * height;
+        length = width * height;
         if (this.needsDecode) {
           // invert and scale to {0, 255} 
-          for (var i = 0; i < length; ++i) {
+          for (i = 0; i < length; ++i) {
             buffer[i] = (comps[i] - 1) & 255;
           }
         } else {
           // scale to {0, 255}
-          for (var i = 0; i < length; ++i) {
+          for (i = 0; i < length; ++i) {
             buffer[i] = (-comps[i]) & 255;
           }
         }
@@ -581,10 +584,10 @@ var PDFImage = (function PDFImageClosure() {
       if (this.needsDecode) {
         this.decodeBuffer(comps);
       }
-      var length = width * height;
+      length = width * height;
       // we aren't using a colorspace so we need to scale the value
       var scale = 255 / ((1 << bpc) - 1);
-      for (var i = 0; i < length; ++i) {
+      for (i = 0; i < length; ++i) {
         buffer[i] = (scale * comps[i]) | 0;
       }
     },
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index c3102fa..1fc244a 100755
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -237,8 +237,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
     var templateY = new Int8Array(templateLength);
     var changingTemplateEntries = [];
     var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
+    var c, k;
 
-    for (var k = 0; k < templateLength; k++) {
+    for (k = 0; k < templateLength; k++) {
       templateX[k] = template[k].x;
       templateY[k] = template[k].y;
       minX = Math.min(minX, template[k].x);
@@ -260,7 +261,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
     var changingTemplateX = new Int8Array(changingEntriesLength);
     var changingTemplateY = new Int8Array(changingEntriesLength);
     var changingTemplateBit = new Uint16Array(changingEntriesLength);
-    for (var c = 0; c < changingEntriesLength; c++) {
+    for (c = 0; c < changingEntriesLength; c++) {
       k = changingTemplateEntries[c];
       changingTemplateX[c] = template[k].x;
       changingTemplateY[c] = template[k].y;
@@ -279,7 +280,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
     var decoder = decodingContext.decoder;
     var contexts = decodingContext.contextCache.getContexts('GB');
 
-    var ltp = 0, c, j, i0, j0, k, contextLabel = 0, bit, shift;
+    var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
     for (var i = 0; i < height; i++) {
       if (prediction) {
         var sltp = decoder.readBit(contexts, pseudoPixelContext);
@@ -346,7 +347,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
     var codingTemplateLength = codingTemplate.length;
     var codingTemplateX = new Int32Array(codingTemplateLength);
     var codingTemplateY = new Int32Array(codingTemplateLength);
-    for (var k = 0; k < codingTemplateLength; k++) {
+    var k;
+    for (k = 0; k < codingTemplateLength; k++) {
       codingTemplateX[k] = codingTemplate[k].x;
       codingTemplateY[k] = codingTemplate[k].y;
     }
@@ -358,7 +360,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
     var referenceTemplateLength = referenceTemplate.length;
     var referenceTemplateX = new Int32Array(referenceTemplateLength);
     var referenceTemplateY = new Int32Array(referenceTemplateLength);
-    for (var k = 0; k < referenceTemplateLength; k++) {
+    for (k = 0; k < referenceTemplateLength; k++) {
       referenceTemplateX[k] = referenceTemplate[k].x;
       referenceTemplateY[k] = referenceTemplate[k].y;
     }
@@ -383,19 +385,20 @@ var Jbig2Image = (function Jbig2ImageClosure() {
       var row = new Uint8Array(width);
       bitmap.push(row);
       for (var j = 0; j < width; j++) {
-
+        var i0, j0;
         var contextLabel = 0;
-        for (var k = 0; k < codingTemplateLength; k++) {
-          var i0 = i + codingTemplateY[k], j0 = j + codingTemplateX[k];
+        for (k = 0; k < codingTemplateLength; k++) {
+          i0 = i + codingTemplateY[k];
+          j0 = j + codingTemplateX[k];
           if (i0 < 0 || j0 < 0 || j0 >= width) {
             contextLabel <<= 1; // out of bound pixel
           } else {
             contextLabel = (contextLabel << 1) | bitmap[i0][j0];
           }
         }
-        for (var k = 0; k < referenceTemplateLength; k++) {
-          var i0 = i + referenceTemplateY[k] + offsetY;
-          var j0 = j + referenceTemplateX[k] + offsetX;
+        for (k = 0; k < referenceTemplateLength; k++) {
+          i0 = i + referenceTemplateY[k] + offsetY;
+          j0 = j + referenceTemplateX[k] + offsetX;
           if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
               j0 >= referenceWidth) {
             contextLabel <<= 1; // out of bound pixel
@@ -512,8 +515,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
 
     // Prepare bitmap
     var bitmap = [];
-    for (var i = 0; i < height; i++) {
-      var row = new Uint8Array(width);
+    var i, row;
+    for (i = 0; i < height; i++) {
+      row = new Uint8Array(width);
       if (defaultPixelValue) {
         for (var j = 0; j < width; j++) {
           row[j] = defaultPixelValue;
@@ -526,7 +530,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
     var contextCache = decodingContext.contextCache;
     var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
     var firstS = 0;
-    var i = 0;
+    i = 0;
     while (i < numberOfSymbolInstances) {
       var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
       stripT += deltaT;
@@ -535,12 +539,12 @@ var Jbig2Image = (function Jbig2ImageClosure() {
       firstS += deltaFirstS;
       var currentS = firstS;
       do {
-        var currentT = stripSize == 1 ? 0 :
-          decodeInteger(contextCache, 'IAIT', decoder); // 6.4.9
+        var currentT = (stripSize == 1 ? 0 :
+                        decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
         var t = stripSize * stripT + currentT;
         var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
-        var applyRefinement = refinement &&
-          decodeInteger(contextCache, 'IARI', decoder);
+        var applyRefinement = (refinement &&
+                               decodeInteger(contextCache, 'IARI', decoder));
         var symbolBitmap = inputSymbols[symbolId];
         var symbolWidth = symbolBitmap[0].length;
         var symbolHeight = symbolBitmap.length;
@@ -558,25 +562,26 @@ var Jbig2Image = (function Jbig2ImageClosure() {
         }
         var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
         var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
+        var s2, t2, symbolRow;
         if (transposed) {
           // Place Symbol Bitmap from T1,S1
-          for (var s2 = 0; s2 < symbolHeight; s2++) {
-            var row = bitmap[offsetS + s2];
+          for (s2 = 0; s2 < symbolHeight; s2++) {
+            row = bitmap[offsetS + s2];
             if (!row) {
               continue;
             }
-            var symbolRow = symbolBitmap[s2];
+            symbolRow = symbolBitmap[s2];
             // To ignore Parts of Symbol bitmap which goes
             // outside bitmap region
             var maxWidth = Math.min(width - offsetT, symbolWidth);
             switch (combinationOperator) {
               case 0: // OR
-                for (var t2 = 0; t2 < maxWidth; t2++) {
+                for (t2 = 0; t2 < maxWidth; t2++) {
                   row[offsetT + t2] |= symbolRow[t2];
                 }
                 break;
               case 2: // XOR
-                for (var t2 = 0; t2 < maxWidth; t2++) {
+                for (t2 = 0; t2 < maxWidth; t2++) {
                   row[offsetT + t2] ^= symbolRow[t2];
                 }
                 break;
@@ -587,20 +592,20 @@ var Jbig2Image = (function Jbig2ImageClosure() {
           }
           currentS += symbolHeight - 1;
         } else {
-          for (var t2 = 0; t2 < symbolHeight; t2++) {
-            var row = bitmap[offsetT + t2];
+          for (t2 = 0; t2 < symbolHeight; t2++) {
+            row = bitmap[offsetT + t2];
             if (!row) {
               continue;
             }
-            var symbolRow = symbolBitmap[t2];
+            symbolRow = symbolBitmap[t2];
             switch (combinationOperator) {
               case 0: // OR
-                for (var s2 = 0; s2 < symbolWidth; s2++) {
+                for (s2 = 0; s2 < symbolWidth; s2++) {
                   row[offsetS + s2] |= symbolRow[s2];
                 }
                 break;
               case 2: // XOR
-                for (var s2 = 0; s2 < symbolWidth; s2++) {
+                for (s2 = 0; s2 < symbolWidth; s2++) {
                   row[offsetS + s2] ^= symbolRow[s2];
                 }
                 break;
@@ -655,7 +660,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
     var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
       (segmentHeader.number <= 65536 ? 2 : 4));
     var referredTo = [];
-    for (var i = 0; i < referredToCount; i++) {
+    var i, ii;
+    for (i = 0; i < referredToCount; i++) {
       var number = (referredToSegmentNumberSize == 1 ? data[position] :
         (referredToSegmentNumberSize == 2 ? readUint16(data, position) :
         readUint32(data, position)));
@@ -690,7 +696,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
         searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
         searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
         searchPattern[5] = genericRegionInfo.height & 0xFF;
-        for (var i = position, ii = data.length; i < ii; i++) {
+        for (i = position, ii = data.length; i < ii; i++) {
           var j = 0;
           while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
             j++;
@@ -757,7 +763,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
     var header = segment.header;
 
     var data = segment.data, position = segment.start, end = segment.end;
-    var args;
+    var args, at, i, atLength;
     switch (header.type) {
       case 0: // SymbolDictionary
         // 7.4.2 Symbol dictionary segment syntax
@@ -775,9 +781,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
         dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
         position += 2;
         if (!dictionary.huffman) {
-          var atLength = dictionary.template === 0 ? 4 : 1;
-          var at = [];
-          for (var i = 0; i < atLength; i++) {
+          atLength = dictionary.template === 0 ? 4 : 1;
+          at = [];
+          for (i = 0; i < atLength; i++) {
             at.push({
               x: readInt8(data, position),
               y: readInt8(data, position + 1)
@@ -787,8 +793,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
           dictionary.at = at;
         }
         if (dictionary.refinement && !dictionary.refinementTemplate) {
-          var at = [];
-          for (var i = 0; i < 2; i++) {
+          at = [];
+          for (i = 0; i < 2; i++) {
             at.push({
               x: readInt8(data, position),
               y: readInt8(data, position + 1)
@@ -834,8 +840,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
             !!(textRegionHuffmanFlags & 14);
         }
         if (textRegion.refinement && !textRegion.refinementTemplate) {
-          var at = [];
-          for (var i = 0; i < 2; i++) {
+          at = [];
+          for (i = 0; i < 2; i++) {
             at.push({
               x: readInt8(data, position),
               y: readInt8(data, position + 1)
@@ -862,9 +868,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
         genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
         genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
         if (!genericRegion.mmr) {
-          var atLength = genericRegion.template === 0 ? 4 : 1;
-          var at = [];
-          for (var i = 0; i < atLength; i++) {
+          atLength = genericRegion.template === 0 ? 4 : 1;
+          at = [];
+          for (i = 0; i < atLength; i++) {
             at.push({
               x: readInt8(data, position),
               y: readInt8(data, position + 1)
@@ -976,12 +982,13 @@ var Jbig2Image = (function Jbig2ImageClosure() {
       var buffer = this.buffer;
       var mask0 =  128 >> (regionInfo.x & 7);
       var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
+      var i, j, mask, offset;
       switch (combinationOperator) {
         case 0: // OR
-          for (var i = 0; i < height; i++) {
-            var mask = mask0;
-            var offset = offset0;
-            for (var j = 0; j < width; j++) {
+          for (i = 0; i < height; i++) {
+            mask = mask0;
+            offset = offset0;
+            for (j = 0; j < width; j++) {
               if (bitmap[i][j]) {
                 buffer[offset] |= mask;
               }
@@ -995,10 +1002,10 @@ var Jbig2Image = (function Jbig2ImageClosure() {
           }
         break;
         case 2: // XOR
-          for (var i = 0; i < height; i++) {
-            var mask = mask0;
-            var offset = offset0;
-            for (var j = 0; j < width; j++) {
+          for (i = 0; i < height; i++) {
+            mask = mask0;
+            offset = offset0;
+            for (j = 0; j < width; j++) {
               if (bitmap[i][j]) {
                 buffer[offset] ^= mask;
               }
diff --git a/src/core/jpx.js b/src/core/jpx.js
index f051784..392f9a6 100644
--- a/src/core/jpx.js
+++ b/src/core/jpx.js
@@ -139,7 +139,7 @@ var JpxImage = (function JpxImageClosure() {
           var code = readUint16(data, position);
           position += 2;
 
-          var length = 0, j;
+          var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
           switch (code) {
             case 0xFF4F: // Start of codestream (SOC)
               context.mainHeader = true;
@@ -181,8 +181,7 @@ var JpxImage = (function JpxImageClosure() {
               length = readUint16(data, position);
               var qcd = {};
               j = position + 2;
-              var sqcd = data[j++];
-              var spqcdSize, scalarExpounded;
+              sqcd = data[j++];
               switch (sqcd & 0x1F) {
                 case 0:
                   spqcdSize = 8;
@@ -202,7 +201,7 @@ var JpxImage = (function JpxImageClosure() {
               qcd.noQuantization = (spqcdSize == 8);
               qcd.scalarExpounded = scalarExpounded;
               qcd.guardBits = sqcd >> 5;
-              var spqcds = [];
+              spqcds = [];
               while (j < length + position) {
                 var spqcd = {};
                 if (spqcdSize == 8) {
@@ -234,8 +233,7 @@ var JpxImage = (function JpxImageClosure() {
                 cqcc = readUint16(data, j);
                 j += 2;
               }
-              var sqcd = data[j++];
-              var spqcdSize, scalarExpounded;
+              sqcd = data[j++];
               switch (sqcd & 0x1F) {
                 case 0:
                   spqcdSize = 8;
@@ -255,9 +253,9 @@ var JpxImage = (function JpxImageClosure() {
               qcc.noQuantization = (spqcdSize == 8);
               qcc.scalarExpounded = scalarExpounded;
               qcc.guardBits = sqcd >> 5;
-              var spqcds = [];
+              spqcds = [];
               while (j < (length + position)) {
-                var spqcd = {};
+                spqcd = {};
                 if (spqcdSize == 8) {
                   spqcd.epsilon = data[j++] >> 3;
                   spqcd.mu = 0;
@@ -330,7 +328,7 @@ var JpxImage = (function JpxImageClosure() {
               break;
             case 0xFF90: // Start of tile-part (SOT)
               length = readUint16(data, position);
-              var tile = {};
+              tile = {};
               tile.index = readUint16(data, position + 2);
               tile.length = readUint32(data, position + 4);
               tile.dataEnd = tile.length + position - 2;
@@ -348,7 +346,7 @@ var JpxImage = (function JpxImageClosure() {
               context.currentTile = tile;
               break;
             case 0xFF93: // Start of data (SOD)
-              var tile = context.currentTile;
+              tile = context.currentTile;
               if (tile.partIndex === 0) {
                 initializeTile(context, tile.index);
                 buildPackets(context);
@@ -409,12 +407,12 @@ var JpxImage = (function JpxImageClosure() {
   function calculateTileGrids(context, components) {
     var siz = context.SIZ;
     // Section B.3 Division into tile and tile-components
-    var tiles = [];
+    var tile, tiles = [];
     var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
     var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
     for (var q = 0; q < numYtiles; q++) {
       for (var p = 0; p < numXtiles; p++) {
-        var tile = {};
+        tile = {};
         tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
         tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
         tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
@@ -432,7 +430,8 @@ var JpxImage = (function JpxImageClosure() {
       var component = components[i];
       var tileComponents = [];
       for (var j = 0, jj = tiles.length; j < jj; j++) {
-        var tileComponent = {}, tile = tiles[j];
+        var tileComponent = {};
+        tile = tiles[j];
         tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
         tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
         tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
@@ -498,9 +497,10 @@ var JpxImage = (function JpxImageClosure() {
     var precinctParameters = subband.resolution.precinctParameters;
     var codeblocks = [];
     var precincts = [];
-    for (var j = cby0; j < cby1; j++) {
-      for (var i = cbx0; i < cbx1; i++) {
-        var codeblock = {
+    var i, ii, j, codeblock, precinctNumber;
+    for (j = cby0; j < cby1; j++) {
+      for (i = cbx0; i < cbx1; i++) {
+        codeblock = {
           cbx: i,
           cby: j,
           tbx0: codeblockWidth * i,
@@ -515,8 +515,7 @@ var JpxImage = (function JpxImageClosure() {
         var pj = Math.floor((codeblock.tby0 -
                  precinctParameters.precinctYOffset) /
                  precinctParameters.precinctHeight);
-        var precinctNumber = pj +
-                             pi * precinctParameters.numprecinctswide;
+        precinctNumber = pj + pi * precinctParameters.numprecinctswide;
         codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
         codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
         codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
@@ -816,19 +815,20 @@ var JpxImage = (function JpxImageClosure() {
         continue;
       }
       var layerNumber = packet.layerNumber;
-      var queue = [];
+      var queue = [], codeblock;
       for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
-        var codeblock = packet.codeblocks[i];
+        codeblock = packet.codeblocks[i];
         var precinct = codeblock.precinct;
         var codeblockColumn = codeblock.cbx - precinct.cbxMin;
         var codeblockRow = codeblock.cby - precinct.cbyMin;
         var codeblockIncluded = false;
         var firstTimeInclusion = false;
+        var valueReady;
         if ('included' in codeblock) {
           codeblockIncluded = !!readBits(1);
         } else {
           // reading inclusion tree
-          var precinct = codeblock.precinct;
+          precinct = codeblock.precinct;
           var inclusionTree, zeroBitPlanesTree;
           if ('inclusionTree' in precinct) {
             inclusionTree = precinct.inclusionTree;
@@ -845,7 +845,7 @@ var JpxImage = (function JpxImageClosure() {
           if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
             while (true) {
               if (readBits(1)) {
-                var valueReady = !inclusionTree.nextLevel();
+                valueReady = !inclusionTree.nextLevel();
                 if (valueReady) {
                   codeblock.included = true;
                   codeblockIncluded = firstTimeInclusion = true;
@@ -866,7 +866,7 @@ var JpxImage = (function JpxImageClosure() {
           zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
           while (true) {
             if (readBits(1)) {
-              var valueReady = !zeroBitPlanesTree.nextLevel();
+              valueReady = !zeroBitPlanesTree.nextLevel();
               if (valueReady) {
                 break;
               }
@@ -894,7 +894,7 @@ var JpxImage = (function JpxImageClosure() {
       alignToByte();
       while (queue.length > 0) {
         var packetItem = queue.shift();
-        var codeblock = packetItem.codeblock;
+        codeblock = packetItem.codeblock;
         if (!('data' in codeblock)) {
           codeblock.data = [];
         }
@@ -930,14 +930,15 @@ var JpxImage = (function JpxImageClosure() {
 
       // collect data
       var data = codeblock.data, totalLength = 0, codingpasses = 0;
-      for (var q = 0, qq = data.length; q < qq; q++) {
-        var dataItem = data[q];
+      var q, qq, dataItem;
+      for (q = 0, qq = data.length; q < qq; q++) {
+        dataItem = data[q];
         totalLength += dataItem.end - dataItem.start;
         codingpasses += dataItem.codingpasses;
       }
       var encodedData = new Uint8Array(totalLength), k = 0;
-      for (var q = 0, qq = data.length; q < qq; q++) {
-        var dataItem = data[q];
+      for (q = 0, qq = data.length; q < qq; q++) {
+        dataItem = data[q];
         var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
         encodedData.set(chunk, k);
         k += chunk.length;
@@ -946,7 +947,7 @@ var JpxImage = (function JpxImageClosure() {
       var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
       bitModel.setDecoder(decoder);
 
-      for (var q = 0; q < codingpasses; q++) {
+      for (q = 0; q < codingpasses; q++) {
         switch (currentCodingpassType) {
           case 0:
             bitModel.runSignificancePropogationPass();
@@ -972,7 +973,7 @@ var JpxImage = (function JpxImageClosure() {
       var bitsDecoded = bitModel.bitsDecoded;
       var magnitudeCorrection = reversible ? 0 : 0.5;
       for (var j = 0; j < blockHeight; j++) {
-        for (var k = 0; k < blockWidth; k++) {
+        for (k = 0; k < blockWidth; k++) {
           n = magnitude[position];
           if (n !== 0) {
             n = (n + magnitudeCorrection) * delta;
@@ -1068,32 +1069,35 @@ var JpxImage = (function JpxImageClosure() {
     for (var i = 0, ii = context.tiles.length; i < ii; i++) {
       var tile = context.tiles[i];
       var result = [];
-      for (var c = 0; c < componentsCount; c++) {
+      var c;
+      for (c = 0; c < componentsCount; c++) {
         var image = transformTile(context, tile, c);
         result.push(image);
       }
 
       // Section G.2.2 Inverse multi component transform
+      var y0items, y1items, y2items, j, jj, y0, y1, y2;
+      var component, offset, tileImage, items;
       if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
         var component0 = tile.components[0];
         if (!component0.codingStyleParameters.reversibleTransformation) {
           // inverse irreversible multiple component transform
-          var y0items = result[0].items;
-          var y1items = result[1].items;
-          var y2items = result[2].items;
-          for (var j = 0, jj = y0items.length; j < jj; ++j) {
-            var y0 = y0items[j] + 0.5, y1 = y1items[j], y2 = y2items[j];
+          y0items = result[0].items;
+          y1items = result[1].items;
+          y2items = result[2].items;
+          for (j = 0, jj = y0items.length; j < jj; ++j) {
+            y0 = y0items[j] + 0.5; y1 = y1items[j]; y2 = y2items[j];
             y0items[j] = y0 + 1.402 * y2;
             y1items[j] = y0 - 0.34413 * y1 - 0.71414 * y2;
             y2items[j] = y0 + 1.772 * y1;
           }
         } else {
           // inverse reversible multiple component transform
-          var y0items = result[0].items;
-          var y1items = result[1].items;
-          var y2items = result[2].items;
-          for (var j = 0, jj = y0items.length; j < jj; ++j) {
-            var y0 = y0items[j], y1 = y1items[j], y2 = y2items[j];
+          y0items = result[0].items;
+          y1items = result[1].items;
+          y2items = result[2].items;
+          for (j = 0, jj = y0items.length; j < jj; ++j) {
+            y0 = y0items[j]; y1 = y1items[j]; y2 = y2items[j];
             var i1 = y0 - ((y2 + y1) >> 2);
             y1items[j] = i1;
             y0items[j] = y2 + i1;
@@ -1103,15 +1107,15 @@ var JpxImage = (function JpxImageClosure() {
       }
 
       // To simplify things: shift and clamp output to 8 bit unsigned
-      for (var c = 0; c < componentsCount; c++) {
-        var component = components[c];
+      for (c = 0; c < componentsCount; c++) {
+        component = components[c];
         var shift = component.precision - 8;
-        var tileImage = result[c];
-        var items = tileImage.items;
+        tileImage = result[c];
+        items = tileImage.items;
         var data = new Uint8Array(items.length);
         var low = -(128 << shift);
         var high = 127 << shift;
-        for (var j = 0, jj = items.length; j < jj; j++) {
+        for (j = 0, jj = items.length; j < jj; j++) {
           var val = items[j];
           data[j] = val <= low ? 0 : val >= high ? 255 : (val >> shift) + 128;
         }
@@ -1157,9 +1161,9 @@ var JpxImage = (function JpxImageClosure() {
     }
     TagTree.prototype = {
       reset: function TagTree_reset(i, j) {
-        var currentLevel = 0, value = 0;
+        var currentLevel = 0, value = 0, level;
         while (currentLevel < this.levels.length) {
-          var level = this.levels[currentLevel];
+          level = this.levels[currentLevel];
           var index = i + j * level.width;
           if (index in level.items) {
             value = level.items[index];
@@ -1171,7 +1175,7 @@ var JpxImage = (function JpxImageClosure() {
           currentLevel++;
         }
         currentLevel--;
-        var level = this.levels[currentLevel];
+        level = this.levels[currentLevel];
         level.items[level.index] = value;
         this.currentLevel = currentLevel;
         delete this.value;
@@ -1191,7 +1195,7 @@ var JpxImage = (function JpxImageClosure() {
         }
 
         this.currentLevel = currentLevel;
-        var level = this.levels[currentLevel];
+        level = this.levels[currentLevel];
         level.items[level.index] = value;
         return true;
       }
@@ -1257,7 +1261,7 @@ var JpxImage = (function JpxImageClosure() {
         var level = this.levels[levelIndex];
         var currentValue = level.items[level.index];
         while (--levelIndex >= 0) {
-          var level = this.levels[levelIndex];
+          level = this.levels[levelIndex];
           level.items[level.index] = currentValue;
         }
       },
@@ -1272,7 +1276,7 @@ var JpxImage = (function JpxImageClosure() {
         }
 
         this.currentLevel = currentLevel;
-        var level = this.levels[currentLevel];
+        level = this.levels[currentLevel];
         level.items[level.index] = value;
         return true;
       }
@@ -1351,9 +1355,10 @@ var JpxImage = (function JpxImageClosure() {
         var width = this.width, height = this.height;
         var left = (column > 0);
         var right = (column + 1 < width);
+        var i;
 
         if (row > 0) {
-          var i = index - width;
+          i = index - width;
           if (left) {
             neighborsSignificance[i - 1] += 0x10;
           }
@@ -1364,7 +1369,7 @@ var JpxImage = (function JpxImageClosure() {
         }
 
         if (row + 1 < height) {
-          var i = index + width;
+          i = index + width;
           if (left) {
             neighborsSignificance[i - 1] += 0x10;
           }
@@ -1434,6 +1439,7 @@ var JpxImage = (function JpxImageClosure() {
         var coefficentsMagnitude = this.coefficentsMagnitude;
         var coefficentsSign = this.coefficentsSign;
         var contribution, sign0, sign1, significance1;
+        var contextLabel, decoded;
 
         // calculate horizontal contribution
         significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
@@ -1471,11 +1477,11 @@ var JpxImage = (function JpxImageClosure() {
         }
 
         if (contribution >= 0) {
-          var contextLabel = 9 + contribution;
-          var decoded = this.decoder.readBit(this.contexts, contextLabel);
+          contextLabel = 9 + contribution;
+          decoded = this.decoder.readBit(this.contexts, contextLabel);
         } else {
-          var contextLabel = 9 - contribution;
-          var decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
+          contextLabel = 9 - contribution;
+          decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
         }
         return decoded;
       },
@@ -1552,7 +1558,7 @@ var JpxImage = (function JpxImageClosure() {
               neighborsSignificance[index0 + twoRowsDown] === 0 &&
               neighborsSignificance[index0 + threeRowsDown] === 0);
             var i1 = 0, index = index0;
-            var i;
+            var i, sign;
             if (allEmpty) {
               var hasSignificantCoefficent =
                 decoder.readBit(contexts, RUNLENGTH_CONTEXT);
@@ -1568,7 +1574,7 @@ var JpxImage = (function JpxImageClosure() {
               i = i0 + i1;
               index += i1 * width;
 
-              var sign = this.decodeSignBit(i, j, index);
+              sign = this.decodeSignBit(i, j, index);
               coefficentsSign[index] = sign;
               coefficentsMagnitude[index] = 1;
               this.setNeighborsSignificance(i, j, index);
@@ -1595,7 +1601,7 @@ var JpxImage = (function JpxImageClosure() {
               var contextLabel = labels[neighborsSignificance[index]];
               var decision = decoder.readBit(contexts, contextLabel);
               if (decision == 1) {
-                var sign = this.decodeSignBit(i, j, index);
+                sign = this.decodeSignBit(i, j, index);
                 coefficentsSign[index] = sign;
                 coefficentsMagnitude[index] = 1;
                 this.setNeighborsSignificance(i, j, index);
@@ -1659,11 +1665,11 @@ var JpxImage = (function JpxImageClosure() {
       var width = llWidth + hlWidth;
       var height = llHeight + lhHeight;
       var items = new Float32Array(width * height);
-      var i, j, k, l;
+      var i, j, k, l, v, u;
 
       for (i = 0, k = 0; i < llHeight; i++) {
         l = i * 2 * width;
-        for (var j = 0; j < llWidth; j++, k++, l += 2) {
+        for (j = 0; j < llWidth; j++, k++, l += 2) {
           items[l] = llItems[k];
         }
       }
@@ -1693,12 +1699,12 @@ var JpxImage = (function JpxImageClosure() {
       if (width === 1) {
         // if width = 1, when u0 even keep items as is, when odd divide by 2
         if ((u0 & 1) !== 0) {
-          for (var v = 0, k = 0; v < height; v++, k += width) {
+          for (v = 0, k = 0; v < height; v++, k += width) {
             items[k] *= 0.5;
           }
         }
       } else {
-        for (var v = 0, k = 0; v < height; v++, k += width) {
+        for (v = 0, k = 0; v < height; v++, k += width) {
           rowBuffer.set(items.subarray(k, k + width), bufferPadding);
 
           this.extend(rowBuffer, bufferPadding, width);
@@ -1721,18 +1727,19 @@ var JpxImage = (function JpxImageClosure() {
       for (i = 0; i < numBuffers; i++) {
         colBuffers.push(new Float32Array(height + 2 * bufferPadding));
       }
-      var b, currentBuffer = 0, ll = bufferPadding + height;
+      var b, currentBuffer = 0;
+      ll = bufferPadding + height;
 
       // Section F.3.5 VER_SR
       if (height === 1) {
           // if height = 1, when v0 even keep items as is, when odd divide by 2
         if ((v0 & 1) !== 0) {
-          for (var u = 0; u < width; u++) {
+          for (u = 0; u < width; u++) {
             items[u] *= 0.5;
           }
         }
       } else {
-        for (var u = 0; u < width; u++) {
+        for (u = 0; u < width; u++) {
           // if we ran out of buffers, copy several image columns at once
           if (currentBuffer === 0) {
             numBuffers = Math.min(width - u, numBuffers);
@@ -1780,7 +1787,7 @@ var JpxImage = (function JpxImageClosure() {
     IrreversibleTransform.prototype.filter =
       function irreversibleTransformFilter(y, offset, length, i0, x) {
       var len = length >> 1;
-      var offset = offset | 0;
+      offset = offset | 0;
 
       var alpha = -1.586134342059924;
       var beta = -0.052980118572961;
@@ -1788,32 +1795,33 @@ var JpxImage = (function JpxImageClosure() {
       var delta = 0.443506852043971;
       var K = 1.230174104914001;
       var K_ = 1 / K;
+      var j, n, nn;
 
       // step 1 is combined with step 3
 
       // step 2
-      for (var j = offset - 3, n = len + 4; n--; j += 2) {
+      for (j = offset - 3, n = len + 4; n--; j += 2) {
         x[j] = K_ * y[j];
       }
 
       // step 1 & 3
-      for (var j = offset - 2, n = len + 3; n--; j += 2) {
+      for (j = offset - 2, n = len + 3; n--; j += 2) {
         x[j] = K * y[j] -
           delta * (x[j - 1] + x[j + 1]);
       }
 
       // step 4
-      for (var j = offset - 1, n = len + 2; n--; j += 2) {
+      for (j = offset - 1, n = len + 2; n--; j += 2) {
         x[j] -= gamma * (x[j - 1] + x[j + 1]);
       }
 
       // step 5
-      for (var j = offset, n = len + 1; n--; j += 2) {
+      for (j = offset, n = len + 1; n--; j += 2) {
         x[j] -= beta * (x[j - 1] + x[j + 1]);
       }
 
       // step 6
-      for (var j = offset + 1, n = len; n--; j += 2) {
+      for (j = offset + 1, n = len; n--; j += 2) {
         x[j] -= alpha * (x[j - 1] + x[j + 1]);
       }
     };
@@ -1831,13 +1839,14 @@ var JpxImage = (function JpxImageClosure() {
     ReversibleTransform.prototype.filter =
       function reversibleTransformFilter(y, offset, length, i0, x) {
       var len = length >> 1;
-      var offset = offset | 0;
+      offset = offset | 0;
+      var j, n;
 
-      for (var j = offset, n = len + 1; n--; j += 2) {
+      for (j = offset, n = len + 1; n--; j += 2) {
         x[j] = y[j] - ((y[j - 1] + y[j + 1] + 2) >> 2);
       }
 
-      for (var j = offset + 1, n = len; n--; j += 2) {
+      for (j = offset + 1, n = len; n--; j += 2) {
         x[j] = y[j] + ((x[j - 1] + x[j + 1]) >> 1);
       }
     };
diff --git a/src/core/obj.js b/src/core/obj.js
index 59c8dbf..d604535 100644
--- a/src/core/obj.js
+++ b/src/core/obj.js
@@ -988,13 +988,14 @@ var XRef = (function XRefClosure() {
         }
       }
       // reading XRef streams
-      for (var i = 0, ii = xrefStms.length; i < ii; ++i) {
+      var i, ii;
+      for (i = 0, ii = xrefStms.length; i < ii; ++i) {
         this.startXRefQueue.push(xrefStms[i]);
         this.readXRef(/* recoveryMode */ true);
       }
       // finding main trailer
       var dict;
-      for (var i = 0, ii = trailers.length; i < ii; ++i) {
+      for (i = 0, ii = trailers.length; i < ii; ++i) {
         stream.pos = trailers[i];
         var parser = new Parser(new Lexer(stream), true, null);
         var obj = parser.getObj();
@@ -1332,6 +1333,7 @@ var ObjectLoader = (function() {
   }
 
   function addChildren(node, nodesToVisit) {
+    var value;
     if (isDict(node) || isStream(node)) {
       var map;
       if (isDict(node)) {
@@ -1340,14 +1342,14 @@ var ObjectLoader = (function() {
         map = node.dict.map;
       }
       for (var key in map) {
-        var value = map[key];
+        value = map[key];
         if (mayHaveChildren(value)) {
           nodesToVisit.push(value);
         }
       }
     } else if (isArray(node)) {
       for (var i = 0, ii = node.length; i < ii; i++) {
-        var value = node[i];
+        value = node[i];
         if (mayHaveChildren(value)) {
           nodesToVisit.push(value);
         }
diff --git a/src/core/parser.js b/src/core/parser.js
index acdb46b..fb5e20f 100644
--- a/src/core/parser.js
+++ b/src/core/parser.js
@@ -192,7 +192,7 @@ var Parser = (function ParserClosure() {
 
         var a = 1;
         var b = 0;
-        for (var i = 0, ii = imageBytes.length; i < ii; ++i) {
+        for (i = 0, ii = imageBytes.length; i < ii; ++i) {
           a = (a + (imageBytes[i] & 0xff)) % 65521;
           b = (b + a) % 65521;
         }
@@ -261,11 +261,11 @@ var Parser = (function ParserClosure() {
         var ENDSTREAM_SIGNATURE_LENGTH = 9;
         var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
                                    0x61, 0x6D];
-        var skipped = 0, found = false;
+        var skipped = 0, found = false, i, j;
         while (stream.pos < stream.end) {
           var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
           var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
-          var found = false, i, j;
+          found = false;
           for (i = 0, j = 0; i < scanLength; i++) {
             var b = scanBytes[i];
             if (b !== ENDSTREAM_SIGNATURE[j]) {
diff --git a/src/core/pattern.js b/src/core/pattern.js
index a59c766..f84567e 100644
--- a/src/core/pattern.js
+++ b/src/core/pattern.js
@@ -162,15 +162,16 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
       return;
     }
 
+    var rgbColor;
     for (var i = t0; i <= t1; i += step) {
-      var rgbColor = cs.getRgb(fn([i]), 0);
+      rgbColor = cs.getRgb(fn([i]), 0);
       var cssColor = Util.makeCssRgb(rgbColor);
       colorStops.push([(i - t0) / diff, cssColor]);
     }
 
     var background = 'transparent';
     if (dict.has('Background')) {
-      var rgbColor = cs.getRgb(dict.get('Background'), 0);
+      rgbColor = cs.getRgb(dict.get('Background'), 0);
       background = Util.makeCssRgb(rgbColor);
     }
 
diff --git a/src/core/stream.js b/src/core/stream.js
index b2580f9..0faa56b 100644
--- a/src/core/stream.js
+++ b/src/core/stream.js
@@ -446,7 +446,8 @@ var FlateStream = (function FlateStreamClosure() {
 
     // find max code length
     var maxLen = 0;
-    for (var i = 0; i < n; ++i) {
+    var i;
+    for (i = 0; i < n; ++i) {
       if (lengths[i] > maxLen) {
         maxLen = lengths[i];
       }
@@ -463,13 +464,13 @@ var FlateStream = (function FlateStreamClosure() {
           // bit-reverse the code
           var code2 = 0;
           var t = code;
-          for (var i = 0; i < len; ++i) {
+          for (i = 0; i < len; ++i) {
             code2 = (code2 << 1) | (t & 1);
             t >>= 1;
           }
 
           // fill the table entries
-          for (var i = code2; i < size; i += skip) {
+          for (i = code2; i < size; i += skip) {
             codes[i] = (len << 16) | val;
           }
           ++code;
@@ -481,6 +482,7 @@ var FlateStream = (function FlateStreamClosure() {
   };
 
   FlateStream.prototype.readBlock = function FlateStream_readBlock() {
+    var buffer, len;
     var str = this.str;
     // read block header
     var hdr = this.getBits(3);
@@ -518,7 +520,7 @@ var FlateStream = (function FlateStreamClosure() {
       this.codeSize = 0;
 
       var bufferLength = this.bufferLength;
-      var buffer = this.ensureBuffer(bufferLength + blockLen);
+      buffer = this.ensureBuffer(bufferLength + blockLen);
       var end = bufferLength + blockLen;
       this.bufferLength = end;
       if (blockLen === 0) {
@@ -550,24 +552,26 @@ var FlateStream = (function FlateStreamClosure() {
       // build the code lengths code table
       var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
 
-      for (var i = 0; i < numCodeLenCodes; ++i) {
+      var i;
+      for (i = 0; i < numCodeLenCodes; ++i) {
         codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
       }
       var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
 
       // build the literal and distance code tables
-      var len = 0;
-      var i = 0;
+      len = 0;
+      i = 0;
       var codes = numLitCodes + numDistCodes;
       var codeLengths = new Uint8Array(codes);
+      var bitsLength, bitsOffset, what;
       while (i < codes) {
         var code = this.getCode(codeLenCodeTab);
         if (code == 16) {
-          var bitsLength = 2, bitsOffset = 3, what = len;
+          bitsLength = 2; bitsOffset = 3; what = len;
         } else if (code == 17) {
-          var bitsLength = 3, bitsOffset = 3, what = (len = 0);
+          bitsLength = 3; bitsOffset = 3; what = (len = 0);
         } else if (code == 18) {
-          var bitsLength = 7, bitsOffset = 11, what = (len = 0);
+          bitsLength = 7; bitsOffset = 11; what = (len = 0);
         } else {
           codeLengths[i++] = len = code;
           continue;
@@ -587,7 +591,7 @@ var FlateStream = (function FlateStreamClosure() {
       error('Unknown block type in flate stream');
     }
 
-    var buffer = this.buffer;
+    buffer = this.buffer;
     var limit = buffer ? buffer.length : 0;
     var pos = this.bufferLength;
     while (true) {
@@ -610,7 +614,7 @@ var FlateStream = (function FlateStreamClosure() {
       if (code2 > 0) {
         code2 = this.getBits(code2);
       }
-      var len = (code1 & 0xffff) + code2;
+      len = (code1 & 0xffff) + code2;
       code1 = this.getCode(distCodeTable);
       code1 = distDecode[code1];
       code2 = code1 >> 16;
@@ -683,9 +687,10 @@ var PredictorStream = (function PredictorStreamClosure() {
     var inbuf = 0, outbuf = 0;
     var inbits = 0, outbits = 0;
     var pos = bufferLength;
+    var i;
 
     if (bits === 1) {
-      for (var i = 0; i < rowBytes; ++i) {
+      for (i = 0; i < rowBytes; ++i) {
         var c = rawBytes[i];
         inbuf = (inbuf << 8) | c;
         // bitwise addition is exclusive or
@@ -695,7 +700,7 @@ var PredictorStream = (function PredictorStreamClosure() {
         inbuf &= 0xFFFF;
       }
     } else if (bits === 8) {
-      for (var i = 0; i < colors; ++i) {
+      for (i = 0; i < colors; ++i) {
         buffer[pos++] = rawBytes[i];
       }
       for (; i < rowBytes; ++i) {
@@ -707,7 +712,7 @@ var PredictorStream = (function PredictorStreamClosure() {
       var bitMask = (1 << bits) - 1;
       var j = 0, k = bufferLength;
       var columns = this.columns;
-      for (var i = 0; i < columns; ++i) {
+      for (i = 0; i < columns; ++i) {
         for (var kk = 0; kk < colors; ++kk) {
           if (inbits < bits) {
             inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
@@ -753,15 +758,15 @@ var PredictorStream = (function PredictorStreamClosure() {
       prevRow = new Uint8Array(rowBytes);
     }
 
-    var j = bufferLength;
+    var i, j = bufferLength, up, c;
     switch (predictor) {
       case 0:
-        for (var i = 0; i < rowBytes; ++i) {
+        for (i = 0; i < rowBytes; ++i) {
           buffer[j++] = rawBytes[i];
         }
         break;
       case 1:
-        for (var i = 0; i < pixBytes; ++i) {
+        for (i = 0; i < pixBytes; ++i) {
           buffer[j++] = rawBytes[i];
         }
         for (; i < rowBytes; ++i) {
@@ -770,12 +775,12 @@ var PredictorStream = (function PredictorStreamClosure() {
         }
         break;
       case 2:
-        for (var i = 0; i < rowBytes; ++i) {
+        for (i = 0; i < rowBytes; ++i) {
           buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
         }
         break;
       case 3:
-        for (var i = 0; i < pixBytes; ++i) {
+        for (i = 0; i < pixBytes; ++i) {
           buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
         }
         for (; i < rowBytes; ++i) {
@@ -787,13 +792,13 @@ var PredictorStream = (function PredictorStreamClosure() {
       case 4:
         // we need to save the up left pixels values. the simplest way
         // is to create a new buffer
-        for (var i = 0; i < pixBytes; ++i) {
-          var up = prevRow[i];
-          var c = rawBytes[i];
+        for (i = 0; i < pixBytes; ++i) {
+          up = prevRow[i];
+          c = rawBytes[i];
           buffer[j++] = up + c;
         }
         for (; i < rowBytes; ++i) {
-          var up = prevRow[i];
+          up = prevRow[i];
           var upLeft = prevRow[i - pixBytes];
           var left = buffer[j - pixBytes];
           var p = left + up - upLeft;
@@ -811,7 +816,7 @@ var PredictorStream = (function PredictorStreamClosure() {
             pc = -pc;
           }
 
-          var c = rawBytes[i];
+          c = rawBytes[i];
           if (pa <= pb && pa <= pc) {
             buffer[j++] = left + c;
           } else if (pb <= pc) {
@@ -951,6 +956,7 @@ var JpxStream = (function JpxStreamClosure() {
       var tileTop = tileCompoments[0].top;
 
       var dataPosition, sourcePosition, data0, data1, data2, data3, rowFeed;
+      var i, j;
       switch (componentsCount) {
         case 1:
           data0 = tileCompoments[0].items;
@@ -958,8 +964,8 @@ var JpxStream = (function JpxStreamClosure() {
           dataPosition = width * tileTop + tileLeft;
           rowFeed = width - tileWidth;
           sourcePosition = 0;
-          for (var j = 0; j < tileHeight; j++) {
-            for (var i = 0; i < tileWidth; i++) {
+          for (j = 0; j < tileHeight; j++) {
+            for (i = 0; i < tileWidth; i++) {
               data[dataPosition++] = data0[sourcePosition++];
             }
             dataPosition += rowFeed;
@@ -973,8 +979,8 @@ var JpxStream = (function JpxStreamClosure() {
           dataPosition = (width * tileTop + tileLeft) * 3;
           rowFeed = (width - tileWidth) * 3;
           sourcePosition = 0;
-          for (var j = 0; j < tileHeight; j++) {
-            for (var i = 0; i < tileWidth; i++) {
+          for (j = 0; j < tileHeight; j++) {
+            for (i = 0; i < tileWidth; i++) {
               data[dataPosition++] = data0[sourcePosition];
               data[dataPosition++] = data1[sourcePosition];
               data[dataPosition++] = data2[sourcePosition];
@@ -992,8 +998,8 @@ var JpxStream = (function JpxStreamClosure() {
           dataPosition = (width * tileTop + tileLeft) * 4;
           rowFeed = (width - tileWidth) * 4;
           sourcePosition = 0;
-          for (var j = 0; j < tileHeight; j++) {
-            for (var i = 0; i < tileWidth; i++) {
+          for (j = 0; j < tileHeight; j++) {
+            for (i = 0; i < tileWidth; i++) {
               data[dataPosition++] = data0[sourcePosition];
               data[dataPosition++] = data1[sourcePosition];
               data[dataPosition++] = data2[sourcePosition];
@@ -1156,18 +1162,19 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
     }
 
     var bufferLength = this.bufferLength, buffer;
+    var i;
 
     // special code for z
     if (c == Z_LOWER_CHAR) {
       buffer = this.ensureBuffer(bufferLength + 4);
-      for (var i = 0; i < 4; ++i) {
+      for (i = 0; i < 4; ++i) {
         buffer[bufferLength + i] = 0;
       }
       this.bufferLength += 4;
     } else {
       var input = this.input;
       input[0] = c;
-      for (var i = 1; i < 5; ++i) {
+      for (i = 1; i < 5; ++i) {
         c = str.getByte();
         while (Lexer.isSpace(c)) {
           c = str.getByte();
@@ -1190,11 +1197,11 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
         this.eof = true;
       }
       var t = 0;
-      for (var i = 0; i < 5; ++i) {
+      for (i = 0; i < 5; ++i) {
         t = t * 85 + (input[i] - 0x21);
       }
 
-      for (var i = 3; i >= 0; --i) {
+      for (i = 3; i >= 0; --i) {
         buffer[bufferLength + i] = t & 0xFF;
         t >>= 8;
       }
@@ -1287,11 +1294,12 @@ var RunLengthStream = (function RunLengthStreamClosure() {
       return;
     }
 
+    var buffer;
     var bufferLength = this.bufferLength;
     var n = repeatHeader[0];
     if (n < 128) {
       // copy n bytes
-      var buffer = this.ensureBuffer(bufferLength + n + 1);
+      buffer = this.ensureBuffer(bufferLength + n + 1);
       buffer[bufferLength++] = repeatHeader[1];
       if (n > 0) {
         var source = this.str.getBytes(n);
@@ -1301,7 +1309,7 @@ var RunLengthStream = (function RunLengthStreamClosure() {
     } else {
       n = 257 - n;
       var b = repeatHeader[1];
-      var buffer = this.ensureBuffer(bufferLength + n + 1);
+      buffer = this.ensureBuffer(bufferLength + n + 1);
       for (var i = 0; i < n; i++) {
         buffer[bufferLength++] = b;
       }
@@ -1851,7 +1859,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
     var codingLine = this.codingLine;
     var columns = this.columns;
 
-    var refPos, blackPixels, bits;
+    var refPos, blackPixels, bits, i;
 
     if (this.outputBits === 0) {
       if (this.eof) {
@@ -1861,7 +1869,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
 
       var code1, code2, code3;
       if (this.nextLine2D) {
-        for (var i = 0; codingLine[i] < columns; ++i) {
+        for (i = 0; codingLine[i] < columns; ++i) {
           refLine[i] = codingLine[i];
         }
         refLine[i++] = columns;
@@ -2063,7 +2071,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
             this.eatBits(1);
           }
           if (this.encoding >= 0) {
-            for (var i = 0; i < 4; ++i) {
+            for (i = 0; i < 4; ++i) {
               code1 = this.lookBits(12);
               if (code1 != 1) {
                 info('bad rtc code: ' + code1);
@@ -2114,7 +2122,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
                            codingLine[this.codingPos - 1]);
       }
     } else {
-      var bits = 8;
+      bits = 8;
       c = 0;
       do {
         if (this.outputBits > bits) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list