@@ -45,8 +45,7 @@ api.cache = new ActiveContextCache();
45
45
*
46
46
* @return the new active context.
47
47
*/
48
- api . process = ( { activeCtx, localCtx, options,
49
- propertyTermDefinition = false } ) => {
48
+ api . process = ( { activeCtx, localCtx, options} ) => {
50
49
// normalize local context to an array of @context objects
51
50
if ( _isObject ( localCtx ) && '@context' in localCtx &&
52
51
_isArray ( localCtx [ '@context' ] ) ) {
@@ -65,11 +64,23 @@ api.process = ({activeCtx, localCtx, options,
65
64
for ( let i = 0 ; i < ctxs . length ; ++ i ) {
66
65
let ctx = ctxs [ i ] ;
67
66
67
+ // update active context to one computed from last iteration
68
+ activeCtx = rval ;
69
+
70
+ // get context from cache if available
71
+ if ( api . cache ) {
72
+ const cached = api . cache . get ( activeCtx , ctx ) ;
73
+ if ( cached ) {
74
+ rval = activeCtx = cached ;
75
+ continue ;
76
+ }
77
+ }
78
+
68
79
// reset to initial context
69
80
if ( ctx === null ) {
70
81
// We can't nullify if there are protected terms and we're
71
- // not in a term definition
72
- if ( ! propertyTermDefinition &&
82
+ // not processing a property term scoped context
83
+ if ( ! options . isPropertyTermScopedContext &&
73
84
Object . keys ( activeCtx . protected ) . length !== 0 ) {
74
85
const protectedMode = ( options && options . protectedMode ) || 'error' ;
75
86
if ( protectedMode === 'error' ) {
@@ -82,6 +93,7 @@ api.process = ({activeCtx, localCtx, options,
82
93
// FIXME: remove logging and use a handler
83
94
console . warn ( 'WARNING: invalid context nullification' ) ;
84
95
const oldActiveCtx = activeCtx ;
96
+ // copy all protected term definitions to fresh initial context
85
97
rval = activeCtx = api . getInitialContext ( options ) ;
86
98
for ( const [ term , _protected ] of
87
99
Object . entries ( oldActiveCtx . protected ) ) {
@@ -91,6 +103,12 @@ api.process = ({activeCtx, localCtx, options,
91
103
}
92
104
}
93
105
activeCtx . protected = util . clone ( oldActiveCtx . protected ) ;
106
+
107
+ // cache result
108
+ if ( api . cache ) {
109
+ api . cache . set ( oldActiveCtx , ctx , rval ) ;
110
+ }
111
+
94
112
continue ;
95
113
}
96
114
throw new JsonLdError (
@@ -114,17 +132,7 @@ api.process = ({activeCtx, localCtx, options,
114
132
'jsonld.SyntaxError' , { code : 'invalid local context' , context : ctx } ) ;
115
133
}
116
134
117
- // get context from cache if available
118
- if ( api . cache ) {
119
- const cached = api . cache . get ( activeCtx , ctx ) ;
120
- if ( cached ) {
121
- rval = activeCtx = cached ;
122
- continue ;
123
- }
124
- }
125
-
126
- // update active context and clone new one before updating
127
- activeCtx = rval ;
135
+ // clone context before updating it
128
136
rval = rval . clone ( ) ;
129
137
130
138
// define context mappings for keys in local context
@@ -277,7 +285,7 @@ api.createTermDefinition = (activeCtx, localCtx, term, defined, options) => {
277
285
}
278
286
279
287
// FIXME if(1.1) ... ?
280
- if ( term in activeCtx . protected ) {
288
+ if ( term in activeCtx . protected && ! options . isPropertyTermScopedContext ) {
281
289
const protectedMode = ( options && options . protectedMode ) || 'error' ;
282
290
if ( protectedMode === 'error' ) {
283
291
throw new JsonLdError (
@@ -442,14 +450,9 @@ api.createTermDefinition = (activeCtx, localCtx, term, defined, options) => {
442
450
}
443
451
444
452
// Handle term protection
445
- if ( '@protected' in value ) {
446
- if ( value [ '@protected' ] ) {
447
- activeCtx . protected [ term ] = true ;
448
- }
449
- } else if ( '@protected' in defined ) {
450
- if ( defined [ '@protected' ] ) {
451
- activeCtx . protected [ term ] = true ;
452
- }
453
+ if ( value [ '@protected' ] === true ||
454
+ ( defined [ '@protected' ] === true && value [ '@protected' ] !== false ) ) {
455
+ activeCtx . protected [ term ] = true ;
453
456
}
454
457
455
458
// IRI mapping now defined
0 commit comments