From 539c4d254c75165a51d4a9cfd2a05342f503516a Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 27 Sep 2017 22:37:57 +1000 Subject: src/loadlib.js: Load code with Function to catch syntax errors before evaluation --- src/loadlib.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/loadlib.js') diff --git a/src/loadlib.js b/src/loadlib.js index acdf514..da60d0b 100644 --- a/src/loadlib.js +++ b/src/loadlib.js @@ -42,7 +42,15 @@ if (WEB) { xhr.send(); if (xhr.status >= 200 && xhr.status <= 299) { - return eval(xhr.response); + let func; + try { + func = Function(xhr.response); + } catch (e) { + lua.lua_pushstring(L, lua.to_luastring(`${e.name}: ${e.message}`)); + return null; + } + let res = func(); + return res; } else { lua.lua_pushstring(L, lua.to_luastring(`${xhr.status}: ${xhr.statusText}`)); return null; -- cgit v1.2.3-54-g00ecf