Use [].forEach instead of for-..-in in evaluator

To prevent errors whenever the array's prototype is extended.
 (cmap is an array)
This commit is contained in:
Rob Wu 2014-01-25 18:04:33 +01:00
parent 520fdf2f6a
commit 2779bab03e

View File

@ -909,8 +909,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} else if (isStream(cmapObj)) { } else if (isStream(cmapObj)) {
var cmap = CMapFactory.create(cmapObj).map; var cmap = CMapFactory.create(cmapObj).map;
// Convert UTF-16BE // Convert UTF-16BE
for (var i in cmap) { // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
var token = cmap[i]; // to iterate over all keys.
cmap.forEach(function(token, i) {
var str = []; var str = [];
for (var k = 0; k < token.length; k += 2) { for (var k = 0; k < token.length; k += 2) {
var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1); var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
@ -923,7 +924,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000); str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
} }
cmap[i] = String.fromCharCode.apply(String, str); cmap[i] = String.fromCharCode.apply(String, str);
} });
return cmap; return cmap;
} }
return charToUnicode; return charToUnicode;