Fixed js codegen issue for uncaught exceptions.

This commit is contained in:
Yuriy Glukhov 2016-08-27 15:08:03 +03:00
commit 8bff930c7c
3 changed files with 5 additions and 4 deletions

View file

@ -560,6 +560,7 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) =
# ++excHandler; # ++excHandler;
# try { # try {
# stmts; # stmts;
# --excHandler;
# } catch (EXC) { # } catch (EXC) {
# var prevJSError = lastJSError; lastJSError = EXC; # var prevJSError = lastJSError; lastJSError = EXC;
# --excHandler; # --excHandler;
@ -595,7 +596,7 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) =
var generalCatchBranchExists = false var generalCatchBranchExists = false
let dollar = rope(if p.target == targetJS: "" else: "$") let dollar = rope(if p.target == targetJS: "" else: "$")
if p.target == targetJS and catchBranchesExist: if p.target == targetJS and catchBranchesExist:
addf(p.body, "} catch (EXC) {$n var prevJSError = lastJSError;$n" & addf(p.body, "--excHandler;$n} catch (EXC) {$n var prevJSError = lastJSError;$n" &
" lastJSError = EXC;$n --excHandler;$n", []) " lastJSError = EXC;$n --excHandler;$n", [])
elif p.target == targetPHP: elif p.target == targetPHP:
addf(p.body, "} catch (Exception $$EXC) {$n $$prevJSError = $$lastJSError;$n $$lastJSError = $$EXC;$n", []) addf(p.body, "} catch (Exception $$EXC) {$n $$prevJSError = $$lastJSError;$n $$lastJSError = $$EXC;$n", [])

View file

@ -14,10 +14,9 @@ proc genErrors(s: string) =
raise newException(EsomeotherErr, "bla") raise newException(EsomeotherErr, "bla")
when true: when true:
try: discard except: discard
try: try:
genErrors("errssor!") genErrors("errssor!")
except ESomething: except ESomething:
echo("Error happened") echo("Error happened")

View file

@ -220,6 +220,7 @@ proc jsTests(r: var TResults, cat: Category, options: string) =
for testfile in ["exception/texceptions", "exception/texcpt1", for testfile in ["exception/texceptions", "exception/texcpt1",
"exception/texcsub", "exception/tfinally", "exception/texcsub", "exception/tfinally",
"exception/tfinally2", "exception/tfinally3", "exception/tfinally2", "exception/tfinally3",
"exception/tunhandledexc",
"actiontable/tactiontable", "method/tmultim1", "actiontable/tactiontable", "method/tmultim1",
"method/tmultim3", "method/tmultim4", "method/tmultim3", "method/tmultim4",
"varres/tvarres0", "varres/tvarres3", "varres/tvarres4", "varres/tvarres0", "varres/tvarres3", "varres/tvarres4",