From: miker Date: Thu, 29 Oct 2009 19:48:33 +0000 (+0000) Subject: give decodeJS a way to try to load a class that was requested but does not yet exist X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ce38e5428f27e6f4ce9c073966913caa8a093a15;p=opensrf%2Fbjwebb.git give decodeJS a way to try to load a class that was requested but does not yet exist git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1831 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/javascript/JSON_v1.js b/src/javascript/JSON_v1.js index 4ba09f0..d70aacd 100644 --- a/src/javascript/JSON_v1.js +++ b/src/javascript/JSON_v1.js @@ -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) {