Revision: 3988 Author: [email protected] Date: Fri Feb 19 12:41:53 2010 Log: Fix error trapping in embedded modules. http://codereview.appspot.com/216044
Cajita keeps track, in the module handler of the outcome of the last module. The same module handler is used to handle the modules a module loads. The lastOutcome variable is shared state across modules which means that the outer modules result is not independent of any modules it loads. This fixes that by using a local variable inside the handle function to store intermediate results. The problem arises because lastOutcome is set on both sides of the call to newModule.instantiate. [email protected] http://code.google.com/p/google-caja/source/detail?r=3988 Modified: /trunk/src/com/google/caja/cajita.js ======================================= --- /trunk/src/com/google/caja/cajita.js Thu Feb 11 23:24:24 2010 +++ /trunk/src/com/google/caja/cajita.js Fri Feb 19 12:41:53 2010 @@ -3309,23 +3309,22 @@ */ handle: markFuncFreeze(function handle(newModule) { registerClosureInspector(newModule); - lastOutcome = void 0; + var outcome = void 0; try { var result = newModule.instantiate(___, imports); if (result !== NO_RESULT) { - lastOutcome = [true, result]; + outcome = [true, result]; } } catch (ex) { - lastOutcome = [false, ex]; - } - if (lastOutcome) { - if (lastOutcome[0]) { - return lastOutcome[1]; + outcome = [false, ex]; + } + lastOutcome = outcome; + if (outcome) { + if (outcome[0]) { + return outcome[1]; } else { - throw lastOutcome[1]; - } - } else { - return void 0; + throw outcome[1]; + } } }), @@ -3370,14 +3369,14 @@ ? onerror.CALL___(message, String(source), String(lineNum)) : onerror !== null); if (shouldReport !== false) { - cajita.log(source + ':' + lineNum + ': ' + message); + log(source + ':' + lineNum + ': ' + message); } } }); } - + /** - * Produces a function module given an object literal module + * Produces a function module given an object literal module */ function prepareModule(module, load) { registerClosureInspector(module);
