Spyed functions will now re-throw errors. Watchup...

This commit is contained in:
Gaël Métais
2014-12-30 15:24:30 +01:00
parent 9ec5bd7183
commit 909ffc1aac
@@ -46,6 +46,7 @@ exports.module = function(phantomas) {
obj[fn] = function() {
var result;
var err;
// Before
if (enabled) {
@@ -54,16 +55,29 @@ exports.module = function(phantomas) {
// Execute
try {
result = origFn.apply(this, arguments);
} catch(e) {
// Catching the err for the moment, because we need to make sure the callbackAfter function is called.
phantomas.log('Error catched on spyed function "' + fn + '": ' + e);
phantomas.log(arguments);
err = e;
} finally {
// After
if (enabled && callbackAfter) {
callbackAfter.call(this, result, arguments);
}
if (err) {
phantomas.log('Re-throwing the error');
throw err;
}
}
return result;