diff --git a/src/core/worker.js b/src/core/worker.js index 25dd08ee0..eb51bacfa 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -123,20 +123,19 @@ class WorkerMessageHandler { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { // Fail early, and predictably, rather than having (some) fonts fail to // load/render with slightly cryptic error messages in environments where - // the `Array.prototype` has been *incorrectly* extended. + // the `{Object, Array}.prototype` has been *incorrectly* extended. // // PLEASE NOTE: We do *not* want to slow down font parsing by adding // `hasOwnProperty` checks all over the code-base. - const enumerableProperties = []; - for (const property in []) { - enumerableProperties.push(property); + const buildMsg = (type, prop) => + `The \`${type}.prototype\` contains unexpected enumerable property ` + + `"${prop}", thus breaking e.g. \`for...in\` iteration of ${type}s.`; + + for (const prop in {}) { + throw new Error(buildMsg("Object", prop)); } - if (enumerableProperties.length) { - throw new Error( - "The `Array.prototype` contains unexpected enumerable properties: " + - enumerableProperties.join(", ") + - "; thus breaking e.g. `for...in` iteration of `Array`s." - ); + for (const prop in []) { + throw new Error(buildMsg("Array", prop)); } } const workerHandlerName = docId + "_worker";