Skip to content

Commit 67eb3bb

Browse files
committed
Merge pull request mozilla#3239 from brendandahl/scope-fix
Bind chunk promises to avoid scope problems.
2 parents f07564b + 328cfd0 commit 67eb3bb

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/evaluator.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
884884
case 'TJ':
885885
var chunkPromise = new Promise();
886886
chunkPromises.push(chunkPromise);
887-
fontPromise.then(function(items, font) {
887+
fontPromise.then(function(items, chunkPromise, font) {
888888
var chunk = '';
889889
for (var j = 0, jj = items.length; j < jj; j++) {
890890
if (typeof items[j] === 'string') {
@@ -901,41 +901,40 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
901901
}
902902
}
903903
}
904-
905904
chunkPromise.resolve(
906905
getBidiText(chunk, -1, font.vertical));
907-
}.bind(null, args[0]));
906+
}.bind(null, args[0], chunkPromise));
908907
break;
909908
case 'Tj':
910909
var chunkPromise = new Promise();
911910
chunkPromises.push(chunkPromise);
912-
fontPromise.then(function(charCodes, font) {
911+
fontPromise.then(function(charCodes, chunkPromise, font) {
913912
var chunk = fontCharsToUnicode(charCodes, font);
914913
chunkPromise.resolve(
915914
getBidiText(chunk, -1, font.vertical));
916-
}.bind(null, args[0]));
915+
}.bind(null, args[0], chunkPromise));
917916
break;
918917
case '\'':
919918
// For search, adding a extra white space for line breaks
920919
// would be better here, but that causes too much spaces in
921920
// the text-selection divs.
922921
var chunkPromise = new Promise();
923922
chunkPromises.push(chunkPromise);
924-
fontPromise.then(function(charCodes, font) {
923+
fontPromise.then(function(charCodes, chunkPromise, font) {
925924
var chunk = fontCharsToUnicode(charCodes, font);
926925
chunkPromise.resolve(
927926
getBidiText(chunk, -1, font.vertical));
928-
}.bind(null, args[0]));
927+
}.bind(null, args[0], chunkPromise));
929928
break;
930929
case '"':
931930
// Note comment in "'"
932931
var chunkPromise = new Promise();
933932
chunkPromises.push(chunkPromise);
934-
fontPromise.then(function(charCodes, font) {
933+
fontPromise.then(function(charCodes, chunkPromise, font) {
935934
var chunk = fontCharsToUnicode(charCodes, font);
936935
chunkPromise.resolve(
937936
getBidiText(chunk, -1, font.vertical));
938-
}.bind(null, args[2]));
937+
}.bind(null, args[2], chunkPromise));
939938
break;
940939
case 'Do':
941940
if (args[0].code) {

0 commit comments

Comments
 (0)