1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Add a getRawValues method, to Dict instances, to provide an easier way of getting all *raw* values

When the old `Dict.getAll()` method was removed, it was replaced with a `Dict.getKeys()` call and `Dict.get(...)` calls (in a loop).
While this pattern obviously makes a lot of sense in many cases, there's some instances where we actually want the *raw* `Dict` values (i.e. `Ref`s where applicable). In those cases, `Dict.getRaw(...)` calls are instead used within the loop. However, by introducing a new `Dict.getRawValues()` method we can reduce the number of (strictly unnecessary) function calls by simply getting the *raw* `Dict` values directly.
This commit is contained in:
Jonas Jenwald 2020-07-17 12:57:34 +02:00
parent 6381b5b08f
commit ea8e432c45
4 changed files with 39 additions and 12 deletions

View file

@ -275,6 +275,35 @@ describe("primitives", function () {
expect(keys.sort()).toEqual(expectedKeys);
});
it("should get all raw values", function () {
// Test direct objects:
const expectedRawValues1 = [testFontFile, testFontFile2, testFontFile3];
const rawValues1 = dictWithManyKeys.getRawValues();
expect(rawValues1.sort()).toEqual(expectedRawValues1);
// Test indirect objects:
const typeName = Name.get("Page");
const resources = new Dict(null),
resourcesRef = Ref.get(5, 0);
const contents = new StringStream("data"),
contentsRef = Ref.get(10, 0);
const xref = new XRefMock([
{ ref: resourcesRef, data: resources },
{ ref: contentsRef, data: contents },
]);
const dict = new Dict(xref);
dict.set("Type", typeName);
dict.set("Resources", resourcesRef);
dict.set("Contents", contentsRef);
const expectedRawValues2 = [contentsRef, resourcesRef, typeName];
const rawValues2 = dict.getRawValues();
expect(rawValues2.sort()).toEqual(expectedRawValues2);
});
it("should create only one object for Dict.empty", function () {
const firstDictEmpty = Dict.empty;
const secondDictEmpty = Dict.empty;