mozilla/pdf.js — pull request #5234 by Snuffleupagus (2014-08-23 19:51:35+00:00)
Title: Add PDFJS.abortGetDocument function to enable cancelling of calls to PDFJS.getDocument

This PR contains a tentative patch for fixing #3485 (and should also fix #5228).

I was slightly unsure of the best way to handle the rejection of `workerReadyCapability`, since it's not easily available outside of `getDocument` and I didn't just want to expose it in `PDFJS`.
A caveat with this the patch is that it's only possible to abort the current `getDocument`, so if you have multiple ones active simultaneously this isn't going to work. Since this implementation should work fine when used in the generic viewer (e.g. for #5228), I don't know if it's really worth complicating the solution too much.

One other thing to note here: `abortGetDocument` really only makes sense when `getDocument` isn't resolved/rejected yet, since otherwise just calling `destroy` is enough.

When I started looking at this, I realized that our current exception handling code wasn't really working as intended (rejection with multiple arguments). The first commit fixes this, and I'd be happy to extract that into a separate PR if that's preferred.

@yurydelendik Please let me know if this PR heading in the right direction, or if you'd prefer a different/modified solution!