Update to jsonld.js v0.2.15.
authorDave Longley <dlongley@digitalbazaar.com>
Wed, 09 Jul 2014 15:21:27 -0400
changeset 2165 daba882b81ab
parent 2164 bbd26f6da88c
child 2166 a96f09f9631b
child 2167 44bb6afefe3f
Update to jsonld.js v0.2.15.
playground/index.html
playground/jsonld.js
--- a/playground/index.html	Tue Jul 08 17:39:41 2014 -0400
+++ b/playground/index.html	Wed Jul 09 15:21:27 2014 -0400
@@ -313,7 +313,7 @@
     <script src="//cdn.jsdelivr.net/g/[email protected],[email protected],[email protected],[email protected](codemirror.min.js+addon/lint/lint.js+addon/edit/matchbrackets.js+addon/edit/closebrackets.js+addon/display/placeholder.js+addon/hint/show-hint.js+mode/ntriples/ntriples.js+mode/javascript/javascript.js)"></script>
 
     <!-- local scripts -->
-    <script src="//cdnjs.cloudflare.com/ajax/libs/jsonld/0.2.14/jsonld.js"></script>
+    <script src="//cdnjs.cloudflare.com/ajax/libs/jsonld/0.2.15/jsonld.js"></script>
     <script src="./jsonlint.js"></script>
     <script src="./tv4.min.js"></script>
     <script src="./json-schema-lint.js"></script>
--- a/playground/jsonld.js	Tue Jul 08 17:39:41 2014 -0400
+++ b/playground/jsonld.js	Wed Jul 09 15:21:27 2014 -0400
@@ -3065,16 +3065,15 @@
     return activeCtx.clone();
   }
 
-  // process each context in order
+  // process each context in order, update active context
+  // on each iteration to ensure proper caching
   var rval = activeCtx;
-  var mustClone = true;
   for(var i = 0; i < ctxs.length; ++i) {
     var ctx = ctxs[i];
 
     // reset to initial context
     if(ctx === null) {
-      rval = _getInitialContext(options);
-      mustClone = false;
+      rval = activeCtx = _getInitialContext(options);
       continue;
     }
 
@@ -3094,17 +3093,14 @@
     if(jsonld.cache.activeCtx) {
       var cached = jsonld.cache.activeCtx.get(activeCtx, ctx);
       if(cached) {
-        rval = cached;
-        mustClone = true;
+        rval = activeCtx = cached;
         continue;
       }
     }
 
-    // clone context, if required, before updating
-    if(mustClone) {
-      rval = rval.clone();
-      mustClone = false;
-    }
+    // update active context and clone new one before updating
+    activeCtx = rval;
+    rval = rval.clone();
 
     // define context mappings for keys in local context
     var defined = {};
@@ -4743,7 +4739,8 @@
   if(_isKeyword(term)) {
     throw new JsonLdError(
       'Invalid JSON-LD syntax; keywords cannot be overridden.',
-      'jsonld.SyntaxError', {code: 'keyword redefinition', context: localCtx});
+      'jsonld.SyntaxError',
+      {code: 'keyword redefinition', context: localCtx, term: term});
   }
 
   if(term === '') {