From 6d68023f27f14e8e72bf84de1dc81dac0dd71a80 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 12 Nov 2017 16:33:19 +1100 Subject: src/lauxlib.js: Catch read errors on read rather than fstat-ing then hoping --- src/lauxlib.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/lauxlib.js') 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); } -- cgit v1.2.3-54-g00ecf