From c8d109ee3634ec8973338bdbf73dbaf3bd20afe5 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 27 Sep 2017 23:20:21 +1000 Subject: src/loadlib.js: Check that JS library returns expected type(s) --- src/loadlib.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/loadlib.js') 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; -- cgit v1.2.3-54-g00ecf