Merge pull request #12017 from Snuffleupagus/api-intentStates-Map
Convert the `PDFPageProxy.intentStates` property from an `Object` to a `Map`
This commit is contained in:
commit
3c81b5e26e
@ -591,7 +591,7 @@ class ChunkedStreamManager {
|
|||||||
if (this.pdfNetworkStream) {
|
if (this.pdfNetworkStream) {
|
||||||
this.pdfNetworkStream.cancelAllRequests(reason);
|
this.pdfNetworkStream.cancelAllRequests(reason);
|
||||||
}
|
}
|
||||||
for (const [, capability] of this._promisesByRequest) {
|
for (const capability of this._promisesByRequest.values()) {
|
||||||
capability.reject(reason);
|
capability.reject(reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -898,7 +898,7 @@ class PDFPageProxy {
|
|||||||
|
|
||||||
this.cleanupAfterRender = false;
|
this.cleanupAfterRender = false;
|
||||||
this.pendingCleanup = false;
|
this.pendingCleanup = false;
|
||||||
this.intentStates = Object.create(null);
|
this._intentStates = new Map();
|
||||||
this.destroyed = false;
|
this.destroyed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1003,10 +1003,11 @@ class PDFPageProxy {
|
|||||||
// this call to render.
|
// this call to render.
|
||||||
this.pendingCleanup = false;
|
this.pendingCleanup = false;
|
||||||
|
|
||||||
if (!this.intentStates[renderingIntent]) {
|
let intentState = this._intentStates.get(renderingIntent);
|
||||||
this.intentStates[renderingIntent] = Object.create(null);
|
if (!intentState) {
|
||||||
|
intentState = Object.create(null);
|
||||||
|
this._intentStates.set(renderingIntent, intentState);
|
||||||
}
|
}
|
||||||
const intentState = this.intentStates[renderingIntent];
|
|
||||||
|
|
||||||
// Ensure that a pending `streamReader` cancel timeout is always aborted.
|
// Ensure that a pending `streamReader` cancel timeout is always aborted.
|
||||||
if (intentState.streamReaderCancelTimeout) {
|
if (intentState.streamReaderCancelTimeout) {
|
||||||
@ -1128,14 +1129,15 @@ class PDFPageProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const renderingIntent = "oplist";
|
const renderingIntent = "oplist";
|
||||||
if (!this.intentStates[renderingIntent]) {
|
let intentState = this._intentStates.get(renderingIntent);
|
||||||
this.intentStates[renderingIntent] = Object.create(null);
|
if (!intentState) {
|
||||||
|
intentState = Object.create(null);
|
||||||
|
this._intentStates.set(renderingIntent, intentState);
|
||||||
}
|
}
|
||||||
const intentState = this.intentStates[renderingIntent];
|
|
||||||
let opListTask;
|
let opListTask;
|
||||||
|
|
||||||
if (!intentState.opListReadCapability) {
|
if (!intentState.opListReadCapability) {
|
||||||
opListTask = {};
|
opListTask = Object.create(null);
|
||||||
opListTask.operatorListChanged = operatorListChanged;
|
opListTask.operatorListChanged = operatorListChanged;
|
||||||
intentState.opListReadCapability = createPromiseCapability();
|
intentState.opListReadCapability = createPromiseCapability();
|
||||||
intentState.renderTasks = [];
|
intentState.renderTasks = [];
|
||||||
@ -1222,8 +1224,7 @@ class PDFPageProxy {
|
|||||||
this._transport.pageCache[this._pageIndex] = null;
|
this._transport.pageCache[this._pageIndex] = null;
|
||||||
|
|
||||||
const waitOn = [];
|
const waitOn = [];
|
||||||
Object.keys(this.intentStates).forEach(intent => {
|
for (const [intent, intentState] of this._intentStates) {
|
||||||
const intentState = this.intentStates[intent];
|
|
||||||
this._abortOperatorList({
|
this._abortOperatorList({
|
||||||
intentState,
|
intentState,
|
||||||
reason: new Error("Page was destroyed."),
|
reason: new Error("Page was destroyed."),
|
||||||
@ -1232,16 +1233,13 @@ class PDFPageProxy {
|
|||||||
|
|
||||||
if (intent === "oplist") {
|
if (intent === "oplist") {
|
||||||
// Avoid errors below, since the renderTasks are just stubs.
|
// Avoid errors below, since the renderTasks are just stubs.
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
intentState.renderTasks.forEach(function (renderTask) {
|
for (const internalRenderTask of intentState.renderTasks) {
|
||||||
const renderCompleted = renderTask.capability.promise.catch(
|
waitOn.push(internalRenderTask.completed);
|
||||||
function () {}
|
internalRenderTask.cancel();
|
||||||
); // ignoring failures
|
}
|
||||||
waitOn.push(renderCompleted);
|
}
|
||||||
renderTask.cancel();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this.objs.clear();
|
this.objs.clear();
|
||||||
this.annotationsPromise = null;
|
this.annotationsPromise = null;
|
||||||
this.pendingCleanup = false;
|
this.pendingCleanup = false;
|
||||||
@ -1264,22 +1262,16 @@ class PDFPageProxy {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_tryCleanup(resetStats = false) {
|
_tryCleanup(resetStats = false) {
|
||||||
if (
|
if (!this.pendingCleanup) {
|
||||||
!this.pendingCleanup ||
|
|
||||||
Object.keys(this.intentStates).some(intent => {
|
|
||||||
const intentState = this.intentStates[intent];
|
|
||||||
return (
|
|
||||||
intentState.renderTasks.length !== 0 ||
|
|
||||||
!intentState.operatorList.lastChunk
|
|
||||||
);
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
for (const { renderTasks, operatorList } of this._intentStates.values()) {
|
||||||
|
if (renderTasks.length !== 0 || !operatorList.lastChunk) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Object.keys(this.intentStates).forEach(intent => {
|
this._intentStates.clear();
|
||||||
delete this.intentStates[intent];
|
|
||||||
});
|
|
||||||
this.objs.clear();
|
this.objs.clear();
|
||||||
this.annotationsPromise = null;
|
this.annotationsPromise = null;
|
||||||
if (resetStats && this._stats) {
|
if (resetStats && this._stats) {
|
||||||
@ -1293,7 +1285,7 @@ class PDFPageProxy {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_startRenderPage(transparency, intent) {
|
_startRenderPage(transparency, intent) {
|
||||||
const intentState = this.intentStates[intent];
|
const intentState = this._intentStates.get(intent);
|
||||||
if (!intentState) {
|
if (!intentState) {
|
||||||
return; // Rendering was cancelled.
|
return; // Rendering was cancelled.
|
||||||
}
|
}
|
||||||
@ -1343,7 +1335,7 @@ class PDFPageProxy {
|
|||||||
);
|
);
|
||||||
const reader = readableStream.getReader();
|
const reader = readableStream.getReader();
|
||||||
|
|
||||||
const intentState = this.intentStates[args.intent];
|
const intentState = this._intentStates.get(args.intent);
|
||||||
intentState.streamReader = reader;
|
intentState.streamReader = reader;
|
||||||
|
|
||||||
const pump = () => {
|
const pump = () => {
|
||||||
@ -1428,13 +1420,12 @@ class PDFPageProxy {
|
|||||||
}
|
}
|
||||||
// Remove the current `intentState`, since a cancelled `getOperatorList`
|
// Remove the current `intentState`, since a cancelled `getOperatorList`
|
||||||
// call on the worker-thread cannot be re-started...
|
// call on the worker-thread cannot be re-started...
|
||||||
Object.keys(this.intentStates).some(intent => {
|
for (const [intent, curIntentState] of this._intentStates) {
|
||||||
if (this.intentStates[intent] === intentState) {
|
if (curIntentState === intentState) {
|
||||||
delete this.intentStates[intent];
|
this._intentStates.delete(intent);
|
||||||
return true;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
});
|
|
||||||
// ... and force clean-up to ensure that any old state is always removed.
|
// ... and force clean-up to ensure that any old state is always removed.
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
}
|
}
|
||||||
@ -2650,6 +2641,13 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||||||
this._canvas = params.canvasContext.canvas;
|
this._canvas = params.canvasContext.canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get completed() {
|
||||||
|
return this.capability.promise.catch(function () {
|
||||||
|
// Ignoring errors, since we only want to know when rendering is
|
||||||
|
// no longer pending.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
initializeGraphics(transparency = false) {
|
initializeGraphics(transparency = false) {
|
||||||
if (this.cancelled) {
|
if (this.cancelled) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user