diff options
author | daurnimator <quae@daurnimator.com> | 2017-06-19 00:54:11 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-06-19 00:54:11 +1000 |
commit | 5928a46812aa108d7388e5ad3ed0c9aa4b6d5a61 (patch) | |
tree | 71b1d216f5211623b96b17408ea5312e7aff0e86 /tests/test-suite | |
parent | 098ea04c2a85a15e621269a6f4b38d3a607f47d0 (diff) | |
download | fengari-5928a46812aa108d7388e5ad3ed0c9aa4b6d5a61.tar.gz fengari-5928a46812aa108d7388e5ad3ed0c9aa4b6d5a61.tar.bz2 fengari-5928a46812aa108d7388e5ad3ed0c9aa4b6d5a61.zip |
tests/test-suite: Fix checkpanic
Diffstat (limited to 'tests/test-suite')
-rw-r--r-- | tests/test-suite/api.js | 7 | ||||
-rw-r--r-- | tests/test-suite/ltests.js | 20 |
2 files changed, 13 insertions, 14 deletions
diff --git a/tests/test-suite/api.js b/tests/test-suite/api.js index a4fce37..8b59e9c 100644 --- a/tests/test-suite/api.js +++ b/tests/test-suite/api.js @@ -757,8 +757,7 @@ test("[test-suite] api: testing lua_to...", function (t) { }, "Lua program ran without error"); }); -// TODO: longjmp ? -test("[test-suite] api: testing panic function", { skip: true }, function (t) { +test("[test-suite] api: testing panic function", function (t) { let luaCode = ` do -- trivial error @@ -776,10 +775,12 @@ test("[test-suite] api: testing panic function", { skip: true }, function (t) { "bad argument #4 (string expected, got no value)") + --[[ TODO: T.totalmem -- memory error T.totalmem(T.totalmem()+10000) -- set low memory limit (+10k) assert(T.checkpanic("newuserdata 20000") == "not enough memory") T.totalmem(0) -- restore high limit + ]] -- stack error if not _soft then @@ -804,7 +805,7 @@ test("[test-suite] api: testing panic function", { skip: true }, function (t) { ltests.luaopen_tests(L); - lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode)); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Lua program loaded without error"); diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js index 4d53053..56a673c 100644 --- a/tests/test-suite/ltests.js +++ b/tests/test-suite/ltests.js @@ -662,11 +662,10 @@ const Chook = function(L, ar) { runJS(L, L, { script: scpt, offset: 0 }); /* run script from C_HOOK[L] */ }; -class Aux { +class Aux { constructor() { - this.jb = null; this.paniccode = null; - this.L = null; + this.L = null; } } @@ -674,20 +673,19 @@ class Aux { ** does a long-jump back to "main program". */ const panicback = function(L) { - let b = Aux(); + let b = new Aux(); lua.lua_checkstack(L, 1); /* open space for 'Aux' struct */ lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, lua.to_luastring("_jmpbuf", true)); /* get 'Aux' struct */ b = lua.lua_touserdata(L, -1); lua.lua_pop(L, 1); /* remove 'Aux' struct */ - runJS(b.L, L, b.paniccode); /* run optional panic code */ - longjmp(b.jb, 1); // TODO ? - return 1; /* to avoid warnings */ + runJS(b.L, L, { script: b.paniccode, offset: 0 }); /* run optional panic code */ + throw 1; }; const checkpanic = function(L) { let b = new Aux(); let code = lauxlib.luaL_checkstring(L, 1); - b.paniccode = lauxlib.luaL_optstring(L, 2, ""); + b.paniccode = lauxlib.luaL_optstring(L, 2, lua.to_luastring("", true)); b.L = L; let L1 = lua.lua_newstate(); /* create new state */ if (L1 === null) { /* error? */ @@ -697,10 +695,10 @@ const checkpanic = function(L) { lua.lua_atpanic(L1, panicback); /* set its panic function */ lua.lua_pushlightuserdata(L1, b); lua.lua_setfield(L1, lua.LUA_REGISTRYINDEX, lua.to_luastring("_jmpbuf", true)); /* store 'Aux' struct */ - if (setjmp(b.jb) === 0) { /* set jump buffer */ // TODO ? - runJS(L, L1, code); /* run code unprotected */ + try { /* set jump buffer */ + runJS(L, L1, { script: code, offset: 0 }); /* run code unprotected */ lua.lua_pushliteral(L, "no errors"); - } else { /* error handling */ + } catch (e) { /* error handling */ /* move error message to original state */ lua.lua_pushstring(L, lua.lua_tostring(L1, -1)); } |