Merge pull request #9002 from mozilla/revert-8971-close-handler

Revert "Closes all promises/streams when handler is destroyed."
This commit is contained in:
Brendan Dahl 2017-10-06 10:26:24 -07:00 committed by GitHub
commit ec46967360
3 changed files with 15 additions and 41 deletions

View File

@ -14,11 +14,10 @@
*/
import {
AbortException, arrayByteLength, arraysToBytes, assert,
createPromiseCapability, info, InvalidPDFException, isNodeJS, MessageHandler,
MissingPDFException, PasswordException, setVerbosityLevel,
UnexpectedResponseException, UnknownErrorException, UNSUPPORTED_FEATURES,
warn, XRefParseException
arrayByteLength, arraysToBytes, assert, createPromiseCapability, info,
InvalidPDFException, isNodeJS, MessageHandler, MissingPDFException,
PasswordException, setVerbosityLevel, UnexpectedResponseException,
UnknownErrorException, UNSUPPORTED_FEATURES, warn, XRefParseException
} from '../shared/util';
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
import { Ref } from './primitives';
@ -842,7 +841,7 @@ var WorkerMessageHandler = {
return Promise.all(waitOn).then(function () {
// Notice that even if we destroying handler, resolved response promise
// must be sent back.
handler.close(new AbortException('Worker was terminated'));
handler.destroy();
handler = null;
});
});

View File

@ -15,11 +15,11 @@
/* globals requirejs, __non_webpack_require__ */
import {
AbortException, assert, createPromiseCapability, deprecated,
getVerbosityLevel, info, InvalidPDFException, isArrayBuffer, isSameOrigin,
loadJpegStream, MessageHandler, MissingPDFException, NativeImageDecoding,
PageViewport, PasswordException, StatTimer, stringToBytes,
UnexpectedResponseException, UnknownErrorException, Util, warn
assert, createPromiseCapability, deprecated, getVerbosityLevel, info,
InvalidPDFException, isArrayBuffer, isSameOrigin, loadJpegStream,
MessageHandler, MissingPDFException, NativeImageDecoding, PageViewport,
PasswordException, StatTimer, stringToBytes, UnexpectedResponseException,
UnknownErrorException, Util, warn
} from '../shared/util';
import {
DOMCanvasFactory, DOMCMapReaderFactory, getDefaultSetting,
@ -1382,7 +1382,7 @@ var PDFWorker = (function PDFWorkerClosure() {
var messageHandler = new MessageHandler('main', 'worker', worker);
var terminateEarly = () => {
worker.removeEventListener('error', onWorkerError);
messageHandler.close(new Error('Worker was terminated'));
messageHandler.destroy();
worker.terminate();
if (this.destroyed) {
this._readyCapability.reject(new Error('Worker was destroyed'));
@ -1424,7 +1424,7 @@ var PDFWorker = (function PDFWorkerClosure() {
});
} else {
this._setupFakeWorker();
messageHandler.close(new Error('Worker was terminated'));
messageHandler.destroy();
worker.terminate();
}
});
@ -1527,7 +1527,7 @@ var PDFWorker = (function PDFWorkerClosure() {
pdfWorkerPorts.delete(this._port);
this._port = null;
if (this._messageHandler) {
this._messageHandler.close(new AbortException('Worker was destroyed'));
this._messageHandler.destroy();
this._messageHandler = null;
}
},
@ -1607,7 +1607,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
}
if (this.messageHandler) {
this.messageHandler.close(new AbortException('Worker was destroyed'));
this.messageHandler.destroy();
this.messageHandler = null;
}
this.destroyCapability.resolve();

View File

@ -1628,33 +1628,8 @@ MessageHandler.prototype = {
}
},
close(reason) {
destroy() {
this.comObj.removeEventListener('message', this._onComObjOnMessage);
// Reject all promises and streams.
for (let i in this.callbacksCapabilities) {
const callbackCapability = this.callbacksCapabilities[i];
callbackCapability.reject(reason);
}
for (let i in this.streamSinks) {
const sink = this.streamSinks[i];
sink.sinkCapability.reject(reason);
}
for (let i in this.streamControllers) {
const controller = this.streamControllers[i];
if (!controller.isClosed) {
controller.controller.error(reason);
}
if (controller.startCall) {
controller.startCall.reject(reason);
}
if (controller.pullCall) {
controller.pullCall.reject(reason);
}
if (controller.cancelCall) {
controller.cancelCall.reject(reason);
}
}
},
};