1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Add a isDestsEqual helper function, to allow comparing explicit destinations, in pdf_history.js

This commit is contained in:
Jonas Jenwald 2017-08-13 17:11:49 +02:00
parent 0c4985546a
commit 388851e37b
4 changed files with 84 additions and 0 deletions

View file

@ -30,6 +30,43 @@ class PDFHistory {
forward() {}
}
function isDestsEqual(firstDest, secondDest) {
function isEntryEqual(first, second) {
if (typeof first !== typeof second) {
return false;
}
if (first instanceof Array || second instanceof Array) {
return false;
}
if (first !== null && typeof first === 'object' && second !== null) {
if (Object.keys(first).length !== Object.keys(second).length) {
return false;
}
for (var key in first) {
if (!isEntryEqual(first[key], second[key])) {
return false;
}
}
return true;
}
return first === second || (Number.isNaN(first) && Number.isNaN(second));
}
if (!(firstDest instanceof Array && secondDest instanceof Array)) {
return false;
}
if (firstDest.length !== secondDest.length) {
return false;
}
for (let i = 0, ii = firstDest.length; i < ii; i++) {
if (!isEntryEqual(firstDest[i], secondDest[i])) {
return false;
}
}
return true;
}
export {
PDFHistory,
isDestsEqual,
};