From 5928a46812aa108d7388e5ad3ed0c9aa4b6d5a61 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 19 Jun 2017 00:54:11 +1000 Subject: tests/test-suite: Fix checkpanic --- tests/test-suite/ltests.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'tests/test-suite/ltests.js') 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)); } -- cgit v1.2.3-54-g00ecf