@@ -123,20 +123,19 @@ class WorkerMessageHandler {
123123 if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
124124 // Fail early, and predictably, rather than having (some) fonts fail to
125125 // load/render with slightly cryptic error messages in environments where
126- // the `Array.prototype` has been *incorrectly* extended.
126+ // the `{Object, Array} .prototype` has been *incorrectly* extended.
127127 //
128128 // PLEASE NOTE: We do *not* want to slow down font parsing by adding
129129 // `hasOwnProperty` checks all over the code-base.
130- const enumerableProperties = [ ] ;
131- for ( const property in [ ] ) {
132- enumerableProperties . push ( property ) ;
130+ const buildMsg = ( type , prop ) =>
131+ `The \`${ type } .prototype\` contains unexpected enumerable property ` +
132+ `"${ prop } ", thus breaking e.g. \`for...in\` iteration of ${ type } s.` ;
133+
134+ for ( const prop in { } ) {
135+ throw new Error ( buildMsg ( "Object" , prop ) ) ;
133136 }
134- if ( enumerableProperties . length ) {
135- throw new Error (
136- "The `Array.prototype` contains unexpected enumerable properties: " +
137- enumerableProperties . join ( ", " ) +
138- "; thus breaking e.g. `for...in` iteration of `Array`s."
139- ) ;
137+ for ( const prop in [ ] ) {
138+ throw new Error ( buildMsg ( "Array" , prop ) ) ;
140139 }
141140 }
142141 const workerHandlerName = docId + "_worker" ;
0 commit comments