@@ -98,46 +98,12 @@ api.process = async ({
9898 if ( ctx === null ) {
9999 // We can't nullify if there are protected terms and we're
100100 // not allowing overrides (e.g. processing a property term scoped context)
101- if ( ! overrideProtected &&
102- Object . keys ( activeCtx . protected ) . length !== 0 ) {
103- const protectedMode = ( options && options . protectedMode ) || 'error' ;
104- if ( protectedMode === 'error' ) {
105- throw new JsonLdError (
106- 'Tried to nullify a context with protected terms outside of ' +
107- 'a term definition.' ,
108- 'jsonld.SyntaxError' ,
109- { code : 'invalid context nullification' } ) ;
110- } else if ( protectedMode === 'warn' ) {
111- // FIXME: remove logging and use a handler
112- console . warn ( 'WARNING: invalid context nullification' ) ;
113-
114- // get processed context from cache if available
115- const processed = resolvedContext . getProcessed ( activeCtx ) ;
116- if ( processed ) {
117- rval = activeCtx = processed ;
118- continue ;
119- }
120-
121- const oldActiveCtx = activeCtx ;
122- // copy all protected term definitions to fresh initial context
123- rval = activeCtx = api . getInitialContext ( options ) . clone ( ) ;
124- for ( const [ term , _protected ] of
125- Object . entries ( oldActiveCtx . protected ) ) {
126- if ( _protected ) {
127- activeCtx . mappings [ term ] =
128- util . clone ( oldActiveCtx . mappings [ term ] ) ;
129- }
130- }
131- activeCtx . protected = util . clone ( oldActiveCtx . protected ) ;
132-
133- // cache processed result
134- resolvedContext . setProcessed ( oldActiveCtx , rval ) ;
135- continue ;
136- }
101+ if ( ! overrideProtected && Object . keys ( activeCtx . protected ) . length !== 0 ) {
137102 throw new JsonLdError (
138- 'Invalid protectedMode.' ,
103+ 'Tried to nullify a context with protected terms outside of ' +
104+ 'a term definition.' ,
139105 'jsonld.SyntaxError' ,
140- { code : 'invalid protected mode' , context : localCtx , protectedMode } ) ;
106+ { code : 'invalid context nullification' } ) ;
141107 }
142108 rval = activeCtx = api . getInitialContext ( options ) . clone ( ) ;
143109 continue ;
@@ -429,9 +395,6 @@ api.process = async ({
429395 * @param defined a map of defining/defined keys to detect cycles and prevent
430396 * double definitions.
431397 * @param {Object } [options] - creation options.
432- * @param {string } [options.protectedMode="error"] - "error" to throw error
433- * on `@protected` constraint violation, "warn" to allow violations and
434- * signal a warning.
435398 * @param overrideProtected `false` allows protected terms to be modified.
436399 */
437400api . createTermDefinition = ( {
@@ -918,23 +881,10 @@ api.createTermDefinition = ({
918881 activeCtx . protected [ term ] = true ;
919882 mapping . protected = true ;
920883 if ( ! _deepCompare ( previousMapping , mapping ) ) {
921- const protectedMode = ( options && options . protectedMode ) || 'error' ;
922- if ( protectedMode === 'error' ) {
923- throw new JsonLdError (
924- `Invalid JSON-LD syntax; tried to redefine "${ term } " which is a ` +
925- 'protected term.' ,
926- 'jsonld.SyntaxError' ,
927- { code : 'protected term redefinition' , context : localCtx , term} ) ;
928- } else if ( protectedMode === 'warn' ) {
929- // FIXME: remove logging and use a handler
930- console . warn ( 'WARNING: protected term redefinition' , { term} ) ;
931- return ;
932- }
933884 throw new JsonLdError (
934- 'Invalid protectedMode .' ,
885+ 'Invalid JSON-LD syntax; tried to redefine a protected term .' ,
935886 'jsonld.SyntaxError' ,
936- { code : 'invalid protected mode' , context : localCtx , term,
937- protectedMode} ) ;
887+ { code : 'protected term redefinition' , context : localCtx , term} ) ;
938888 }
939889 }
940890} ;
0 commit comments