[MessageHandler] Add a non-PRODUCTION/TESTING check to ensure that wrapReason is called with a valid reason

There shouldn't be any situation where `reason` isn't either an `Error`, or a cloned "Error" sent via `postMessage`.
This commit is contained in:
Jonas Jenwald 2019-10-06 14:07:53 +02:00
parent 9201c8dad4
commit eabedab38e

View File

@ -31,7 +31,13 @@ const StreamKind = {
};
function wrapReason(reason) {
if (typeof reason !== 'object') {
if (typeof PDFJSDev === 'undefined' ||
PDFJSDev.test('!PRODUCTION || TESTING')) {
assert(reason instanceof Error ||
(typeof reason === 'object' && reason !== null),
'wrapReason: Expected "reason" to be a (possibly cloned) Error.');
}
if (typeof reason !== 'object' || reason === null) {
return reason;
}
switch (reason.name) {