Introduce (some) private properties/methods in the PDFObjects
class
This ensures that the underlying data cannot be accessed directly, from the outside, since that's definately not intended here. Note that we expose `PDFObjects`-instances, via the `commonObjs` and `objs` properties, on the `PDFPageProxy`-instances hence these changes really cannot hurt.
This commit is contained in:
parent
fbed707592
commit
beecde3229
@ -3049,19 +3049,17 @@ class WorkerTransport {
|
|||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
class PDFObjects {
|
class PDFObjects {
|
||||||
constructor() {
|
#objs = Object.create(null);
|
||||||
this._objs = Object.create(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures there is an object defined for `objId`.
|
* Ensures there is an object defined for `objId`.
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
_ensureObj(objId) {
|
#ensureObj(objId) {
|
||||||
if (this._objs[objId]) {
|
const obj = this.#objs[objId];
|
||||||
return this._objs[objId];
|
if (obj) {
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
return (this._objs[objId] = {
|
return (this.#objs[objId] = {
|
||||||
capability: createPromiseCapability(),
|
capability: createPromiseCapability(),
|
||||||
data: null,
|
data: null,
|
||||||
resolved: false,
|
resolved: false,
|
||||||
@ -3080,30 +3078,30 @@ 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);
|
this.#ensureObj(objId).capability.promise.then(callback);
|
||||||
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
|
||||||
// directly.
|
// directly.
|
||||||
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 || !obj.resolved) {
|
if (!obj?.resolved) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
has(objId) {
|
has(objId) {
|
||||||
const obj = this._objs[objId];
|
const obj = this.#objs[objId];
|
||||||
return obj?.resolved || false;
|
return obj?.resolved || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the object `objId` with optional `data`.
|
* Resolves the object `objId` with optional `data`.
|
||||||
*/
|
*/
|
||||||
resolve(objId, data) {
|
resolve(objId, data = null) {
|
||||||
const obj = this._ensureObj(objId);
|
const obj = this.#ensureObj(objId);
|
||||||
|
|
||||||
obj.resolved = true;
|
obj.resolved = true;
|
||||||
obj.data = data;
|
obj.data = data;
|
||||||
@ -3111,7 +3109,7 @@ class PDFObjects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this._objs = Object.create(null);
|
this.#objs = Object.create(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user