Fix Exception throw within catch block (fix #566)

This commit is contained in:
Gordon Williams 2015-08-26 14:04:10 +01:00
parent 92e054fa29
commit 071102b859
3 changed files with 46 additions and 6 deletions

View File

@ -14,6 +14,7 @@
Add Object.defineProperty/defineProperties (even if they ignore most args)
Fix value returned when redefining an existing function
Ensure Pico powers down USB in deep sleep - now down to 20uA!
Fix Exception throw within catch block (fix #566)
1v80 : Fix SD card IO that can corrupt SD card on file append since 1v73 (fix #536)
Fix some potential pointer issues in hashlib

View File

@ -2062,15 +2062,20 @@ NO_INLINE JsVar *jspeStatementTry() {
jsvUnLock(actualExceptionName);
// remove any stack trace
jsvRemoveNamedChild(execInfo.hiddenRoot, JSPARSE_STACKTRACE_VAR);
// Now clear the exception flag (it's handled - we hope!)
execInfo.execute = execInfo.execute & (JsExecFlags)~EXEC_EXCEPTION;
}
// Now clear the exception flag (it's handled - we hope!)
execInfo.execute = execInfo.execute & (JsExecFlags)~(EXEC_EXCEPTION|EXEC_ERROR_LINE_REPORTED);
jsvUnLock(exceptionVar);
}
JSP_SAVE_EXECUTE();
if (shouldExecuteBefore && !hadException) jspSetNoExecute();
jspeBlock();
JSP_RESTORE_EXECUTE();
if (shouldExecuteBefore && !hadException) {
JSP_SAVE_EXECUTE();
jspSetNoExecute();
jspeBlock();
JSP_RESTORE_EXECUTE();
} else {
jspeBlock();
}
}
if (execInfo.lex->tk == LEX_R_FINALLY || (!hadCatch && ((execInfo.execute&(EXEC_ERROR|EXEC_INTERRUPTED))==0))) {
JSP_MATCH(LEX_R_FINALLY);

34
tests/test_exception_7.js Normal file
View File

@ -0,0 +1,34 @@
// http://forum.espruino.com/conversations/273386/
var r = "";
function log(s) {
r += s+"\n";
console.log(s);
}
function outer() {
try {
log('In outer');
inner();
log('Out outer');
} catch(x) {
log('Catch outer '+x);
}
}
function inner() {
try {
log('In inner');
throw "coucou";
log('Out inner');
} catch(x) {
log('Catch inner '+x);
throw x;
}
}
outer();
result = r=="In outer\nIn inner\nCatch inner coucou\nCatch outer coucou\n";