Ensure that full clean-up is always run when handling the "Terminate" message in src/core/worker.js
This is beneficial in situations where the Worker is being re-used, for example with fake workers, since it ensures that things like font resources are actually released.
This commit is contained in:
parent
40f531ee87
commit
090ff116d4
@ -33,7 +33,14 @@ import {
|
|||||||
warn,
|
warn,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
import { Catalog, ObjectLoader, XRef } from "./obj.js";
|
import { Catalog, ObjectLoader, XRef } from "./obj.js";
|
||||||
import { Dict, isDict, isName, isStream, Ref } from "./primitives.js";
|
import {
|
||||||
|
clearPrimitiveCaches,
|
||||||
|
Dict,
|
||||||
|
isDict,
|
||||||
|
isName,
|
||||||
|
isStream,
|
||||||
|
Ref,
|
||||||
|
} from "./primitives.js";
|
||||||
import {
|
import {
|
||||||
getInheritableProperty,
|
getInheritableProperty,
|
||||||
MissingDataException,
|
MissingDataException,
|
||||||
@ -815,8 +822,8 @@ class PDFDocument {
|
|||||||
return this.catalog.fontFallback(id, handler);
|
return this.catalog.fontFallback(id, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
async cleanup() {
|
||||||
return this.catalog.cleanup();
|
return this.catalog ? this.catalog.cleanup() : clearPrimitiveCaches();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,16 +593,22 @@ var WorkerMessageHandler = {
|
|||||||
|
|
||||||
handler.on("Terminate", function wphTerminate(data) {
|
handler.on("Terminate", function wphTerminate(data) {
|
||||||
terminated = true;
|
terminated = true;
|
||||||
|
|
||||||
|
const waitOn = [];
|
||||||
if (pdfManager) {
|
if (pdfManager) {
|
||||||
pdfManager.terminate(new AbortException("Worker was terminated."));
|
pdfManager.terminate(new AbortException("Worker was terminated."));
|
||||||
|
|
||||||
|
const cleanupPromise = pdfManager.cleanup();
|
||||||
|
waitOn.push(cleanupPromise);
|
||||||
|
|
||||||
pdfManager = null;
|
pdfManager = null;
|
||||||
|
} else {
|
||||||
|
clearPrimitiveCaches();
|
||||||
}
|
}
|
||||||
if (cancelXHRs) {
|
if (cancelXHRs) {
|
||||||
cancelXHRs(new AbortException("Worker was terminated."));
|
cancelXHRs(new AbortException("Worker was terminated."));
|
||||||
}
|
}
|
||||||
clearPrimitiveCaches();
|
|
||||||
|
|
||||||
var waitOn = [];
|
|
||||||
WorkerTasks.forEach(function(task) {
|
WorkerTasks.forEach(function(task) {
|
||||||
waitOn.push(task.finished);
|
waitOn.push(task.finished);
|
||||||
task.terminate();
|
task.terminate();
|
||||||
|
Loading…
Reference in New Issue
Block a user