summaryrefslogtreecommitdiff
path: root/src/ldo.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-12 14:52:14 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-15 18:56:25 +1000
commit4a0aa6eecf10432453c22031c247cf24819f1040 (patch)
tree542bf773168d6af2069a91125447801a5576d2c6 /src/ldo.js
parent424a3604dd90a40773e3434450bb5cb685962926 (diff)
downloadfengari-4a0aa6eecf10432453c22031c247cf24819f1040.tar.gz
fengari-4a0aa6eecf10432453c22031c247cf24819f1040.tar.bz2
fengari-4a0aa6eecf10432453c22031c247cf24819f1040.zip
Add facility for a user provided (state-global) native error handler
Diffstat (limited to 'src/ldo.js')
-rw-r--r--src/ldo.js26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/ldo.js b/src/ldo.js
index bb34216..c4619e5 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -273,12 +273,26 @@ const luaD_rawrunprotected = function(L, f, ud) {
} catch (e) {
if (lj.status === TS.LUA_OK) {
/* error was not thrown via luaD_throw, i.e. it is a JS error */
- lj.status = -1;
- /* run error handler (if possible) with error object as light userdata */
- try {
- lapi.lua_pushlightuserdata(L, e);
- ldebug.luaG_errormsg(L);
- } catch (e) {}
+ /* run user error handler (if it exists) */
+ let atnativeerror = L.l_G.atnativeerror;
+ if (atnativeerror) {
+ try {
+ lj.status = TS.LUA_OK;
+
+ lapi.lua_pushcfunction(L, atnativeerror);
+ lapi.lua_pushlightuserdata(L, e);
+ luaD_callnoyield(L, L.top - 2, 1);
+
+ lj.status = TS.LUA_ERRRUN;
+ } catch(e2) {
+ if (lj.status === TS.LUA_OK) {
+ /* also failed */
+ lj.status = -1;
+ }
+ }
+ } else {
+ lj.status = -1;
+ }
}
}