Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/hx/cppia/CppiaFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,18 @@ void ScriptCallable::runFunction(CppiaCtx *ctx)
#ifdef CPPIA_JIT
if (compiled)
{
{
AutoFrame frame(ctx);
//printf("Running compiled code...\n");
compiled(ctx);
//printf("Done.\n");
}
if (ctx->exception)
{
Dynamic caught = ctx->exception;
ctx->exception = nullptr;
HX_STACK_DO_THROW(caught);
}
}
else
#endif
Expand Down Expand Up @@ -543,10 +551,18 @@ void ScriptCallable::runFunctionClosure(CppiaCtx *ctx)
#ifdef CPPIA_JIT
if (compiled)
{
{
AutoFrame frame(ctx);
//printf("Running compiled code...\n");
compiled(ctx);
//printf("Done.\n");
}
if (ctx->exception)
{
Dynamic caught = ctx->exception;
ctx->exception = nullptr;
HX_STACK_DO_THROW(caught);
}
}
else
#endif
Expand Down Expand Up @@ -747,7 +763,13 @@ class CppiaClosure : public hx::Object
AutoFrame frame(ctx);
function->compiled(ctx);
}
if (!ctx->exception)
if (ctx->exception)
{
Dynamic caught = ctx->exception;
ctx->exception = nullptr;
HX_STACK_DO_THROW(caught);
}

{
switch(function->returnType)
{
Expand Down
11 changes: 11 additions & 0 deletions test/cppia/Client.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ class ClientFoo implements IFoo {
}
}

class ClientThrower {

public static function boom():String {
throw "boom";
}

public static function fine():String {
return "still here";
}
}

class Client
{
public static var clientBool0 = true;
Expand Down
19 changes: 19 additions & 0 deletions test/cppia/cases/TestCommon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ class TestCommon extends Test {
Assert.equals(2, Common.callbackSet, 'Bad cppia closure');
}

@:depends(testStatus)
function testThrowReachesTheCaller() {
final cls = Type.resolveClass('ClientThrower');

if (Assert.notNull(cls, 'Unable to resolve ClientThrower')) {
var caught:String = null;

try {
Reflect.callMethod(null, Reflect.field(cls, 'boom'), []);
} catch (e:Dynamic) {
caught = Std.string(e);
}

Assert.equals('boom', caught, 'The throw did not reach the caller');
Assert.equals('still here', Std.string(Reflect.callMethod(null, Reflect.field(cls, 'fine'), [])),
'A later call answered null, so the exception was left on the context');
}
}

@:depends(testStatus)
function testInterfaceCalling() {
final obj : IFoo = Type.createInstance(Type.resolveClass('ClientFoo'), []);
Expand Down