[api-minor] Replace all deprecated calls with throwing of actual Errors

All of these methods have been marked as `deprecated` in *three* releases now, and I'd thus like to (slowly) move towards complete removal.

However rather than just removing the methods right away, which would cause somewhat cryptic failures, this patch tries to implement a hopefully reasonable middle ground by throwing `Error`s with (essentially) the same information as the previous warnings.

While the previous `deprecated` messages could perhaps be seen as optional, with these changes API consumers will now be forced to actually migrate their code.
This commit is contained in:
Jonas Jenwald 2019-10-08 23:25:32 +02:00
parent 5191d10dbc
commit ea729ec55c

View File

@ -23,9 +23,8 @@ import {
unreachable, warn
} from '../shared/util';
import {
deprecated, DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer,
loadScript, PageViewport, releaseImageResources, RenderingCancelledException,
StatTimer
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, loadScript,
PageViewport, releaseImageResources, RenderingCancelledException, StatTimer
} from './display_utils';
import { FontFaceObject, FontLoader } from './font_loader';
import { apiCompatibilityParams } from './api_compatibility';
@ -467,6 +466,7 @@ const PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
}
/**
* Promise for document loading task completion.
* @return {Promise}
*/
get promise() {
@ -494,16 +494,11 @@ const PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
/**
* Registers callbacks to indicate the document loading completion.
*
* @param {function} onFulfilled The callback for the loading completion.
* @param {function} onRejected The callback for the loading failure.
* @return {Promise} A promise that is resolved after the onFulfilled or
* onRejected callback.
* @ignore
*/
then(onFulfilled, onRejected) {
deprecated('PDFDocumentLoadingTask.then method, ' +
'use the `promise` getter instead.');
return this.promise.then.apply(this.promise, arguments);
throw new Error('Removed API method: ' +
'PDFDocumentLoadingTask.then, use the `promise` getter instead.');
}
}
return PDFDocumentLoadingTask;
@ -964,10 +959,8 @@ class PDFPageProxy {
getViewport({ scale, rotation = this.rotate, dontFlip = false, } = {}) {
if ((typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC')) &&
(arguments.length > 1 || typeof arguments[0] === 'number')) {
deprecated('getViewport is called with obsolete arguments.');
scale = arguments[0];
rotation = typeof arguments[1] === 'number' ? arguments[1] : this.rotate;
dontFlip = typeof arguments[2] === 'boolean' ? arguments[2] : false;
throw new Error(
'PDFPageProxy.getViewport is called with obsolete arguments.');
}
return new PageViewport({
viewBox: this.view,
@ -2545,15 +2538,11 @@ class RenderTask {
/**
* Registers callbacks to indicate the rendering task completion.
*
* @param {function} onFulfilled The callback for the rendering completion.
* @param {function} onRejected The callback for the rendering failure.
* @return {Promise} A promise that is resolved after the onFulfilled or
* onRejected callback.
* @ignore
*/
then(onFulfilled, onRejected) {
deprecated('RenderTask.then method, use the `promise` getter instead.');
return this.promise.then.apply(this.promise, arguments);
throw new Error('Removed API method: ' +
'RenderTask.then, use the `promise` getter instead.');
}
}