@@ -898,7 +898,7 @@ class PDFPageProxy {
898
898
899
899
this . cleanupAfterRender = false ;
900
900
this . pendingCleanup = false ;
901
- this . intentStates = Object . create ( null ) ;
901
+ this . _intentStates = new Map ( ) ;
902
902
this . destroyed = false ;
903
903
}
904
904
@@ -1003,10 +1003,11 @@ class PDFPageProxy {
1003
1003
// this call to render.
1004
1004
this . pendingCleanup = false ;
1005
1005
1006
- if ( ! this . intentStates [ renderingIntent ] ) {
1007
- this . intentStates [ renderingIntent ] = Object . create ( null ) ;
1006
+ let intentState = this . _intentStates . get ( renderingIntent ) ;
1007
+ if ( ! intentState ) {
1008
+ intentState = Object . create ( null ) ;
1009
+ this . _intentStates . set ( renderingIntent , intentState ) ;
1008
1010
}
1009
- const intentState = this . intentStates [ renderingIntent ] ;
1010
1011
1011
1012
// Ensure that a pending `streamReader` cancel timeout is always aborted.
1012
1013
if ( intentState . streamReaderCancelTimeout ) {
@@ -1128,14 +1129,15 @@ class PDFPageProxy {
1128
1129
}
1129
1130
1130
1131
const renderingIntent = "oplist" ;
1131
- if ( ! this . intentStates [ renderingIntent ] ) {
1132
- this . intentStates [ renderingIntent ] = Object . create ( null ) ;
1132
+ let intentState = this . _intentStates . get ( renderingIntent ) ;
1133
+ if ( ! intentState ) {
1134
+ intentState = Object . create ( null ) ;
1135
+ this . _intentStates . set ( renderingIntent , intentState ) ;
1133
1136
}
1134
- const intentState = this . intentStates [ renderingIntent ] ;
1135
1137
let opListTask ;
1136
1138
1137
1139
if ( ! intentState . opListReadCapability ) {
1138
- opListTask = { } ;
1140
+ opListTask = Object . create ( null ) ;
1139
1141
opListTask . operatorListChanged = operatorListChanged ;
1140
1142
intentState . opListReadCapability = createPromiseCapability ( ) ;
1141
1143
intentState . renderTasks = [ ] ;
@@ -1222,8 +1224,7 @@ class PDFPageProxy {
1222
1224
this . _transport . pageCache [ this . _pageIndex ] = null ;
1223
1225
1224
1226
const waitOn = [ ] ;
1225
- Object . keys ( this . intentStates ) . forEach ( intent => {
1226
- const intentState = this . intentStates [ intent ] ;
1227
+ for ( const [ intent , intentState ] of this . _intentStates ) {
1227
1228
this . _abortOperatorList ( {
1228
1229
intentState,
1229
1230
reason : new Error ( "Page was destroyed." ) ,
@@ -1232,16 +1233,13 @@ class PDFPageProxy {
1232
1233
1233
1234
if ( intent === "oplist" ) {
1234
1235
// Avoid errors below, since the renderTasks are just stubs.
1235
- return ;
1236
+ continue ;
1236
1237
}
1237
- intentState . renderTasks . forEach ( function ( renderTask ) {
1238
- const renderCompleted = renderTask . capability . promise . catch (
1239
- function ( ) { }
1240
- ) ; // ignoring failures
1241
- waitOn . push ( renderCompleted ) ;
1242
- renderTask . cancel ( ) ;
1243
- } ) ;
1244
- } ) ;
1238
+ for ( const internalRenderTask of intentState . renderTasks ) {
1239
+ waitOn . push ( internalRenderTask . completed ) ;
1240
+ internalRenderTask . cancel ( ) ;
1241
+ }
1242
+ }
1245
1243
this . objs . clear ( ) ;
1246
1244
this . annotationsPromise = null ;
1247
1245
this . pendingCleanup = false ;
@@ -1264,22 +1262,16 @@ class PDFPageProxy {
1264
1262
* @private
1265
1263
*/
1266
1264
_tryCleanup ( resetStats = false ) {
1267
- if (
1268
- ! this . pendingCleanup ||
1269
- Object . keys ( this . intentStates ) . some ( intent => {
1270
- const intentState = this . intentStates [ intent ] ;
1271
- return (
1272
- intentState . renderTasks . length !== 0 ||
1273
- ! intentState . operatorList . lastChunk
1274
- ) ;
1275
- } )
1276
- ) {
1265
+ if ( ! this . pendingCleanup ) {
1277
1266
return false ;
1278
1267
}
1268
+ for ( const { renderTasks, operatorList } of this . _intentStates . values ( ) ) {
1269
+ if ( renderTasks . length !== 0 || ! operatorList . lastChunk ) {
1270
+ return false ;
1271
+ }
1272
+ }
1279
1273
1280
- Object . keys ( this . intentStates ) . forEach ( intent => {
1281
- delete this . intentStates [ intent ] ;
1282
- } ) ;
1274
+ this . _intentStates . clear ( ) ;
1283
1275
this . objs . clear ( ) ;
1284
1276
this . annotationsPromise = null ;
1285
1277
if ( resetStats && this . _stats ) {
@@ -1293,7 +1285,7 @@ class PDFPageProxy {
1293
1285
* @private
1294
1286
*/
1295
1287
_startRenderPage ( transparency , intent ) {
1296
- const intentState = this . intentStates [ intent ] ;
1288
+ const intentState = this . _intentStates . get ( intent ) ;
1297
1289
if ( ! intentState ) {
1298
1290
return ; // Rendering was cancelled.
1299
1291
}
@@ -1343,7 +1335,7 @@ class PDFPageProxy {
1343
1335
) ;
1344
1336
const reader = readableStream . getReader ( ) ;
1345
1337
1346
- const intentState = this . intentStates [ args . intent ] ;
1338
+ const intentState = this . _intentStates . get ( args . intent ) ;
1347
1339
intentState . streamReader = reader ;
1348
1340
1349
1341
const pump = ( ) => {
@@ -1428,13 +1420,12 @@ class PDFPageProxy {
1428
1420
}
1429
1421
// Remove the current `intentState`, since a cancelled `getOperatorList`
1430
1422
// call on the worker-thread cannot be re-started...
1431
- Object . keys ( this . intentStates ) . some ( intent => {
1432
- if ( this . intentStates [ intent ] === intentState ) {
1433
- delete this . intentStates [ intent ] ;
1434
- return true ;
1423
+ for ( const [ intent , curIntentState ] of this . _intentStates ) {
1424
+ if ( curIntentState === intentState ) {
1425
+ this . _intentStates . delete ( intent ) ;
1426
+ break ;
1435
1427
}
1436
- return false ;
1437
- } ) ;
1428
+ }
1438
1429
// ... and force clean-up to ensure that any old state is always removed.
1439
1430
this . cleanup ( ) ;
1440
1431
}
@@ -2650,6 +2641,13 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
2650
2641
this . _canvas = params . canvasContext . canvas ;
2651
2642
}
2652
2643
2644
+ get completed ( ) {
2645
+ return this . capability . promise . catch ( function ( ) {
2646
+ // Ignoring errors, since we only want to know when rendering is
2647
+ // no longer pending.
2648
+ } ) ;
2649
+ }
2650
+
2653
2651
initializeGraphics ( transparency = false ) {
2654
2652
if ( this . cancelled ) {
2655
2653
return ;
0 commit comments