summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-15 19:34:05 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-15 19:34:05 +1000
commitf1274016f284ad3c1d5f9e87db6cbedb86fef18d (patch)
tree3d3eac8b679d4de932574f26f88c625ab98b5870
parentb22283e31b68bb3d558c962b4eac2321c526c9c2 (diff)
downloadfengari-f1274016f284ad3c1d5f9e87db6cbedb86fef18d.tar.gz
fengari-f1274016f284ad3c1d5f9e87db6cbedb86fef18d.tar.bz2
fengari-f1274016f284ad3c1d5f9e87db6cbedb86fef18d.zip
src/ldo.js: message handler should still be run after native error handling
-rw-r--r--README.md1
-rw-r--r--src/ldo.js10
2 files changed, 11 insertions, 0 deletions
diff --git a/README.md b/README.md
index 0fbfc4e..b27dc58 100644
--- a/README.md
+++ b/README.md
@@ -110,6 +110,7 @@ Alias for `lua_pushcclosure`.
Sets a function to be called if a native JavaScript error is thrown across a lua pcall.
The function will be run as if it were a message handler (see https://www.lua.org/manual/5.3/manual.html#2.3).
+The current message handler will be run after the native error handler returns.
### `b = lua_isproxy(p, L)`
diff --git a/src/ldo.js b/src/ldo.js
index c4619e5..3bbcec6 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -283,6 +283,16 @@ const luaD_rawrunprotected = function(L, f, ud) {
lapi.lua_pushlightuserdata(L, e);
luaD_callnoyield(L, L.top - 2, 1);
+ /* Now run the message handler (if it exists) */
+ /* copy of luaG_errormsg without the throw */
+ if (L.errfunc !== 0) { /* is there an error handling function? */
+ let errfunc = L.errfunc;
+ L.stack[L.top] = L.stack[L.top - 1];
+ L.stack[L.top - 1] = L.stack[errfunc];
+ L.top++;
+ luaD_callnoyield(L, L.top - 2, 1);
+ }
+
lj.status = TS.LUA_ERRRUN;
} catch(e2) {
if (lj.status === TS.LUA_OK) {