mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Merge pull request #19828 from Snuffleupagus/worker-check-Object-prototype
Check that the `Object.prototype` hasn't been incorrectly extended (PR 11582 follow-up)
This commit is contained in:
commit
87a143dbbc
1 changed files with 9 additions and 10 deletions
|
@ -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";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue