summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ldo.js17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/ldo.js b/src/ldo.js
index 84bf2b6..4c53f11 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -22,6 +22,12 @@ const CT = defs.constant_types;
const TS = defs.thread_status;
const seterrorobj = function(L, errcode, oldtop) {
+ let current_top = L.top;
+
+ /* extend stack so that L.stack[oldtop] is sure to exist */
+ while (L.top < oldtop + 1)
+ L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null);
+
switch (errcode) {
case TS.LUA_ERRMEM: {
lobject.setsvalue2s(L, oldtop, lstring.luaS_newliteral(L, "not enough memory"));
@@ -32,17 +38,12 @@ const seterrorobj = function(L, errcode, oldtop) {
break;
}
default: {
- lobject.setobjs2s(L, oldtop, L.top - 1);
+ lobject.setobjs2s(L, oldtop, current_top - 1);
}
}
- if (L.top < oldtop + 1) {
- while (L.top < oldtop + 1)
- L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null);
- } else {
- while (L.top > oldtop + 1)
- delete L.stack[--L.top];
- }
+ while (L.top > oldtop + 1)
+ delete L.stack[--L.top];
};
const ERRORSTACKSIZE = luaconf.LUAI_MAXSTACK + 200;