@@ -28,7 +28,9 @@ module.exports = class ContextResolver {
2828 this . sharedCache = sharedCache ;
2929 }
3030
31- async resolve ( { context, documentLoader, base, cycles = new Set ( ) } ) {
31+ async resolve ( {
32+ activeCtx, context, documentLoader, base, cycles = new Set ( )
33+ } ) {
3234 // process `@context`
3335 if ( context && _isObject ( context ) && context [ '@context' ] ) {
3436 context = context [ '@context' ] ;
@@ -46,7 +48,7 @@ module.exports = class ContextResolver {
4648 if ( ! resolved ) {
4749 // not resolved yet, resolve
4850 resolved = await this . _resolveRemoteContext (
49- { url : ctx , documentLoader, base, cycles} ) ;
51+ { activeCtx , url : ctx , documentLoader, base, cycles} ) ;
5052 }
5153
5254 // add to output and continue
@@ -109,38 +111,49 @@ module.exports = class ContextResolver {
109111 return resolved ;
110112 }
111113
112- async _resolveRemoteContext ( { url, documentLoader, base, cycles} ) {
114+ async _resolveRemoteContext ( { activeCtx , url, documentLoader, base, cycles} ) {
113115 // resolve relative URL and fetch context
114116 url = prependBase ( base , url ) ;
115117 const { context, remoteDoc} = await this . _fetchContext (
116- { url, documentLoader, cycles} ) ;
118+ { activeCtx , url, documentLoader, cycles} ) ;
117119
118120 // update base according to remote document and resolve any relative URLs
119121 base = remoteDoc . documentUrl || url ;
120122 _resolveContextUrls ( { context, base} ) ;
121123
122124 // resolve, cache, and return context
123125 const resolved = await this . resolve (
124- { context, documentLoader, base, cycles} ) ;
126+ { activeCtx , context, documentLoader, base, cycles} ) ;
125127 this . _cacheResolvedContext ( { key : url , resolved, tag : remoteDoc . tag } ) ;
126128 return resolved ;
127129 }
128130
129- async _fetchContext ( { url, documentLoader, cycles} ) {
131+ async _fetchContext ( { activeCtx , url, documentLoader, cycles} ) {
130132 // check for max context URLs fetched during a resolve operation
131133 if ( cycles . size > MAX_CONTEXT_URLS ) {
132134 throw new JsonLdError (
133135 'Maximum number of @context URLs exceeded.' ,
134136 'jsonld.ContextUrlError' ,
135- { code : 'loading remote context failed' , max : MAX_CONTEXT_URLS } ) ;
137+ {
138+ code : activeCtx . processingMode === 'json-ld-1.0' ?
139+ 'loading remote context failed' :
140+ 'context overflow' ,
141+ max : MAX_CONTEXT_URLS
142+ } ) ;
136143 }
137144
138145 // check for context URL cycle
146+ // shortcut to avoid extra work that would eventually hit the max above
139147 if ( cycles . has ( url ) ) {
140148 throw new JsonLdError (
141149 'Cyclical @context URLs detected.' ,
142150 'jsonld.ContextUrlError' ,
143- { code : 'recursive context inclusion' , url} ) ;
151+ {
152+ code : activeCtx . processingMode === 'json-ld-1.0' ?
153+ 'recursive context inclusion' :
154+ 'context overflow' ,
155+ url
156+ } ) ;
144157 }
145158
146159 // track cycles
0 commit comments