@@ -69,7 +69,7 @@ const nonSerializable = function nonSerializableClosure() {
69
69
class Dict {
70
70
constructor ( xref = null ) {
71
71
// Map should only be used internally, use functions below to access.
72
- this . _map = Object . create ( null ) ;
72
+ this . _map = new Map ( ) ;
73
73
this . xref = xref ;
74
74
this . objId = null ;
75
75
this . suppressEncryption = false ;
@@ -81,28 +81,28 @@ class Dict {
81
81
}
82
82
83
83
get size ( ) {
84
- return Object . keys ( this . _map ) . length ;
84
+ return this . _map . size ;
85
85
}
86
86
87
87
// Automatically dereferences Ref objects.
88
88
get ( key1 , key2 , key3 ) {
89
- let value = this . _map [ key1 ] ;
89
+ let value = this . _map . get ( key1 ) ;
90
90
if ( value === undefined && key2 !== undefined ) {
91
91
if (
92
92
( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) &&
93
93
key2 . length < key1 . length
94
94
) {
95
95
unreachable ( "Dict.get: Expected keys to be ordered by length." ) ;
96
96
}
97
- value = this . _map [ key2 ] ;
97
+ value = this . _map . get ( key2 ) ;
98
98
if ( value === undefined && key3 !== undefined ) {
99
99
if (
100
100
( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) &&
101
101
key3 . length < key2 . length
102
102
) {
103
103
unreachable ( "Dict.get: Expected keys to be ordered by length." ) ;
104
104
}
105
- value = this . _map [ key3 ] ;
105
+ value = this . _map . get ( key3 ) ;
106
106
}
107
107
}
108
108
if ( value instanceof Ref && this . xref ) {
@@ -113,23 +113,23 @@ class Dict {
113
113
114
114
// Same as get(), but returns a promise and uses fetchIfRefAsync().
115
115
async getAsync ( key1 , key2 , key3 ) {
116
- let value = this . _map [ key1 ] ;
116
+ let value = this . _map . get ( key1 ) ;
117
117
if ( value === undefined && key2 !== undefined ) {
118
118
if (
119
119
( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) &&
120
120
key2 . length < key1 . length
121
121
) {
122
122
unreachable ( "Dict.getAsync: Expected keys to be ordered by length." ) ;
123
123
}
124
- value = this . _map [ key2 ] ;
124
+ value = this . _map . get ( key2 ) ;
125
125
if ( value === undefined && key3 !== undefined ) {
126
126
if (
127
127
( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) &&
128
128
key3 . length < key2 . length
129
129
) {
130
130
unreachable ( "Dict.getAsync: Expected keys to be ordered by length." ) ;
131
131
}
132
- value = this . _map [ key3 ] ;
132
+ value = this . _map . get ( key3 ) ;
133
133
}
134
134
}
135
135
if ( value instanceof Ref && this . xref ) {
@@ -140,23 +140,23 @@ class Dict {
140
140
141
141
// Same as get(), but dereferences all elements if the result is an Array.
142
142
getArray ( key1 , key2 , key3 ) {
143
- let value = this . _map [ key1 ] ;
143
+ let value = this . _map . get ( key1 ) ;
144
144
if ( value === undefined && key2 !== undefined ) {
145
145
if (
146
146
( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) &&
147
147
key2 . length < key1 . length
148
148
) {
149
149
unreachable ( "Dict.getArray: Expected keys to be ordered by length." ) ;
150
150
}
151
- value = this . _map [ key2 ] ;
151
+ value = this . _map . get ( key2 ) ;
152
152
if ( value === undefined && key3 !== undefined ) {
153
153
if (
154
154
( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) &&
155
155
key3 . length < key2 . length
156
156
) {
157
157
unreachable ( "Dict.getArray: Expected keys to be ordered by length." ) ;
158
158
}
159
- value = this . _map [ key3 ] ;
159
+ value = this . _map . get ( key3 ) ;
160
160
}
161
161
}
162
162
if ( value instanceof Ref && this . xref ) {
@@ -176,16 +176,16 @@ class Dict {
176
176
177
177
// No dereferencing.
178
178
getRaw ( key ) {
179
- return this . _map [ key ] ;
179
+ return this . _map . get ( key ) ;
180
180
}
181
181
182
182
getKeys ( ) {
183
- return Object . keys ( this . _map ) ;
183
+ return [ ... this . _map . keys ( ) ] ;
184
184
}
185
185
186
186
// No dereferencing.
187
187
getRawValues ( ) {
188
- return Object . values ( this . _map ) ;
188
+ return [ ... this . _map . values ( ) ] ;
189
189
}
190
190
191
191
set ( key , value ) {
@@ -196,16 +196,21 @@ class Dict {
196
196
unreachable ( 'Dict.set: The "value" cannot be undefined.' ) ;
197
197
}
198
198
}
199
- this . _map [ key ] = value ;
199
+ this . _map . set ( key , value ) ;
200
200
}
201
201
202
202
has ( key ) {
203
- return this . _map [ key ] !== undefined ;
203
+ return this . _map . has ( key ) ;
204
204
}
205
205
206
- forEach ( callback ) {
207
- for ( const key in this . _map ) {
208
- callback ( key , this . get ( key ) ) ;
206
+ * [ Symbol . iterator ] ( ) {
207
+ for ( const [ key , value ] of this . _map ) {
208
+ yield [
209
+ key ,
210
+ value instanceof Ref && this . xref
211
+ ? this . xref . fetch ( value , this . suppressEncryption )
212
+ : value ,
213
+ ] ;
209
214
}
210
215
}
211
216
@@ -226,7 +231,7 @@ class Dict {
226
231
if ( ! ( dict instanceof Dict ) ) {
227
232
continue ;
228
233
}
229
- for ( const [ key , value ] of Object . entries ( dict . _map ) ) {
234
+ for ( const [ key , value ] of dict . _map ) {
230
235
let property = properties . get ( key ) ;
231
236
if ( property === undefined ) {
232
237
property = [ ] ;
@@ -242,20 +247,20 @@ class Dict {
242
247
}
243
248
for ( const [ name , values ] of properties ) {
244
249
if ( values . length === 1 || ! ( values [ 0 ] instanceof Dict ) ) {
245
- mergedDict . _map [ name ] = values [ 0 ] ;
250
+ mergedDict . _map . set ( name , values [ 0 ] ) ;
246
251
continue ;
247
252
}
248
253
const subDict = new Dict ( xref ) ;
249
254
250
255
for ( const dict of values ) {
251
- for ( const [ key , value ] of Object . entries ( dict . _map ) ) {
252
- if ( subDict . _map [ key ] === undefined ) {
253
- subDict . _map [ key ] = value ;
256
+ for ( const [ key , value ] of dict . _map ) {
257
+ if ( ! subDict . _map . has ( key ) ) {
258
+ subDict . _map . set ( key , value ) ;
254
259
}
255
260
}
256
261
}
257
262
if ( subDict . size > 0 ) {
258
- mergedDict . _map [ name ] = subDict ;
263
+ mergedDict . _map . set ( name , subDict ) ;
259
264
}
260
265
}
261
266
properties . clear ( ) ;
0 commit comments