summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-12-28 18:05:00 +1100
committerdaurnimator <quae@daurnimator.com>2017-12-28 20:25:12 +1100
commit2fcd2a4b326f386a3689e40f7f717496cd03e72e (patch)
treebf9ec8488d4a0e9f62a023256c640b2dc4717501 /src
parent746e9017b3b3989e501968c19f6fa82f831004c0 (diff)
downloadfengari-2fcd2a4b326f386a3689e40f7f717496cd03e72e.tar.gz
fengari-2fcd2a4b326f386a3689e40f7f717496cd03e72e.tar.bz2
fengari-2fcd2a4b326f386a3689e40f7f717496cd03e72e.zip
src/lauxlib.js: synchronous xhr is allowed in workers. use arraybuffer reponse type where possible
Diffstat (limited to 'src')
-rw-r--r--src/lauxlib.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index 5687242..51c5749 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -746,16 +746,22 @@ if (typeof process === "undefined") {
throw new Error("Can't read stdin in the browser");
} else {
lua.lua_pushfstring(L, lua.to_luastring("@%s"), filename);
-
let path = lua.to_uristring(filename);
let xhr = new XMLHttpRequest();
xhr.open("GET", path, false);
- // TODO: find a way to load bytes instead of js string
+ /* XXX: Synchronous xhr in main thread always returns a js string
+ Additionally, some browsers make console noise if you even attempt to set responseType
+ */
+ if (typeof window === "undefined") {
+ xhr.responseType = "arraybuffer";
+ }
xhr.send();
-
if (xhr.status >= 200 && xhr.status <= 299) {
- /* TODO: Synchronous xhr alway return a js string */
- lf.f = lua.to_luastring(xhr.response);
+ if (typeof xhr.response === "string") {
+ lf.f = lua.to_luastring(xhr.response);
+ } else {
+ lf.f = new Uint8Array(xhr.response);
+ }
} else {
lf.err = xhr.status;
return errfile(L, "open", fnameindex, { message: `${xhr.status}: ${xhr.statusText}` });