Update to latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Mon, 15 Apr 2013 10:46:46 -0400
changeset 1586 e0f751d4968c
parent 1585 305be96b099e
child 1587 926b73915ffe
Update to latest jsonld.js.
playground/jsonld.js
--- a/playground/jsonld.js	Mon Apr 15 13:38:16 2013 +0200
+++ b/playground/jsonld.js	Mon Apr 15 10:46:46 2013 -0400
@@ -732,21 +732,27 @@
 
 /* Utility API */
 
-// define nextTick
+// define setImmediate and nextTick
 if(typeof process === 'undefined' || !process.nextTick) {
   if(typeof setImmediate === 'function') {
-    jsonld.nextTick = function(callback) {
-      setImmediate(callback);
-    };
+    jsonld.setImmediate = setImmediate;
+    jsonld.nextTick = setImmediate;
   }
   else {
-    jsonld.nextTick = function(callback) {
+    jsonld.setImmediate = function(callback) {
       setTimeout(callback, 0);
     };
+    jsonld.nextTick = jsonld.setImmediate;
   }
 }
 else {
   jsonld.nextTick = process.nextTick;
+  if(typeof setImmediate === 'function') {
+    jsonld.setImmediate = setImmediate;
+  }
+  else {
+    jsonld.setImmediate = jsonld.nextTick;
+  }
 }
 
 /**
@@ -2101,7 +2107,7 @@
     var unique = {};
 
     // hash quads for each unnamed bnode
-    jsonld.nextTick(function() {hashUnnamed(0);});
+    jsonld.setImmediate(function() {hashUnnamed(0);});
     function hashUnnamed(i) {
       if(i === unnamed.length) {
         // done, name blank nodes
@@ -2128,7 +2134,7 @@
       }
 
       // hash next unnamed bnode
-      jsonld.nextTick(function() {hashUnnamed(i + 1);});
+      jsonld.setImmediate(function() {hashUnnamed(i + 1);});
     }
   }
 
@@ -2980,7 +2986,7 @@
   var groups = {};
   var groupHashes;
   var quads = bnodes[id].quads;
-  jsonld.nextTick(function() {groupNodes(0);});
+  jsonld.setImmediate(function() {groupNodes(0);});
   function groupNodes(i) {
     if(i === quads.length) {
       // done, hash groups
@@ -3033,7 +3039,7 @@
       }
     }
 
-    jsonld.nextTick(function() {groupNodes(i + 1);});
+    jsonld.setImmediate(function() {groupNodes(i + 1);});
   }
 
   // hashes a group of adjacent bnodes
@@ -3051,7 +3057,7 @@
     var chosenPath = null;
     var chosenNamer = null;
     var permutator = new Permutator(groups[groupHash]);
-    jsonld.nextTick(function() {permutate();});
+    jsonld.setImmediate(function() {permutate();});
     function permutate() {
       var permutation = permutator.next();
       var pathNamerCopy = pathNamer.clone();
@@ -3119,7 +3125,7 @@
 
         // do next permutation
         if(permutator.hasNext()) {
-          jsonld.nextTick(function() {permutate();});
+          jsonld.setImmediate(function() {permutate();});
         }
         else {
           // digest chosen path and update namer
@@ -4215,11 +4221,14 @@
         'of strings or a string.',
         'jsonld.SyntaxError', {context: localCtx});
     }
-    // expand and add @id mapping
-    mapping['@id'] = _expandIri(
-      activeCtx, id, {vocab: true, base: true}, localCtx, defined);
-  }
-  else {
+    if(id !== term) {
+      // expand and add @id mapping
+      mapping['@id'] = _expandIri(
+        activeCtx, id, {vocab: true, base: true}, localCtx, defined);
+    }
+  }
+
+  if(!('@id' in mapping)) {
     // see if the term has a prefix
     var colon = term.indexOf(':');
     if(colon !== -1) {