From 4627bb4b5c3ccc8431fbba68a78efd50ebb13909 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 13 Feb 2017 11:35:50 +0100 Subject: JSHint --- src/ldo.js | 11 ++++------- src/lfunc.js | 5 +++-- src/lopcodes.js | 4 ++-- src/ltm.js | 13 +++++++------ src/lundump.js | 6 +++--- src/lvm.js | 39 +++++++++++++++++++-------------------- 6 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/ldo.js b/src/ldo.js index 85bd3d3..26a4a0f 100644 --- a/src/ldo.js +++ b/src/ldo.js @@ -21,10 +21,8 @@ const luaD_precall = function(L, off, nresults) { switch(func.type) { case CT.LUA_TCCL: // JS function ? throw new Error("LUA_TCCL not implemeted yet"); - break; case CT.LUA_TLCF: // still JS function ? throw new Error("LUA_TLCF not implemeted yet"); - break; case CT.LUA_TLCL: { let p = func.p; let n = L.top - off - 1; @@ -63,7 +61,6 @@ const luaD_precall = function(L, off, nresults) { ci.callstatus = lstate.CIST_LUA; return false; - break; } default: tryfuncTM(L, off, func); @@ -84,7 +81,7 @@ const moveresults = function(L, firstResult, res, nres, wanted) { case 0: break; case 1: { - if (nres == 0) + if (nres === 0) firstResult = nil; L.stack[res] = L.stack[firstResult]; break; @@ -136,13 +133,13 @@ const adjust_varargs = function(L, p, actual) { const tryfuncTM = function(L, off, func) { let tm = ltm.luaT_gettmbyobj(L, func, TMS.TM_CALL); if (!tm.ttisfunction(tm)) - throw new Error("__call metatable member is not a function") // TODO: luaG_typeerror + throw new Error("__call metatable member is not a function"); // TODO: luaG_typeerror /* Open a hole inside the stack at 'func' */ - for (p = L.top; p > off; p--) + for (let p = L.top; p > off; p--) L.stack[p] = L.stack[p-1]; L.top++; /* slot ensured by caller */ L.stack[off] = tm; /* tag method is the new function to be called */ -} +}; module.exports = { nil: nil, diff --git a/src/lfunc.js b/src/lfunc.js index 2e0a70a..ac09c5e 100644 --- a/src/lfunc.js +++ b/src/lfunc.js @@ -1,5 +1,6 @@ /*jshint esversion: 6 */ "use strict"; +const assert = require('assert'); class Proto { @@ -47,7 +48,7 @@ class UpVal { return this.v !== null; } -}; +} const findupval = function(L, level) { let pp = L.openupval; @@ -85,7 +86,7 @@ const luaF_close = function(L, level) { uv.v = null; } } -} +}; module.exports = { Proto: Proto, diff --git a/src/lopcodes.js b/src/lopcodes.js index 383e9c5..6bdfd7c 100644 --- a/src/lopcodes.js +++ b/src/lopcodes.js @@ -78,10 +78,10 @@ const ISK = function (x) { const INDEXK = function (r) { return r & ~BITRK; -} +}; /* number of list items to accumulate before a SETLIST instruction */ -const LFIELDS_PER_FLUSH = 50 +const LFIELDS_PER_FLUSH = 50; module.exports = { OpCodes: OpCodes, diff --git a/src/ltm.js b/src/ltm.js index 5d93e28..e08c511 100644 --- a/src/ltm.js +++ b/src/ltm.js @@ -50,7 +50,7 @@ const luaT_callTM = function(L, f, p1, p2, p3, hasres) { if (!hasres) /* no result? 'p3' is third argument */ L.stack[L.top++] = p3; /* 3rd argument */ - if (ci.callstatus & lstate.CIST_LUA) + if (L.ci.callstatus & lstate.CIST_LUA) ldo.luaD_call(L, func, hasres); else ldo.luaD_callnoyield(L, func, hasres); @@ -67,20 +67,20 @@ const luaT_callbinTM = function(L, p1, p2, res, event) { if (tm.ttisnil()) return false; luaT_callTM(L, tm, p1, p2, res, 1); return true; -} +}; const luaT_trybinTM = function(L, p1, p2, res, event) { if (!luaT_gettmbyobj(L, p1, p2, res, event)) { throw new Error("TM error"); // TODO: luaG_error } -} +}; const luaT_callorderTM = function(L, p1, p2, event) { if (!luaT_callbinTM(L, p2, p2, L.top, event)) return -1; else return !l_isfalse(L.stack[L.top]) ? 1 : 0; -} +}; const luaT_gettmbyobj = function(L, o, event) { let mt; @@ -88,12 +88,13 @@ const luaT_gettmbyobj = function(L, o, event) { case CT.LUA_TTABLE: case CT.LUA_TTUSERDATA: mt = o.value.metatable; + break; default: // TODO: mt = G(L)->mt[ttnov(o)]; } return mt ? mt.__index(mt, event) : ldo.nil; -} +}; module.exports = { TMS: TMS, @@ -102,4 +103,4 @@ module.exports = { luaT_trybinTM: luaT_trybinTM, luaT_callorderTM: luaT_callorderTM, luaT_gettmbyobj: luaT_gettmbyobj -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/lundump.js b/src/lundump.js index b104e32..67867bb 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -105,11 +105,11 @@ class BytecodeParser { /* creates a mask with 'n' 0 bits at position 'p' */ static MASK0(n, p) { - return (~MASK1(n,p)); + return (~BytecodeParser.MASK1(n,p)); } readInstruction() { - let ins = new DataView(new Buffer(this.instructionSize)) + let ins = new DataView(new Buffer(this.instructionSize)); for (let i = 0; i < this.instructionSize; i++) ins.setUint8(i, this.readByte()); @@ -210,7 +210,7 @@ class BytecodeParser { varname: this.readString(), startpc: this.readInt(), endpc: this.readInt() - } + }; console.log(` f.locvars[${i}].varname = ${f.locvars[i].varname} diff --git a/src/lvm.js b/src/lvm.js index 17a9033..7be6b01 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -57,7 +57,7 @@ const luaV_execute = function(L) { ci = L.ci; cl = ci.func; k = cl.p.k; - base = ci.u.l.base + base = ci.u.l.base; i = ci.u.l.savedpc[ci.pcOff++]; ra = RA(L, base, i); @@ -353,7 +353,7 @@ const luaV_execute = function(L) { } else if (numberop !== false) { L.stack[ra] = new TValue(CT.LUA_TNUMFLT, -op.value); } else { - ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_UNM); + ltm.luaT_trybinTM(L, op, op, ra, TMS.TM_UNM); base = ci.u.l.base; } break; @@ -388,7 +388,7 @@ const luaV_execute = function(L) { break; } case "OP_EQ": { - if (luaV_equalobj(RKB(L, base, k, i), RKC(L, base, k, i)) !== i.A) + if (luaV_equalobj(L, RKB(L, base, k, i), RKC(L, base, k, i)) !== i.A) ci.pcOff++; else donextjump(L, ci); @@ -396,7 +396,7 @@ const luaV_execute = function(L) { break; } case "OP_LT": { - if (luaV_lessthan(RKB(L, base, k, i), RKC(L, base, k, i)) !== i.A) + if (luaV_lessthan(L, RKB(L, base, k, i), RKC(L, base, k, i)) !== i.A) ci.pcOff++; else donextjump(L, ci); @@ -404,7 +404,7 @@ const luaV_execute = function(L) { break; } case "OP_LE": { - if (luaV_lessequal(RKB(L, base, k, i), RKC(L, base, k, i)) !== i.A) + if (luaV_lessequal(L, RKB(L, base, k, i), RKC(L, base, k, i)) !== i.A) ci.pcOff++; else donextjump(L, ci); @@ -490,7 +490,6 @@ const luaV_execute = function(L) { if (b) L.top = ci.top; continue newframe; - break; } case "OP_FORLOOP": { if (L.stack[ra].ttisinteger()) { /* integer loop? */ @@ -555,7 +554,7 @@ const luaV_execute = function(L) { break; } case "OP_TFORCALL": { - let cb = ra + 3 /* call base */ + let cb = ra + 3; /* call base */ L.stack[cb + 2] = L.stack[ra + 2]; L.stack[cb + 1] = L.stack[ra + 1]; L.stack[cb] = L.stack[ra]; @@ -647,7 +646,7 @@ const luaV_execute = function(L) { const dojump = function(L, ci, i, e) { let a = i.A; - if (a != 0) lfunc.luaF_close(L, ci.u.l.base + a - 1); + if (a !== 0) lfunc.luaF_close(L, ci.u.l.base + a - 1); ci.pcOff += i.sBx + e; }; @@ -656,20 +655,20 @@ const donextjump = function(L, ci) { }; -const luaV_lessthan = function(l, r) { +const luaV_lessthan = function(L, l, r) { if (l.ttisnumber() && r.ttisnumber()) return LTnum(l, r); else if (l.ttisstring() && r.ttisstring()) return l_strcmp(l, r) < 0; else { - res = ltm.luatT_callorderTM(L, l, r, TMS.TM_LT); + let res = ltm.luatT_callorderTM(L, l, r, TMS.TM_LT); if (res < 0) throw new Error("TM order error"); // TODO: luaG_ordererror return res; } }; -const luaV_lessequal = function(l, r) { +const luaV_lessequal = function(L, l, r) { let res; if (l.ttisnumber() && r.ttisnumber()) @@ -682,21 +681,21 @@ const luaV_lessequal = function(l, r) { return res; } - L.ci.callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */ + L.ci.callstatus |= lstate.CIST_LEQ; /* mark it is doing 'lt' for 'le' */ res = ltm.luatT_callorderTM(L, l, r, TMS.TM_LT); - L.ci.callstatus ^= CIST_LEQ; /* clear mark */ + L.ci.callstatus ^= lstate.CIST_LEQ; /* clear mark */ if (res < 0) throw new Error("TM order error"); // TODO: luaG_ordererror return res === 1; }; -const luaV_equalobj = function(t1, t2) { +const luaV_equalobj = function(L, t1, t2) { if (t1.ttype() !== t2.ttype()) { /* not the same variant? */ if (t1.ttnov() !== t2.ttnov() || t1.ttnov() !== CT.LUA_NUMBER) return 0; /* only numbers can be equal with different variants */ else { /* two numbers with different variants */ /* compare them as integers */ - return Math.floor(t1.value) === Math.floor(t2.value) // TODO: tointeger + return Math.floor(t1.value) === Math.floor(t2.value); // TODO: tointeger } } @@ -723,7 +722,7 @@ const luaV_equalobj = function(t1, t2) { tm = ltm.luaT_gettmbyobj(L, t1, TMS.TM_EQ); if (tm.ttisnil()) tm = ltm.luaT_gettmbyobj(L, t2, TMS.TM_EQ); - break + break; default: return t1.value === t2.value ? 1 : 0; } @@ -756,7 +755,7 @@ const forlimit = function(obj, step) { casted: true, stopnow: stopnow, ilimit: ilimit - } + }; }; /* @@ -848,7 +847,7 @@ const l_strcmp = function(ls, rs) { }; const l_isfalse = function(o) { - return o.ttisnil() || (o.ttisboolean() && o.value === false) + return o.ttisnil() || (o.ttisboolean() && o.value === false); }; /* @@ -884,7 +883,7 @@ const luaV_objlen = function(L, ra, rb) { */ const luaV_concat = function(L, total) { assert(total >= 2); -} +}; /* ** Check appropriate error for stack overflow ("regular" overflow or @@ -897,7 +896,7 @@ const stackerror = function(L) { if (L.nCcalls === llimit.LUAI_MAXCCALLS) throw new Error("JS stack overflow"); else if (L.nCcalls >= llimit.LUAI_MAXCCALLS + (llimit.LUAI_MAXCCALLS >> 3)) /* error while handing stack error */ - throw new Error("stack overflow") // TODO: luaD_throw(L, LUA_ERRERR); + throw new Error("stack overflow"); // TODO: luaD_throw(L, LUA_ERRERR); }; /* -- cgit v1.2.3-70-g09d2