diff options
author | daurnimator <quae@daurnimator.com> | 2017-09-27 22:37:57 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-09-27 22:37:57 +1000 |
commit | 539c4d254c75165a51d4a9cfd2a05342f503516a (patch) | |
tree | a0fb6af1ce8c315e5e119fd8d82ce4998f9c4532 | |
parent | 3728f550e1d8dc56b603b92debdc5f1a374a888f (diff) | |
download | fengari-539c4d254c75165a51d4a9cfd2a05342f503516a.tar.gz fengari-539c4d254c75165a51d4a9cfd2a05342f503516a.tar.bz2 fengari-539c4d254c75165a51d4a9cfd2a05342f503516a.zip |
src/loadlib.js: Load code with Function to catch syntax errors before evaluation
-rw-r--r-- | src/loadlib.js | 10 |
1 files changed, 9 insertions, 1 deletions
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; |