aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-11-12 16:33:19 +1100
committerdaurnimator <quae@daurnimator.com>2017-11-12 16:33:19 +1100
commit6d68023f27f14e8e72bf84de1dc81dac0dd71a80 (patch)
tree220f975504893f41962ab02995287f9b11c31398
parent94a6480244bb874e802a61eb0acf6b87a3046494 (diff)
downloadfengari-6d68023f27f14e8e72bf84de1dc81dac0dd71a80.tar.gz
fengari-6d68023f27f14e8e72bf84de1dc81dac0dd71a80.tar.bz2
fengari-6d68023f27f14e8e72bf84de1dc81dac0dd71a80.zip
src/lauxlib.js: Catch read errors on read rather than fstat-ing then hoping
-rw-r--r--src/lauxlib.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index ab8a8a0..16a509f 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -793,7 +793,13 @@ if (WEB) {
getc = function(lf) {
let b = new Buffer(1);
- let bytes = fs.readSync(lf.f, b, 0, 1, lf.pos);
+ let bytes;
+ try {
+ bytes = fs.readSync(lf.f, b, 0, 1, lf.pos);
+ } catch(e) {
+ lf.err = e;
+ return null;
+ }
lf.pos += bytes;
return bytes > 0 ? b.readUInt8() : null;
};
@@ -809,8 +815,6 @@ if (WEB) {
try {
let jsfilename = lua.to_jsstring(filename);
lf.f = fs.openSync(jsfilename, "r");
- if (!fs.fstatSync(lf.f).isFile())
- throw new Error(`${jsfilename} is not a readable file`);
} catch (e) {
return errfile(L, "open", fnameindex, e);
}