[Opensrf-commits] r1831 - trunk/src/javascript (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Oct 29 15:48:38 EDT 2009


Author: miker
Date: 2009-10-29 15:48:33 -0400 (Thu, 29 Oct 2009)
New Revision: 1831

Modified:
   trunk/src/javascript/JSON_v1.js
Log:
give decodeJS a way to try to load a class that was requested but does not yet exist

Modified: trunk/src/javascript/JSON_v1.js
===================================================================
--- trunk/src/javascript/JSON_v1.js	2009-10-29 19:25:39 UTC (rev 1830)
+++ trunk/src/javascript/JSON_v1.js	2009-10-29 19:48:33 UTC (rev 1831)
@@ -9,6 +9,8 @@
 	return decodeJS(JSON2jsRaw(text));
 }
 
+JSON2js.fallbackObjectifier = null;
+
 function JSON2jsRaw(text) {
 	var obj;
 	eval('obj = ' + text);
@@ -43,7 +45,14 @@
 	if(	arg && typeof arg == 'object' &&
 			arg.constructor == Object &&
 			arg[JSON_CLASS_KEY] ) {
-		eval('arg = new ' + arg[JSON_CLASS_KEY] + '(arg[JSON_DATA_KEY])');	
+
+        try {
+            arg = eval('new ' + arg[JSON_CLASS_KEY] + '(arg[JSON_DATA_KEY])');	
+        } catch(E) {
+            if (JSON2js.fallbackObjectifier)
+                arg = JSON2js.fallbackObjectifier(arg, JSON_CLASS_KEY, JSON_DATA_KEY );
+        }
+
 	}
 
     if(arg._encodehash) {



More information about the opensrf-commits mailing list