From 631e6bebff553ce42c278cb7b670ab160207656a Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Tue, 13 Jun 2017 09:16:12 -0500 Subject: [PATCH] Fixes WeakMap polyfill (and improves PDFWorker port check). --- src/display/api.js | 2 +- src/shared/compatibility.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 729b6276487f2..e7757ddbb87b8 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1232,7 +1232,7 @@ var PDFWorker = (function PDFWorkerClosure() { let pdfWorkerPorts = new WeakMap(); function PDFWorker(name, port) { - if (pdfWorkerPorts.has(port)) { + if (port && pdfWorkerPorts.has(port)) { throw new Error('Cannot use more than one PDFWorker per port'); } diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js index 0af66a21e727d..67f332c7e6f8e 100644 --- a/src/shared/compatibility.js +++ b/src/shared/compatibility.js @@ -1176,10 +1176,14 @@ PDFJS.compatibilityChecked = true; } WeakMap.prototype = { has(obj) { + if ((typeof obj !== 'object' && typeof obj !== 'function') || + obj === null) { + return false; + } return !!Object.getOwnPropertyDescriptor(obj, this.id); }, - get(obj, defaultValue) { - return this.has(obj) ? obj[this.id] : defaultValue; + get(obj) { + return this.has(obj) ? obj[this.id] : undefined; }, set(obj, value) { Object.defineProperty(obj, this.id, {