Fixed issue: #81
This commit is contained in:
Binary file not shown.
@@ -259,6 +259,9 @@ public class LuaClosure extends LuaFunction {
|
|||||||
// process instructions
|
// process instructions
|
||||||
try {
|
try {
|
||||||
for (; true; ++pc) {
|
for (; true; ++pc) {
|
||||||
|
if (Thread.currentThread().isInterrupted()) {
|
||||||
|
throw new LuaError("interrupted");
|
||||||
|
}
|
||||||
if (globals != null && globals.debuglib != null)
|
if (globals != null && globals.debuglib != null)
|
||||||
globals.debuglib.onInstruction( pc, v, top );
|
globals.debuglib.onInstruction( pc, v, top );
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ package org.luaj.vm2;
|
|||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
@@ -162,6 +163,32 @@ public class FragmentsTest extends TestSuite {
|
|||||||
"return ok\n");
|
"return ok\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInterruptedThreadStopsRunningClosure() throws Exception {
|
||||||
|
final Globals globals = JsePlatform.debugGlobals();
|
||||||
|
final LuaValue chunk = globals.load("while true do end", "interrupt.lua");
|
||||||
|
final AtomicReference<Throwable> thrown = new AtomicReference<Throwable>();
|
||||||
|
|
||||||
|
Thread t = new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
chunk.call();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
thrown.set(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, "luaj-interrupt-test");
|
||||||
|
t.start();
|
||||||
|
|
||||||
|
Thread.sleep(50);
|
||||||
|
t.interrupt();
|
||||||
|
t.join(2000);
|
||||||
|
|
||||||
|
assertFalse("lua thread should stop after interrupt", t.isAlive());
|
||||||
|
assertNotNull("expected LuaError from interrupt", thrown.get());
|
||||||
|
assertEquals(LuaError.class, thrown.get().getClass());
|
||||||
|
assertEquals("interrupted", thrown.get().getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
public void testLongIntegerLiteralPrecision() {
|
public void testLongIntegerLiteralPrecision() {
|
||||||
runFragment(
|
runFragment(
|
||||||
LuaValue.varargsOf(new LuaValue[] {
|
LuaValue.varargsOf(new LuaValue[] {
|
||||||
|
|||||||
Reference in New Issue
Block a user