aboutsummaryrefslogtreecommitdiff
path: root/src/lauxlib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-28 11:36:00 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-28 11:40:31 +0200
commit8173e639527cffc583c9c6ad6e7fc0d43429ab50 (patch)
tree0fc1cb51dbeb813f48fca03716088e0ecf61a989 /src/lauxlib.js
parentbaa9730a961ab2d1810a3093f63e2c66241a6b72 (diff)
parent183768f08070003691f206ac16cb2310a7b4fa90 (diff)
downloadfengari-8173e639527cffc583c9c6ad6e7fc0d43429ab50.tar.gz
fengari-8173e639527cffc583c9c6ad6e7fc0d43429ab50.tar.bz2
fengari-8173e639527cffc583c9c6ad6e7fc0d43429ab50.zip
Merge remote-tracking branch 'daurnimator/stack-modification-work' into test-suite
Diffstat (limited to 'src/lauxlib.js')
-rw-r--r--src/lauxlib.js41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index b14379c..0672c14 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -654,6 +654,7 @@ if (!WEB) {
this.f = null; /* file being read */
this.buff = new Buffer(1024); /* area for reading file */
this.pos = 0; /* current position in file */
+ this.err = void 0;
}
}
@@ -665,7 +666,12 @@ if (!WEB) {
lf.n = 0; /* no more pre-read characters */
} else { /* read a block from file */
lf.buff.fill(0);
- bytes = fs.readSync(lf.f, lf.buff, 0, lf.buff.length, lf.pos); /* read block */
+ try {
+ bytes = fs.readSync(lf.f, lf.buff, 0, lf.buff.length, lf.pos); /* read block */
+ } catch(e) {
+ lf.err = e;
+ bytes = 0;
+ }
lf.pos += bytes;
}
if (bytes > 0)
@@ -743,25 +749,24 @@ if (!WEB) {
return errfile(L, "open", fnameindex, e);
}
}
-
- try {
- let com = skipcomment(lf);
- /* check for signature first, as we don't want to add line number corrections in binary case */
- if (com.c === lua.LUA_SIGNATURE.charCodeAt(0) && filename) { /* binary file? */
- /* no need to re-open in node.js */
- } else if (com.skipped) { /* read initial portion */
- lf.buff[lf.n++] = '\n'.charCodeAt(0); /* add line to correct line numbers */
- }
- if (com.c !== null)
- lf.buff[lf.n++] = com.c; /* 'c' is the first character of the stream */
- let status = lua.lua_load(L, getF, lf, lua.lua_tostring(L, -1), mode);
- if (filename) fs.closeSync(lf.f); /* close file (even in case of errors) */
- lua.lua_remove(L, fnameindex);
- return status;
- } catch (err) {
+ let com = skipcomment(lf);
+ /* check for signature first, as we don't want to add line number corrections in binary case */
+ if (com.c === lua.LUA_SIGNATURE.charCodeAt(0) && filename) { /* binary file? */
+ /* no need to re-open in node.js */
+ } else if (com.skipped) { /* read initial portion */
+ lf.buff[lf.n++] = '\n'.charCodeAt(0); /* add line to correct line numbers */
+ }
+ if (com.c !== null)
+ lf.buff[lf.n++] = com.c; /* 'c' is the first character of the stream */
+ let status = lua.lua_load(L, getF, lf, lua.lua_tostring(L, -1), mode);
+ let readstatus = lf.err;
+ if (filename) try { fs.closeSync(lf.f); } catch(e) {} /* close file (even in case of errors) */
+ if (readstatus) {
lua.lua_settop(L, fnameindex); /* ignore results from 'lua_load' */
- return errfile(L, "read", fnameindex, err);
+ return errfile(L, "read", fnameindex, readstatus);
}
+ lua.lua_remove(L, fnameindex);
+ return status;
};
const luaL_loadfile = function(L, filename) {