diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-20 14:57:49 +0100 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-02-20 21:37:27 +0100 |
commit | 7d58c3b7314e4a63591fa375546cfc76a042e644 (patch) | |
tree | c51d390ee3830f924b2fb1e289b9461c8310d625 /src/ldo.js | |
parent | 5860ec2bde3b220eff01b3bd1462e60905ef2fe9 (diff) | |
download | fengari-7d58c3b7314e4a63591fa375546cfc76a042e644.tar.gz fengari-7d58c3b7314e4a63591fa375546cfc76a042e644.tar.bz2 fengari-7d58c3b7314e4a63591fa375546cfc76a042e644.zip |
ldebug, lua_error, error
Diffstat (limited to 'src/ldo.js')
-rw-r--r-- | src/ldo.js | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -227,6 +227,28 @@ const luaD_call = function(L, off, nResults) { L.nCcalls--; }; +const luaD_throw = function(L, errcode) { + if (L.errorJmp) { /* thread has an error handler? */ + L.errorJmp.status = errcode; /* set status */ + throw L.errorJmp; + } else { /* thread has no error handler */ + let g = L.l_G; + L.status = errcode; /* mark it as dead */ + if (g.mainthread.errorJmp) { /* main thread has a handler? */ + g.mainthread.stack[g.mainthread.top++] = L.stack[L.top - 1]; /* copy error obj. */ + luaD_throw(g.mainthread, errcode); /* re-throw in main thread */ + } else { /* no handler at all; abort */ + if (g.panic) { /* panic function? */ + seterrorobj(L, errcode, L.top); /* assume EXTRA_STACK */ + if (L.ci.top < L.top) + L.ci.top = L.top; /* pushing msg. can break this invariant */ + g.panic(L); /* call panic function (last chance to jump out) */ + } + throw new Error(`Aborted ${errcode}`); + } + } +}; + const luaD_rawrunprotected = function(L, f, ud) { let oldnCcalls = L.nCcalls; let lj = { // TODO: necessary when using try/catch ? (ldo.c:47-52) @@ -309,5 +331,6 @@ module.exports.stackerror = stackerror; module.exports.luaD_call = luaD_call; module.exports.luaD_callnoyield = luaD_callnoyield; module.exports.luaD_pcall = luaD_pcall; +module.exports.luaD_throw = luaD_throw; module.exports.luaD_rawrunprotected = luaD_rawrunprotected; module.exports.luaD_protectedparser = luaD_protectedparser;
\ No newline at end of file |