mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Small clean-up of the PDFDocumentProxy.destroy
method and related code
Note how `PDFDocumentProxy.destroy` is a nothing more than an alias for `PDFDocumentLoadingTask.destroy`. While removing the latter method would be a breaking API change, there's still room for at least some clean-up here. The main changes in this patch are: - Stop providing a `PDFDocumentLoadingTask` instance *separately* when creating a `PDFDocumentProxy`, since the loadingTask is already available through the `WorkerTransport` instance. - Stop tracking the `PDFDocumentProxy` instance on the `WorkerTransport`, since that property is completely unused. - Simplify the 'Multiple `getDocument` instances' unit-tests by only destroying *once*, rather than twice, for each document.
This commit is contained in:
parent
d587abbceb
commit
24fc4f83ca
2 changed files with 14 additions and 20 deletions
|
@ -574,9 +574,7 @@ class PDFDataRangeTransport {
|
|||
* properties that can be read synchronously.
|
||||
*/
|
||||
class PDFDocumentProxy {
|
||||
constructor(pdfInfo, transport, loadingTask) {
|
||||
this.loadingTask = loadingTask;
|
||||
|
||||
constructor(pdfInfo, transport) {
|
||||
this._pdfInfo = pdfInfo;
|
||||
this._transport = transport;
|
||||
}
|
||||
|
@ -761,6 +759,13 @@ class PDFDocumentProxy {
|
|||
get loadingParams() {
|
||||
return this._transport.loadingParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {PDFDocumentLoadingTask} The loadingTask for the current document.
|
||||
*/
|
||||
get loadingTask() {
|
||||
return this._transport.loadingTask;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1827,9 +1832,8 @@ class WorkerTransport {
|
|||
}, this);
|
||||
|
||||
messageHandler.on('GetDoc', function({ pdfInfo, }) {
|
||||
this.numPages = pdfInfo.numPages;
|
||||
this.pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
|
||||
loadingTask._capability.resolve(this.pdfDocument);
|
||||
this._numPages = pdfInfo.numPages;
|
||||
loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
|
||||
}, this);
|
||||
|
||||
messageHandler.on('PasswordRequest', function(exception) {
|
||||
|
@ -2130,7 +2134,7 @@ class WorkerTransport {
|
|||
|
||||
getPage(pageNumber) {
|
||||
if (!Number.isInteger(pageNumber) ||
|
||||
pageNumber <= 0 || pageNumber > this.numPages) {
|
||||
pageNumber <= 0 || pageNumber > this._numPages) {
|
||||
return Promise.reject(new Error('Invalid page request'));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue