diff --git a/src/display/worker_options.js b/src/display/worker_options.js index 1e82a4f7e6191..e4bbb81a6ea45 100644 --- a/src/display/worker_options.js +++ b/src/display/worker_options.js @@ -13,21 +13,52 @@ * limitations under the License. */ -/** - * @typedef {Object} GlobalWorkerOptionsType - * @property {Worker | null} workerPort - Defines global port for worker - * process. Overrides the `workerSrc` option. - * @property {string} workerSrc - A string containing the path and filename - * of the worker file. - * - * NOTE: The `workerSrc` option should always be set, in order to prevent any - * issues when using the PDF.js library. - */ +class GlobalWorkerOptions { + static #port = null; + + static #src = ""; + + /** + * @type {Worker | null} + */ + static get workerPort() { + return this.#port; + } + + /** + * @param {Worker | null} workerPort - Defines global port for worker process. + * Overrides the `workerSrc` option. + */ + static set workerPort(val) { + if ( + !(typeof Worker !== "undefined" && val instanceof Worker) && + val !== null + ) { + throw new Error("Invalid `workerPort` type."); + } + this.#port = val; + } -/** @type {GlobalWorkerOptionsType} */ -const GlobalWorkerOptions = Object.create(null); + /** + * @type {string} + */ + static get workerSrc() { + return this.#src; + } -GlobalWorkerOptions.workerPort = null; -GlobalWorkerOptions.workerSrc = ""; + /** + * @param {string} workerSrc - A string containing the path and filename of + * the worker file. + * + * NOTE: The `workerSrc` option should always be set, in order to prevent + * any issues when using the PDF.js library. + */ + static set workerSrc(val) { + if (typeof val !== "string") { + throw new Error("Invalid `workerSrc` type."); + } + this.#src = val; + } +} export { GlobalWorkerOptions };