give decodeJS a way to try to load a class that was requested but does not yet exist
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 29 Oct 2009 19:48:33 +0000 (19:48 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 29 Oct 2009 19:48:33 +0000 (19:48 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1831 9efc2488-bf62-4759-914b-345cdb29e865

src/javascript/JSON_v1.js

index 4ba09f0..d70aacd 100644 (file)
@@ -9,6 +9,8 @@ function JSON2js(text) {
        return decodeJS(JSON2jsRaw(text));
 }
 
+JSON2js.fallbackObjectifier = null;
+
 function JSON2jsRaw(text) {
        var obj;
        eval('obj = ' + text);
@@ -43,7 +45,14 @@ function decodeJS(arg) {
        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) {