From da1592c025a505eb94ef05a0baa916b829df3b62 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 27 Sep 2017 23:27:40 +1000 Subject: src/loadlib.js: Invert condition so that code flows down --- src/loadlib.js | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/loadlib.js b/src/loadlib.js index 4116b0a..04314b7 100644 --- a/src/loadlib.js +++ b/src/loadlib.js @@ -43,31 +43,31 @@ if (WEB) { xhr.open("GET", path, false); xhr.send(); - if (xhr.status >= 200 && xhr.status <= 299) { - let code = xhr.response; - /* Add sourceURL comment to get path in debugger+tracebacks */ - if (!/\/\/[#@] sourceURL=/.test(code)) - code += " //# sourceURL=" + path; - let func; - try { - func = Function("fengari", code); - } catch (e) { - lua.lua_pushstring(L, lua.to_luastring(`${e.name}: ${e.message}`)); - return null; - } - let res = func(fengari); - if (typeof res === "function" || (typeof res === "object" && res !== null)) { - return res; - } else if (res === void 0) { /* assume library added symbols to global environment */ - return window; - } else { - lua.lua_pushstring(L, lua.to_luastring(`library returned unexpected type (${typeof res})`)); - return null; - } - } else { + if (xhr.status < 200 || xhr.status >= 300) { lua.lua_pushstring(L, lua.to_luastring(`${xhr.status}: ${xhr.statusText}`)); return null; } + + let code = xhr.response; + /* Add sourceURL comment to get path in debugger+tracebacks */ + if (!/\/\/[#@] sourceURL=/.test(code)) + code += " //# sourceURL=" + path; + let func; + try { + func = Function("fengari", code); + } catch (e) { + lua.lua_pushstring(L, lua.to_luastring(`${e.name}: ${e.message}`)); + return null; + } + let res = func(fengari); + if (typeof res === "function" || (typeof res === "object" && res !== null)) { + return res; + } else if (res === void 0) { /* assume library added symbols to global environment */ + return window; + } else { + lua.lua_pushstring(L, lua.to_luastring(`library returned unexpected type (${typeof res})`)); + return null; + } }; } else { const pathlib = require('path'); -- cgit v1.2.3-70-g09d2