summaryrefslogtreecommitdiff
path: root/src/ldo.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-20 14:57:49 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-02-20 21:37:27 +0100
commit7d58c3b7314e4a63591fa375546cfc76a042e644 (patch)
treec51d390ee3830f924b2fb1e289b9461c8310d625 /src/ldo.js
parent5860ec2bde3b220eff01b3bd1462e60905ef2fe9 (diff)
downloadfengari-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.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ldo.js b/src/ldo.js
index 458ae46..04592e9 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -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