Skip to content

Commit 4d0709c

Browse files
Merge pull request #20795 from Snuffleupagus/Dict-more-iterators
Change the `Dict.prototype.{getKeys, getRawValues}` methods to return iterators
2 parents 7384359 + 229e364 commit 4d0709c

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/core/annotation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3398,7 +3398,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
33983398
? this.data.fieldValue
33993399
: "Yes";
34003400

3401-
const exportValues = this._decodeFormValue(normalAppearance.getKeys());
3401+
const exportValues = this._decodeFormValue([...normalAppearance.getKeys()]);
34023402
if (exportValues.length === 0) {
34033403
exportValues.push("Off", yes);
34043404
} else if (exportValues.length === 1) {

src/core/primitives.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ class Dict {
180180
}
181181

182182
getKeys() {
183-
return [...this._map.keys()];
183+
return this._map.keys();
184184
}
185185

186186
// No dereferencing.
187187
getRawValues() {
188-
return [...this._map.values()];
188+
return this._map.values();
189189
}
190190

191191
getRawEntries() {

test/unit/primitives_spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,15 @@ describe("primitives", function () {
276276

277277
it("should get all key names", function () {
278278
const expectedKeys = ["FontFile", "FontFile2", "FontFile3"];
279-
const keys = dictWithManyKeys.getKeys();
279+
const keys = [...dictWithManyKeys.getKeys()];
280280

281281
expect(keys.sort()).toEqual(expectedKeys);
282282
});
283283

284284
it("should get all raw values", function () {
285285
// Test direct objects:
286286
const expectedRawValues1 = [testFontFile, testFontFile2, testFontFile3];
287-
const rawValues1 = dictWithManyKeys.getRawValues();
287+
const rawValues1 = [...dictWithManyKeys.getRawValues()];
288288

289289
expect(rawValues1.sort()).toEqual(expectedRawValues1);
290290

@@ -305,7 +305,7 @@ describe("primitives", function () {
305305
dict.set("Contents", contentsRef);
306306

307307
const expectedRawValues2 = [contentsRef, resourcesRef, typeName];
308-
const rawValues2 = dict.getRawValues();
308+
const rawValues2 = [...dict.getRawValues()];
309309

310310
expect(rawValues2.sort()).toEqual(expectedRawValues2);
311311
});
@@ -337,7 +337,7 @@ describe("primitives", function () {
337337
xref: null,
338338
dictArray: [dictWithManyKeys, dictWithSizeKey, fontFileDict],
339339
});
340-
const mergedKeys = mergedDict.getKeys();
340+
const mergedKeys = [...mergedDict.getKeys()];
341341

342342
expect(mergedKeys.sort()).toEqual(expectedKeys);
343343
expect(mergedDict.get("FontFile")).toEqual(testFontFile);
@@ -374,14 +374,14 @@ describe("primitives", function () {
374374
expect(mergedFontDict instanceof Dict).toEqual(true);
375375
expect(mergedSubFontDict instanceof Dict).toEqual(true);
376376

377-
const mergedFontDictKeys = mergedFontDict.getKeys();
378-
const mergedSubFontDictKeys = mergedSubFontDict.getKeys();
377+
const mergedFontDictKeys = [...mergedFontDict.getKeys()];
378+
const mergedSubFontDictKeys = [...mergedSubFontDict.getKeys()];
379379

380380
expect(mergedFontDictKeys).toEqual(["F1"]);
381381
expect(mergedSubFontDictKeys).toEqual(["F1", "F2", "F3"]);
382382

383-
const mergedFontDictValues = mergedFontDict.getRawValues();
384-
const mergedSubFontDictValues = mergedSubFontDict.getRawValues();
383+
const mergedFontDictValues = [...mergedFontDict.getRawValues()];
384+
const mergedSubFontDictValues = [...mergedSubFontDict.getRawValues()];
385385

386386
expect(mergedFontDictValues).toEqual(["Local font one"]);
387387
expect(mergedSubFontDictValues).toEqual([

0 commit comments

Comments
 (0)