Merge pull request #9837 from timvandermeij/unreachable
Replace `NotImplementedException` with `unreachable`
This commit is contained in:
commit
646d81cd09
@ -14,216 +14,193 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
createPromiseCapability, createValidAbsoluteUrl, MissingDataException,
|
||||
NotImplementedException, shadow, unreachable, Util, warn
|
||||
createValidAbsoluteUrl, MissingDataException, shadow, unreachable, warn
|
||||
} from '../shared/util';
|
||||
import { ChunkedStreamManager } from './chunked_stream';
|
||||
import { PDFDocument } from './document';
|
||||
import { Stream } from './stream';
|
||||
|
||||
var BasePdfManager = (function BasePdfManagerClosure() {
|
||||
function BasePdfManager() {
|
||||
unreachable('Cannot initialize BaseManagerManager');
|
||||
class BasePdfManager {
|
||||
constructor() {
|
||||
if (this.constructor === BasePdfManager) {
|
||||
unreachable('Cannot initialize BasePdfManager.');
|
||||
}
|
||||
}
|
||||
|
||||
BasePdfManager.prototype = {
|
||||
get docId() {
|
||||
return this._docId;
|
||||
},
|
||||
get docId() {
|
||||
return this._docId;
|
||||
}
|
||||
|
||||
get password() {
|
||||
return this._password;
|
||||
},
|
||||
get password() {
|
||||
return this._password;
|
||||
}
|
||||
|
||||
get docBaseUrl() {
|
||||
var docBaseUrl = null;
|
||||
if (this._docBaseUrl) {
|
||||
var absoluteUrl = createValidAbsoluteUrl(this._docBaseUrl);
|
||||
if (absoluteUrl) {
|
||||
docBaseUrl = absoluteUrl.href;
|
||||
} else {
|
||||
warn('Invalid absolute docBaseUrl: "' + this._docBaseUrl + '".');
|
||||
}
|
||||
get docBaseUrl() {
|
||||
let docBaseUrl = null;
|
||||
if (this._docBaseUrl) {
|
||||
const absoluteUrl = createValidAbsoluteUrl(this._docBaseUrl);
|
||||
if (absoluteUrl) {
|
||||
docBaseUrl = absoluteUrl.href;
|
||||
} else {
|
||||
warn(`Invalid absolute docBaseUrl: "${this._docBaseUrl}".`);
|
||||
}
|
||||
return shadow(this, 'docBaseUrl', docBaseUrl);
|
||||
},
|
||||
}
|
||||
return shadow(this, 'docBaseUrl', docBaseUrl);
|
||||
}
|
||||
|
||||
onLoadedStream: function BasePdfManager_onLoadedStream() {
|
||||
throw new NotImplementedException();
|
||||
},
|
||||
onLoadedStream() {
|
||||
unreachable('Abstract method `onLoadedStream` called');
|
||||
}
|
||||
|
||||
ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
|
||||
return this.ensure(this.pdfDocument, prop, args);
|
||||
},
|
||||
ensureDoc(prop, args) {
|
||||
return this.ensure(this.pdfDocument, prop, args);
|
||||
}
|
||||
|
||||
ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
|
||||
return this.ensure(this.pdfDocument.xref, prop, args);
|
||||
},
|
||||
ensureXRef(prop, args) {
|
||||
return this.ensure(this.pdfDocument.xref, prop, args);
|
||||
}
|
||||
|
||||
ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
|
||||
return this.ensure(this.pdfDocument.catalog, prop, args);
|
||||
},
|
||||
ensureCatalog(prop, args) {
|
||||
return this.ensure(this.pdfDocument.catalog, prop, args);
|
||||
}
|
||||
|
||||
getPage: function BasePdfManager_getPage(pageIndex) {
|
||||
return this.pdfDocument.getPage(pageIndex);
|
||||
},
|
||||
getPage(pageIndex) {
|
||||
return this.pdfDocument.getPage(pageIndex);
|
||||
}
|
||||
|
||||
cleanup: function BasePdfManager_cleanup() {
|
||||
return this.pdfDocument.cleanup();
|
||||
},
|
||||
cleanup() {
|
||||
return this.pdfDocument.cleanup();
|
||||
}
|
||||
|
||||
ensure: function BasePdfManager_ensure(obj, prop, args) {
|
||||
return new NotImplementedException();
|
||||
},
|
||||
ensure(obj, prop, args) {
|
||||
unreachable('Abstract method `ensure` called');
|
||||
}
|
||||
|
||||
requestRange: function BasePdfManager_requestRange(begin, end) {
|
||||
return new NotImplementedException();
|
||||
},
|
||||
requestRange(begin, end) {
|
||||
unreachable('Abstract method `requestRange` called');
|
||||
}
|
||||
|
||||
requestLoadedStream: function BasePdfManager_requestLoadedStream() {
|
||||
return new NotImplementedException();
|
||||
},
|
||||
requestLoadedStream() {
|
||||
unreachable('Abstract method `requestLoadedStream` called');
|
||||
}
|
||||
|
||||
sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
|
||||
return new NotImplementedException();
|
||||
},
|
||||
sendProgressiveData(chunk) {
|
||||
unreachable('Abstract method `sendProgressiveData` called');
|
||||
}
|
||||
|
||||
updatePassword: function BasePdfManager_updatePassword(password) {
|
||||
this._password = password;
|
||||
},
|
||||
updatePassword(password) {
|
||||
this._password = password;
|
||||
}
|
||||
|
||||
terminate: function BasePdfManager_terminate() {
|
||||
return new NotImplementedException();
|
||||
},
|
||||
};
|
||||
terminate() {
|
||||
unreachable('Abstract method `terminate` called');
|
||||
}
|
||||
}
|
||||
|
||||
return BasePdfManager;
|
||||
})();
|
||||
class LocalPdfManager extends BasePdfManager {
|
||||
constructor(docId, data, password, evaluatorOptions, docBaseUrl) {
|
||||
super();
|
||||
|
||||
var LocalPdfManager = (function LocalPdfManagerClosure() {
|
||||
function LocalPdfManager(docId, data, password, evaluatorOptions,
|
||||
docBaseUrl) {
|
||||
this._docId = docId;
|
||||
this._password = password;
|
||||
this._docBaseUrl = docBaseUrl;
|
||||
this.evaluatorOptions = evaluatorOptions;
|
||||
var stream = new Stream(data);
|
||||
|
||||
const stream = new Stream(data);
|
||||
this.pdfDocument = new PDFDocument(this, stream);
|
||||
this._loadedStreamCapability = createPromiseCapability();
|
||||
this._loadedStreamCapability.resolve(stream);
|
||||
this._loadedStreamPromise = Promise.resolve(stream);
|
||||
}
|
||||
|
||||
Util.inherit(LocalPdfManager, BasePdfManager, {
|
||||
ensure: function LocalPdfManager_ensure(obj, prop, args) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var value = obj[prop];
|
||||
var result;
|
||||
if (typeof value === 'function') {
|
||||
result = value.apply(obj, args);
|
||||
} else {
|
||||
result = value;
|
||||
}
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
ensure(obj, prop, args) {
|
||||
return new Promise(function(resolve) {
|
||||
const value = obj[prop];
|
||||
if (typeof value === 'function') {
|
||||
resolve(value.apply(obj, args));
|
||||
} else {
|
||||
resolve(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
requestRange: function LocalPdfManager_requestRange(begin, end) {
|
||||
return Promise.resolve();
|
||||
},
|
||||
requestRange(begin, end) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
|
||||
return;
|
||||
},
|
||||
requestLoadedStream() {}
|
||||
|
||||
onLoadedStream: function LocalPdfManager_onLoadedStream() {
|
||||
return this._loadedStreamCapability.promise;
|
||||
},
|
||||
onLoadedStream() {
|
||||
return this._loadedStreamPromise;
|
||||
}
|
||||
|
||||
terminate: function LocalPdfManager_terminate() {
|
||||
return;
|
||||
},
|
||||
});
|
||||
terminate() {}
|
||||
}
|
||||
|
||||
return LocalPdfManager;
|
||||
})();
|
||||
class NetworkPdfManager extends BasePdfManager {
|
||||
constructor(docId, pdfNetworkStream, args, evaluatorOptions, docBaseUrl) {
|
||||
super();
|
||||
|
||||
var NetworkPdfManager = (function NetworkPdfManagerClosure() {
|
||||
function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions,
|
||||
docBaseUrl) {
|
||||
this._docId = docId;
|
||||
this._password = args.password;
|
||||
this._docBaseUrl = docBaseUrl;
|
||||
this.msgHandler = args.msgHandler;
|
||||
this.evaluatorOptions = evaluatorOptions;
|
||||
|
||||
var params = {
|
||||
this.streamManager = new ChunkedStreamManager(pdfNetworkStream, {
|
||||
msgHandler: args.msgHandler,
|
||||
url: args.url,
|
||||
length: args.length,
|
||||
disableAutoFetch: args.disableAutoFetch,
|
||||
rangeChunkSize: args.rangeChunkSize,
|
||||
};
|
||||
this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
|
||||
});
|
||||
this.pdfDocument = new PDFDocument(this, this.streamManager.getStream());
|
||||
}
|
||||
|
||||
Util.inherit(NetworkPdfManager, BasePdfManager, {
|
||||
ensure: function NetworkPdfManager_ensure(obj, prop, args) {
|
||||
var pdfManager = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
function ensureHelper() {
|
||||
try {
|
||||
var result;
|
||||
var value = obj[prop];
|
||||
if (typeof value === 'function') {
|
||||
result = value.apply(obj, args);
|
||||
} else {
|
||||
result = value;
|
||||
}
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
if (!(e instanceof MissingDataException)) {
|
||||
reject(e);
|
||||
return;
|
||||
}
|
||||
pdfManager.streamManager.requestRange(e.begin, e.end).
|
||||
then(ensureHelper, reject);
|
||||
ensure(obj, prop, args) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let ensureHelper = () => {
|
||||
try {
|
||||
const value = obj[prop];
|
||||
let result;
|
||||
if (typeof value === 'function') {
|
||||
result = value.apply(obj, args);
|
||||
} else {
|
||||
result = value;
|
||||
}
|
||||
resolve(result);
|
||||
} catch (ex) {
|
||||
if (!(ex instanceof MissingDataException)) {
|
||||
reject(ex);
|
||||
return;
|
||||
}
|
||||
this.streamManager.requestRange(ex.begin, ex.end)
|
||||
.then(ensureHelper, reject);
|
||||
}
|
||||
};
|
||||
|
||||
ensureHelper();
|
||||
});
|
||||
},
|
||||
ensureHelper();
|
||||
});
|
||||
}
|
||||
|
||||
requestRange: function NetworkPdfManager_requestRange(begin, end) {
|
||||
return this.streamManager.requestRange(begin, end);
|
||||
},
|
||||
requestRange(begin, end) {
|
||||
return this.streamManager.requestRange(begin, end);
|
||||
}
|
||||
|
||||
requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
|
||||
this.streamManager.requestAllChunks();
|
||||
},
|
||||
requestLoadedStream() {
|
||||
this.streamManager.requestAllChunks();
|
||||
}
|
||||
|
||||
sendProgressiveData:
|
||||
function NetworkPdfManager_sendProgressiveData(chunk) {
|
||||
this.streamManager.onReceiveData({ chunk, });
|
||||
},
|
||||
sendProgressiveData(chunk) {
|
||||
this.streamManager.onReceiveData({ chunk, });
|
||||
}
|
||||
|
||||
onLoadedStream: function NetworkPdfManager_onLoadedStream() {
|
||||
return this.streamManager.onLoadedStream();
|
||||
},
|
||||
onLoadedStream() {
|
||||
return this.streamManager.onLoadedStream();
|
||||
}
|
||||
|
||||
terminate: function NetworkPdfManager_terminate() {
|
||||
this.streamManager.abort();
|
||||
},
|
||||
});
|
||||
|
||||
return NetworkPdfManager;
|
||||
})();
|
||||
terminate() {
|
||||
this.streamManager.abort();
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
LocalPdfManager,
|
||||
|
@ -444,18 +444,6 @@ var UnexpectedResponseException =
|
||||
return UnexpectedResponseException;
|
||||
})();
|
||||
|
||||
var NotImplementedException = (function NotImplementedExceptionClosure() {
|
||||
function NotImplementedException(msg) {
|
||||
this.message = msg;
|
||||
}
|
||||
|
||||
NotImplementedException.prototype = new Error();
|
||||
NotImplementedException.prototype.name = 'NotImplementedException';
|
||||
NotImplementedException.constructor = NotImplementedException;
|
||||
|
||||
return NotImplementedException;
|
||||
})();
|
||||
|
||||
var MissingDataException = (function MissingDataExceptionClosure() {
|
||||
function MissingDataException(begin, end) {
|
||||
this.begin = begin;
|
||||
@ -1038,7 +1026,6 @@ export {
|
||||
MissingDataException,
|
||||
MissingPDFException,
|
||||
NativeImageDecoding,
|
||||
NotImplementedException,
|
||||
PasswordException,
|
||||
PasswordResponses,
|
||||
StreamType,
|
||||
|
Loading…
Reference in New Issue
Block a user