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

View File

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

View File

@ -1628,33 +1628,8 @@ MessageHandler.prototype = {
} }
}, },
close(reason) { destroy() {
this.comObj.removeEventListener('message', this._onComObjOnMessage); 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);
}
}
}, },
}; };