From 4f415e5ca594c5b60e6fa6315b69acb41273ee7e Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Tue, 18 Apr 2017 11:19:22 +0200 Subject: Fixed debug.getinfo bad name lookup --- src/ldblib.js | 2 +- src/ldebug.js | 14 ++++++++------ tests/lua-tests | 2 +- tests/lua.js | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ldblib.js b/src/ldblib.js index 5c78724..dfc7819 100644 --- a/src/ldblib.js +++ b/src/ldblib.js @@ -153,7 +153,7 @@ const db_getinfo = function(L) { settabsi(L, lua.to_luastring("nparams"), ar.nparams); settabsb(L, lua.to_luastring("isvararg"), ar.isvararg); if (options.indexOf(char['n']) > - 1) { - settabss(L, lua.to_luastring("name"), ar.name ? ar.name.value : null); + settabss(L, lua.to_luastring("name"), ar.name ? ar.name : null); settabss(L, lua.to_luastring("namewhat"), ar.namewhat ? ar.namewhat : null); } if (options.indexOf(char['t']) > - 1) diff --git a/src/ldebug.js b/src/ldebug.js index 0a0e22c..d769500 100644 --- a/src/ldebug.js +++ b/src/ldebug.js @@ -79,10 +79,11 @@ const lua_getstack = function(L, level, ar) { return status; }; +// TODO: returns TValue or String array ? const upvalname = function(p, uv) { assert(uv < p.upvalues.length); let s = p.upvalues[uv].name; - if (s === null) return "?".charCodeAt(0); + if (s === null) return ["?".charCodeAt(0)]; return s; }; @@ -301,8 +302,8 @@ const kname = function(p, pc, c) { /* else no reasonable name found */ } else { /* 'c' is a register */ let what = getobjname(p, pc, c); /* search for 'c' */ - if (what && what.name[0] === 'c'.charCodeAt(0)) { - return what; + if (what && what.funcname[0] === 'c'.charCodeAt(0)) { /* found a constant name? */ + return what; /* 'name' already filled */ } /* else no reasonable name found */ } @@ -393,8 +394,9 @@ const getobjname = function(p, lastpc, reg) { let k = i.C; /* key index */ let t = i.B; /* table index */ let vn = op === 'OP_GETTABLE' ? lfunc.luaF_getlocalname(p, t + 1, pc) : upvalname(p, t); - r.name = kname(p, pc, k); - r.funcname = vn && vn === lua.to_luastring("_ENV") ? lua.to_luastring("global") : lua.to_luastring("field"); + vn = vn ? vn.jsstring() : null; + r.name = kname(p, pc, k).name; + r.funcname = vn && vn === "_ENV" ? lua.to_luastring("global") : lua.to_luastring("field"); return r; } case 'OP_GETUPVAL': { @@ -414,7 +416,7 @@ const getobjname = function(p, lastpc, reg) { } case 'OP_SELF': { let k = i.C; - r.name = kname(p, pc, k); + r.name = kname(p, pc, k).name; r.funcname = lua.to_luastring("method"); return r; } diff --git a/tests/lua-tests b/tests/lua-tests index 21fb72d..9e0d0bf 160000 --- a/tests/lua-tests +++ b/tests/lua-tests @@ -1 +1 @@ -Subproject commit 21fb72de668a3307958d6a6d71770ae2118ba1d3 +Subproject commit 9e0d0bfb5de8cb0534a13c19f23377db62b53d57 diff --git a/tests/lua.js b/tests/lua.js index c230dea..30a9c98 100644 --- a/tests/lua.js +++ b/tests/lua.js @@ -15,7 +15,7 @@ test('constructs.lua', function (t) { return dofile("tests/lua-tests/constructs.lua") `, L; - t.plan(1); + t.plan(2); t.doesNotThrow(function () { @@ -27,11 +27,11 @@ test('constructs.lua', function (t) { }, "Lua program loaded without error"); - // t.doesNotThrow(function () { + t.doesNotThrow(function () { lapi.lua_call(L, 0, -1); - // }, "Lua program ran without error"); + }, "Lua program ran without error"); }); -- cgit v1.2.3-70-g09d2