@@ -946,7 +946,6 @@ async function _retrieveContextUrls(input, options) {
946
946
const documentLoader = util . normalizeDocumentLoader ( options . documentLoader ) ;
947
947
948
948
// retrieve all @context URLs in input
949
- const _urls = { } ;
950
949
await retrieve ( input , { } , documentLoader ) ;
951
950
952
951
return input ;
@@ -960,17 +959,12 @@ async function _retrieveContextUrls(input, options) {
960
959
{ code : 'loading remote context failed' , max : MAX_CONTEXT_URLS } ) ;
961
960
}
962
961
963
- // find all URLs in the given document, reusing already retrieved URLs
964
- const urls = { } ;
965
- Object . keys ( _urls ) . forEach ( url => {
966
- if ( _urls [ url ] !== false ) {
967
- urls [ url ] = _urls [ url ] ;
968
- }
969
- } ) ;
962
+ // find all URLs in the given document
963
+ const urls = new Map ( ) ;
970
964
_findContextUrls ( doc , urls , false , options . base ) ;
971
965
972
966
// queue all unretrieved URLs
973
- const queue = Object . keys ( urls ) . filter ( u => urls [ u ] === false ) ;
967
+ const queue = [ ... urls . keys ( ) ] . filter ( u => urls . get ( u ) === false ) ;
974
968
975
969
// retrieve URLs in queue
976
970
return Promise . all ( queue . map ( async url => {
@@ -979,7 +973,7 @@ async function _retrieveContextUrls(input, options) {
979
973
throw new JsonLdError (
980
974
'Cyclical @context URLs detected.' ,
981
975
'jsonld.ContextUrlError' ,
982
- { code : 'recursive context inclusion' , url : url } ) ;
976
+ { code : 'recursive context inclusion' , url} ) ;
983
977
}
984
978
985
979
const _cycles = util . clone ( cycles ) ;
@@ -1003,7 +997,7 @@ async function _retrieveContextUrls(input, options) {
1003
997
'non-JSON response, or more than one HTTP Link Header was ' +
1004
998
'provided for a remote context.' ,
1005
999
'jsonld.InvalidUrl' ,
1006
- { code : 'loading remote context failed' , url : url , cause : e } ) ;
1000
+ { code : 'loading remote context failed' , url, cause : e } ) ;
1007
1001
}
1008
1002
1009
1003
// ensure ctx is an object
@@ -1012,7 +1006,7 @@ async function _retrieveContextUrls(input, options) {
1012
1006
'Dereferencing a URL did not result in a JSON object. The ' +
1013
1007
'response was valid JSON, but it was not a JSON object.' ,
1014
1008
'jsonld.InvalidUrl' ,
1015
- { code : 'invalid remote context' , url : url } ) ;
1009
+ { code : 'invalid remote context' , url} ) ;
1016
1010
}
1017
1011
1018
1012
// use empty context if no @context key is present
@@ -1034,7 +1028,7 @@ async function _retrieveContextUrls(input, options) {
1034
1028
await retrieve ( ctx , _cycles , documentLoader ) ;
1035
1029
1036
1030
// store retrieved context w/replaced @context URLs
1037
- urls [ url ] = ctx [ '@context' ] ;
1031
+ urls . set ( url , ctx [ '@context' ] ) ;
1038
1032
1039
1033
// replace all @context URLs in the document
1040
1034
_findContextUrls ( doc , urls , true , options . base ) ;
@@ -1083,7 +1077,7 @@ function _findContextUrls(input, urls, replace, base) {
1083
1077
const _ctx = ctx [ i ] ;
1084
1078
if ( _isString ( _ctx ) ) {
1085
1079
const prepended = prependBase ( base , _ctx ) ;
1086
- const resolved = urls [ prepended ] ;
1080
+ const resolved = urls . get ( prepended ) ;
1087
1081
// replace w/@context if requested
1088
1082
if ( replace ) {
1089
1083
if ( _isArray ( resolved ) ) {
@@ -1096,7 +1090,7 @@ function _findContextUrls(input, urls, replace, base) {
1096
1090
}
1097
1091
} else if ( resolved === undefined ) {
1098
1092
// @context URL found
1099
- urls [ prepended ] = false ;
1093
+ urls . set ( prepended , false ) ;
1100
1094
}
1101
1095
} else {
1102
1096
// look for scoped context
@@ -1110,15 +1104,15 @@ function _findContextUrls(input, urls, replace, base) {
1110
1104
} else if ( _isString ( ctx ) ) {
1111
1105
// string @context
1112
1106
const prepended = prependBase ( base , ctx ) ;
1113
- const resolved = urls [ prepended ] ;
1107
+ const resolved = urls . get ( prepended ) ;
1114
1108
// replace w/@context if requested
1115
1109
if ( replace ) {
1116
1110
if ( resolved !== false ) {
1117
1111
input [ key ] = resolved ;
1118
1112
}
1119
1113
} else if ( resolved === undefined ) {
1120
1114
// @context URL found
1121
- urls [ prepended ] = false ;
1115
+ urls . set ( prepended , false ) ;
1122
1116
}
1123
1117
} else {
1124
1118
// look for scoped context
0 commit comments