Merge pull request #8745 from yurydelendik/cancel-stream
Properly cancel streams and guard at getTextContent.
This commit is contained in:
commit
bbf5b4d706
@ -14,10 +14,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
assert, CMapCompressionType, createPromiseCapability, FONT_IDENTITY_MATRIX,
|
AbortException, assert, CMapCompressionType, createPromiseCapability,
|
||||||
FormatError, getLookupTableFactory, IDENTITY_MATRIX, ImageKind, info, isArray,
|
FONT_IDENTITY_MATRIX, FormatError, getLookupTableFactory, IDENTITY_MATRIX,
|
||||||
isNum, isString, NativeImageDecoding, OPS, TextRenderingMode,
|
ImageKind, info, isArray, isNum, isString, NativeImageDecoding, OPS,
|
||||||
UNSUPPORTED_FEATURES, Util, warn
|
TextRenderingMode, UNSUPPORTED_FEATURES, Util, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { CMapFactory, IdentityCMap } from './cmap';
|
import { CMapFactory, IdentityCMap } from './cmap';
|
||||||
import { DecodeStream, JpegStream, Stream } from './stream';
|
import { DecodeStream, JpegStream, Stream } from './stream';
|
||||||
@ -1744,6 +1744,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
enqueueChunk();
|
enqueueChunk();
|
||||||
resolve();
|
resolve();
|
||||||
}).catch((reason) => {
|
}).catch((reason) => {
|
||||||
|
if (reason instanceof AbortException) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.options.ignoreErrors) {
|
if (this.options.ignoreErrors) {
|
||||||
// Error(s) in the TextContent -- allow text-extraction to continue.
|
// Error(s) in the TextContent -- allow text-extraction to continue.
|
||||||
warn('getTextContent - ignoring errors during task: ' + task.name);
|
warn('getTextContent - ignoring errors during task: ' + task.name);
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createPromiseCapability, Util } from '../shared/util';
|
import { AbortException, createPromiseCapability, Util } from '../shared/util';
|
||||||
import { CustomStyle, getDefaultSetting } from './dom_utils';
|
import { CustomStyle, getDefaultSetting } from './dom_utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -498,7 +498,7 @@ var renderTextLayer = (function renderTextLayerClosure() {
|
|||||||
|
|
||||||
cancel: function TextLayer_cancel() {
|
cancel: function TextLayer_cancel() {
|
||||||
if (this._reader) {
|
if (this._reader) {
|
||||||
this._reader.cancel();
|
this._reader.cancel(new AbortException('text layer task cancelled'));
|
||||||
this._reader = null;
|
this._reader = null;
|
||||||
}
|
}
|
||||||
this._canceled = true;
|
this._canceled = true;
|
||||||
|
@ -500,6 +500,21 @@ let FormatError = (function FormatErrorClosure() {
|
|||||||
return FormatError;
|
return FormatError;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error used to indicate task cancellation.
|
||||||
|
*/
|
||||||
|
let AbortException = (function AbortExceptionClosure() {
|
||||||
|
function AbortException(msg) {
|
||||||
|
this.name = 'AbortException';
|
||||||
|
this.message = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
AbortException.prototype = new Error();
|
||||||
|
AbortException.constructor = AbortException;
|
||||||
|
|
||||||
|
return AbortException;
|
||||||
|
})();
|
||||||
|
|
||||||
var NullCharactersRegExp = /\x00/g;
|
var NullCharactersRegExp = /\x00/g;
|
||||||
|
|
||||||
function removeNullCharacters(str) {
|
function removeNullCharacters(str) {
|
||||||
@ -1227,6 +1242,8 @@ function wrapReason(reason) {
|
|||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
switch (reason.name) {
|
switch (reason.name) {
|
||||||
|
case 'AbortException':
|
||||||
|
return new AbortException(reason.message);
|
||||||
case 'MissingPDFException':
|
case 'MissingPDFException':
|
||||||
return new MissingPDFException(reason.message);
|
return new MissingPDFException(reason.message);
|
||||||
case 'UnexpectedResponseException':
|
case 'UnexpectedResponseException':
|
||||||
@ -1273,7 +1290,7 @@ function MessageHandler(sourceName, targetName, comObj) {
|
|||||||
let callback = callbacksCapabilities[callbackId];
|
let callback = callbacksCapabilities[callbackId];
|
||||||
delete callbacksCapabilities[callbackId];
|
delete callbacksCapabilities[callbackId];
|
||||||
if ('error' in data) {
|
if ('error' in data) {
|
||||||
callback.reject(data.error);
|
callback.reject(wrapReason(data.error));
|
||||||
} else {
|
} else {
|
||||||
callback.resolve(data.data);
|
callback.resolve(data.data);
|
||||||
}
|
}
|
||||||
@ -1651,6 +1668,7 @@ export {
|
|||||||
FontType,
|
FontType,
|
||||||
ImageKind,
|
ImageKind,
|
||||||
CMapCompressionType,
|
CMapCompressionType,
|
||||||
|
AbortException,
|
||||||
InvalidPDFException,
|
InvalidPDFException,
|
||||||
MessageHandler,
|
MessageHandler,
|
||||||
MissingDataException,
|
MissingDataException,
|
||||||
|
Loading…
Reference in New Issue
Block a user