Simplify the data stored on PDFObjects
-instances
The manually tracked `resolved`-property is no longer necessary, since the same information is now directly available on all `PromiseCapability`-instances. Furthermore, since the `PDFObjects.resolve` method is not documented as accepting e.g. only Object-data, we probably shouldn't resolve the `PromiseCapability` with the `data` and instead only store it on the `PDFObjects`-instance.[1] --- [1] While Objects are passed by reference in JavaScript, other primitives such as e.g. strings are passed by value and the current implementation *could* thus lead to increased memory usage. Given how we're using `PDFObjects` in the PDF.js code-base none of this should be an issue, but it still cannot hurt to change this.
This commit is contained in:
parent
beecde3229
commit
f4712bc0ad
@ -3062,7 +3062,6 @@ class PDFObjects {
|
|||||||
return (this.#objs[objId] = {
|
return (this.#objs[objId] = {
|
||||||
capability: createPromiseCapability(),
|
capability: createPromiseCapability(),
|
||||||
data: null,
|
data: null,
|
||||||
resolved: false,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3078,7 +3077,8 @@ class PDFObjects {
|
|||||||
// If there is a callback, then the get can be async and the object is
|
// If there is a callback, then the get can be async and the object is
|
||||||
// not required to be resolved right now.
|
// not required to be resolved right now.
|
||||||
if (callback) {
|
if (callback) {
|
||||||
this.#ensureObj(objId).capability.promise.then(callback);
|
const obj = this.#ensureObj(objId);
|
||||||
|
obj.capability.promise.then(() => callback(obj.data));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// If there isn't a callback, the user expects to get the resolved data
|
// If there isn't a callback, the user expects to get the resolved data
|
||||||
@ -3086,7 +3086,7 @@ class PDFObjects {
|
|||||||
const obj = this.#objs[objId];
|
const obj = this.#objs[objId];
|
||||||
// If there isn't an object yet or the object isn't resolved, then the
|
// If there isn't an object yet or the object isn't resolved, then the
|
||||||
// data isn't ready yet!
|
// data isn't ready yet!
|
||||||
if (!obj?.resolved) {
|
if (!obj?.capability.settled) {
|
||||||
throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
|
throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
|
||||||
}
|
}
|
||||||
return obj.data;
|
return obj.data;
|
||||||
@ -3094,7 +3094,7 @@ class PDFObjects {
|
|||||||
|
|
||||||
has(objId) {
|
has(objId) {
|
||||||
const obj = this.#objs[objId];
|
const obj = this.#objs[objId];
|
||||||
return obj?.resolved || false;
|
return obj?.capability.settled || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3102,10 +3102,8 @@ class PDFObjects {
|
|||||||
*/
|
*/
|
||||||
resolve(objId, data = null) {
|
resolve(objId, data = null) {
|
||||||
const obj = this.#ensureObj(objId);
|
const obj = this.#ensureObj(objId);
|
||||||
|
|
||||||
obj.resolved = true;
|
|
||||||
obj.data = data;
|
obj.data = data;
|
||||||
obj.capability.resolve(data);
|
obj.capability.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
|
Loading…
Reference in New Issue
Block a user