@@ -28,7 +28,9 @@ module.exports = class ContextResolver {
28
28
this . sharedCache = sharedCache ;
29
29
}
30
30
31
- async resolve ( { context, documentLoader, base, cycles = new Set ( ) } ) {
31
+ async resolve ( {
32
+ activeCtx, context, documentLoader, base, cycles = new Set ( )
33
+ } ) {
32
34
// process `@context`
33
35
if ( context && _isObject ( context ) && context [ '@context' ] ) {
34
36
context = context [ '@context' ] ;
@@ -46,7 +48,7 @@ module.exports = class ContextResolver {
46
48
if ( ! resolved ) {
47
49
// not resolved yet, resolve
48
50
resolved = await this . _resolveRemoteContext (
49
- { url : ctx , documentLoader, base, cycles} ) ;
51
+ { activeCtx , url : ctx , documentLoader, base, cycles} ) ;
50
52
}
51
53
52
54
// add to output and continue
@@ -109,38 +111,49 @@ module.exports = class ContextResolver {
109
111
return resolved ;
110
112
}
111
113
112
- async _resolveRemoteContext ( { url, documentLoader, base, cycles} ) {
114
+ async _resolveRemoteContext ( { activeCtx , url, documentLoader, base, cycles} ) {
113
115
// resolve relative URL and fetch context
114
116
url = prependBase ( base , url ) ;
115
117
const { context, remoteDoc} = await this . _fetchContext (
116
- { url, documentLoader, cycles} ) ;
118
+ { activeCtx , url, documentLoader, cycles} ) ;
117
119
118
120
// update base according to remote document and resolve any relative URLs
119
121
base = remoteDoc . documentUrl || url ;
120
122
_resolveContextUrls ( { context, base} ) ;
121
123
122
124
// resolve, cache, and return context
123
125
const resolved = await this . resolve (
124
- { context, documentLoader, base, cycles} ) ;
126
+ { activeCtx , context, documentLoader, base, cycles} ) ;
125
127
this . _cacheResolvedContext ( { key : url , resolved, tag : remoteDoc . tag } ) ;
126
128
return resolved ;
127
129
}
128
130
129
- async _fetchContext ( { url, documentLoader, cycles} ) {
131
+ async _fetchContext ( { activeCtx , url, documentLoader, cycles} ) {
130
132
// check for max context URLs fetched during a resolve operation
131
133
if ( cycles . size > MAX_CONTEXT_URLS ) {
132
134
throw new JsonLdError (
133
135
'Maximum number of @context URLs exceeded.' ,
134
136
'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
+ } ) ;
136
143
}
137
144
138
145
// check for context URL cycle
146
+ // shortcut to avoid extra work that would eventually hit the max above
139
147
if ( cycles . has ( url ) ) {
140
148
throw new JsonLdError (
141
149
'Cyclical @context URLs detected.' ,
142
150
'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
+ } ) ;
144
157
}
145
158
146
159
// track cycles
0 commit comments