aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-09-27 22:37:57 +1000
committerdaurnimator <quae@daurnimator.com>2017-09-27 22:37:57 +1000
commit539c4d254c75165a51d4a9cfd2a05342f503516a (patch)
treea0fb6af1ce8c315e5e119fd8d82ce4998f9c4532 /src
parent3728f550e1d8dc56b603b92debdc5f1a374a888f (diff)
downloadfengari-539c4d254c75165a51d4a9cfd2a05342f503516a.tar.gz
fengari-539c4d254c75165a51d4a9cfd2a05342f503516a.tar.bz2
fengari-539c4d254c75165a51d4a9cfd2a05342f503516a.zip
src/loadlib.js: Load code with Function to catch syntax errors before evaluation
Diffstat (limited to 'src')
-rw-r--r--src/loadlib.js10
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;