summaryrefslogtreecommitdiff
path: root/src/loadlib.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-09-27 23:20:21 +1000
committerdaurnimator <quae@daurnimator.com>2017-09-27 23:20:21 +1000
commitc8d109ee3634ec8973338bdbf73dbaf3bd20afe5 (patch)
treed33d9f7d6b09c4a96d3b241d25a336ba0f1a5e35 /src/loadlib.js
parentfcfa9dafbd6cc57c9259d0f0ae5f3aaa32ddd8d1 (diff)
downloadfengari-c8d109ee3634ec8973338bdbf73dbaf3bd20afe5.tar.gz
fengari-c8d109ee3634ec8973338bdbf73dbaf3bd20afe5.tar.bz2
fengari-c8d109ee3634ec8973338bdbf73dbaf3bd20afe5.zip
src/loadlib.js: Check that JS library returns expected type(s)
Diffstat (limited to 'src/loadlib.js')
-rw-r--r--src/loadlib.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/loadlib.js b/src/loadlib.js
index e7626ab..7a50556 100644
--- a/src/loadlib.js
+++ b/src/loadlib.js
@@ -56,7 +56,12 @@ if (WEB) {
return null;
}
let res = func(fengari);
- return res;
+ if (typeof res === "function" || (typeof res === "object" && res !== null)) {
+ return res;
+ } else {
+ lua.lua_pushstring(L, lua.to_luastring(`library returned unexpected type (${typeof res})`));
+ return null;
+ }
} else {
lua.lua_pushstring(L, lua.to_luastring(`${xhr.status}: ${xhr.statusText}`));
return null;