[api-minor] Limit the PDFDocumentLoadingTask.onUnsupportedFeature functionality to GENERIC builds (PR 15758 follow-up)

This was deprecated in PR 15758 but it's unfortunately quite difficult to tell if third-party users are depending on this, e.g. to implement custom error reporting, and if so to what extent.
However, thanks to the pre-processor we can limit *most* of this code to GENERIC builds which still seem like a worthwhile change.

These changes reduce the bundle size of the Firefox PDF Viewer by 3.8 kB in total.
This commit is contained in:
Jonas Jenwald 2023-01-01 16:57:57 +01:00
parent 0c1fb4e740
commit 1a69d537c1
6 changed files with 159 additions and 105 deletions

View file

@ -609,10 +609,12 @@ class PDFDocumentLoadingTask {
* @type {function}
*/
set onUnsupportedFeature(callback) {
deprecated(
"The PDFDocumentLoadingTask onUnsupportedFeature property will be removed in the future."
);
this.#onUnsupportedFeature = callback;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
deprecated(
"The PDFDocumentLoadingTask onUnsupportedFeature property will be removed in the future."
);
this.#onUnsupportedFeature = callback;
}
}
/**
@ -2748,10 +2750,12 @@ class WorkerTransport {
});
});
messageHandler.on(
"UnsupportedFeature",
this._onUnsupportedFeature.bind(this)
);
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
messageHandler.on(
"UnsupportedFeature",
this._onUnsupportedFeature.bind(this)
);
}
messageHandler.on("FetchBuiltInCMap", data => {
if (this.destroyed) {
@ -2783,10 +2787,12 @@ class WorkerTransport {
}
_onUnsupportedFeature({ featureId }) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
}
this.loadingTask.onUnsupportedFeature?.(featureId);
}
this.loadingTask.onUnsupportedFeature?.(featureId);
}
getData() {