Skip to content

Commit

Permalink
Fixes WeakMap polyfill (and improves PDFWorker port check).
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Jun 13, 2017
1 parent e5ac64f commit 631e6be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
8 changes: 6 additions & 2 deletions src/shared/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 631e6be

Please sign in to comment.