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