aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-04-27 01:56:56 +1000
committerdaurnimator <quae@daurnimator.com>2017-04-27 01:56:56 +1000
commit0ad47e19d91dbfc04f890cdbbd09f7cf9f3e9d5f (patch)
tree355aa8bdb75c6c6771284f5133a5c107f5c09475 /src
parent37249336464af98800a7ed0b6ec21dc76b6effe9 (diff)
downloadfengari-0ad47e19d91dbfc04f890cdbbd09f7cf9f3e9d5f.tar.gz
fengari-0ad47e19d91dbfc04f890cdbbd09f7cf9f3e9d5f.tar.bz2
fengari-0ad47e19d91dbfc04f890cdbbd09f7cf9f3e9d5f.zip
Add a couple of asserts to catch common errors
Diffstat (limited to 'src')
-rw-r--r--src/ldo.js1
-rw-r--r--src/llex.js1
2 files changed, 2 insertions, 0 deletions
diff --git a/src/ldo.js b/src/ldo.js
index 9b845e7..fa59e0b 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -77,6 +77,7 @@ const luaD_precall = function(L, off, nresults) {
luaD_hook(L, defs.LUA_HOOKCALL, -1);
let n = f(L); /* do the actual call */
+ assert(typeof n == "number" && n >= 0 && n==n|0, "invalid return value from JS function (expected integer)");
assert(n < L.top - L.ci.funcOff, "not enough elements in the stack");
luaD_poscall(L, ci, L.top - n, n);
diff --git a/src/llex.js b/src/llex.js
index da15b2f..703db49 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -500,6 +500,7 @@ const llex = function(ls, seminfo) {
ls.buff.buffer = [];
for (;;) {
+ assert(typeof ls.current == "number");
switch (ls.current) {
case char['\n']: case char['\r']: { /* line breaks */
inclinenumber(ls);