summaryrefslogtreecommitdiff
path: root/src/ldo.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-22 17:48:16 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-22 18:46:26 +1000
commit20efa5c3b00e3a82ab135ec4a1f5d0563912aefe (patch)
tree628fa40d294e85e3e3f4d866fa49f6bd45d963ef /src/ldo.js
parent9294302fc069e0b8d893521fa552b5ed66601024 (diff)
downloadfengari-20efa5c3b00e3a82ab135ec4a1f5d0563912aefe.tar.gz
fengari-20efa5c3b00e3a82ab135ec4a1f5d0563912aefe.tar.bz2
fengari-20efa5c3b00e3a82ab135ec4a1f5d0563912aefe.zip
Add luaD_checkstack calls
Diffstat (limited to 'src/ldo.js')
-rw-r--r--src/ldo.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/ldo.js b/src/ldo.js
index 1036ce5..5243f1f 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -63,6 +63,11 @@ const luaD_growstack = function(L, n) {
}
};
+const luaD_checkstack = function(L, n) {
+ if (L.stack.length - L.top <= n)
+ luaD_growstack(L, n);
+};
+
/*
** Prepares a function call: checks the stack, creates a new CallInfo
** entry, fills in the relevant information, calls hook if needed.
@@ -78,11 +83,13 @@ const luaD_precall = function(L, off, nresults) {
case CT.LUA_TLCF: {
let f = func.type === CT.LUA_TCCL ? func.value.f : func.value;
+ luaD_checkstack(L, defs.LUA_MINSTACK);
let ci = lstate.luaE_extendCI(L);
ci.funcOff = off;
ci.nresults = nresults;
ci.func = func;
ci.top = L.top + defs.LUA_MINSTACK;
+ assert(ci.top <= L.stack.length);
ci.callstatus = 0;
if (L.hookmask & defs.LUA_MASKCALL)
luaD_hook(L, defs.LUA_HOOKCALL, -1);
@@ -96,11 +103,11 @@ const luaD_precall = function(L, off, nresults) {
return true;
}
case CT.LUA_TLCL: {
+ let base;
let p = func.value.p;
let n = L.top - off - 1;
let fsize = p.maxstacksize;
- let base;
-
+ luaD_checkstack(L, fsize);
if (p.is_vararg) {
base = adjust_varargs(L, p, n);
} else {
@@ -619,6 +626,7 @@ module.exports.SParser = SParser;
module.exports.adjust_varargs = adjust_varargs;
module.exports.luaD_call = luaD_call;
module.exports.luaD_callnoyield = luaD_callnoyield;
+module.exports.luaD_checkstack = luaD_checkstack;
module.exports.luaD_growstack = luaD_growstack;
module.exports.luaD_hook = luaD_hook;
module.exports.luaD_pcall = luaD_pcall;