@@ -514,9 +514,8 @@ class Catalog {
514
514
const obj = this . _readDests ( ) ,
515
515
dests = Object . create ( null ) ;
516
516
if ( obj instanceof NameTree ) {
517
- const names = obj . getAll ( ) ;
518
- for ( const name in names ) {
519
- dests [ name ] = fetchDestination ( names [ name ] ) ;
517
+ for ( const [ key , value ] of obj . getAll ( ) ) {
518
+ dests [ key ] = fetchDestination ( value ) ;
520
519
}
521
520
} else if ( obj instanceof Dict ) {
522
521
obj . forEach ( function ( key , value ) {
@@ -582,8 +581,9 @@ class Catalog {
582
581
currentIndex = 1 ;
583
582
584
583
for ( let i = 0 , ii = this . numPages ; i < ii ; i ++ ) {
585
- if ( i in nums ) {
586
- const labelDict = nums [ i ] ;
584
+ const labelDict = nums . get ( i ) ;
585
+
586
+ if ( labelDict !== undefined ) {
587
587
if ( ! isDict ( labelDict ) ) {
588
588
throw new FormatError ( "PageLabel is not a dictionary." ) ;
589
589
}
@@ -879,34 +879,35 @@ class Catalog {
879
879
const obj = this . _catDict . get ( "Names" ) ;
880
880
let attachments = null ;
881
881
882
- if ( obj && obj . has ( "EmbeddedFiles" ) ) {
882
+ if ( obj instanceof Dict && obj . has ( "EmbeddedFiles" ) ) {
883
883
const nameTree = new NameTree ( obj . getRaw ( "EmbeddedFiles" ) , this . xref ) ;
884
- const names = nameTree . getAll ( ) ;
885
- for ( const name in names ) {
886
- const fs = new FileSpec ( names [ name ] , this . xref ) ;
884
+ for ( const [ key , value ] of nameTree . getAll ( ) ) {
885
+ const fs = new FileSpec ( value , this . xref ) ;
887
886
if ( ! attachments ) {
888
887
attachments = Object . create ( null ) ;
889
888
}
890
- attachments [ stringToPDFString ( name ) ] = fs . serializable ;
889
+ attachments [ stringToPDFString ( key ) ] = fs . serializable ;
891
890
}
892
891
}
893
892
return shadow ( this , "attachments" , attachments ) ;
894
893
}
895
894
896
895
_collectJavaScript ( ) {
897
896
const obj = this . _catDict . get ( "Names" ) ;
898
-
899
897
let javaScript = null ;
898
+
900
899
function appendIfJavaScriptDict ( name , jsDict ) {
901
- const type = jsDict . get ( "S" ) ;
902
- if ( ! isName ( type , "JavaScript" ) ) {
900
+ if ( ! ( jsDict instanceof Dict ) ) {
901
+ return ;
902
+ }
903
+ if ( ! isName ( jsDict . get ( "S" ) , "JavaScript" ) ) {
903
904
return ;
904
905
}
905
906
906
907
let js = jsDict . get ( "JS" ) ;
907
908
if ( isStream ( js ) ) {
908
909
js = bytesToString ( js . getBytes ( ) ) ;
909
- } else if ( ! isString ( js ) ) {
910
+ } else if ( typeof js !== "string" ) {
910
911
return ;
911
912
}
912
913
@@ -916,22 +917,15 @@ class Catalog {
916
917
javaScript . set ( name , stringToPDFString ( js ) ) ;
917
918
}
918
919
919
- if ( obj && obj . has ( "JavaScript" ) ) {
920
+ if ( obj instanceof Dict && obj . has ( "JavaScript" ) ) {
920
921
const nameTree = new NameTree ( obj . getRaw ( "JavaScript" ) , this . xref ) ;
921
- const names = nameTree . getAll ( ) ;
922
- for ( const name in names ) {
923
- // We don't use most JavaScript in PDF documents. This code is
924
- // defensive so we don't cause errors on document load.
925
- const jsDict = names [ name ] ;
926
- if ( isDict ( jsDict ) ) {
927
- appendIfJavaScriptDict ( name , jsDict ) ;
928
- }
922
+ for ( const [ key , value ] of nameTree . getAll ( ) ) {
923
+ appendIfJavaScriptDict ( key , value ) ;
929
924
}
930
925
}
931
-
932
- // Append OpenAction "JavaScript" actions to the JavaScript array.
926
+ // Append OpenAction "JavaScript" actions, if any, to the JavaScript map.
933
927
const openAction = this . _catDict . get ( "OpenAction" ) ;
934
- if ( isDict ( openAction ) && isName ( openAction . get ( "S" ) , "JavaScript" ) ) {
928
+ if ( openAction ) {
935
929
appendIfJavaScriptDict ( "OpenAction" , openAction ) ;
936
930
}
937
931
0 commit comments