Fix wrenAbortFiber does not work inside of foreign class allocator

This commit is contained in:
Matus Novak
2019-09-17 19:43:53 +02:00
parent 740c365597
commit f91586a71a
3 changed files with 24 additions and 0 deletions

View File

@ -1198,6 +1198,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
CASE_CODE(FOREIGN_CONSTRUCT):
ASSERT(IS_CLASS(stackStart[0]), "'this' should be a class.");
createForeign(vm, fiber, stackStart);
if (wrenHasError(fiber)) RUNTIME_ERROR();
DISPATCH();
CASE_CODE(CLOSURE):

View File

@ -82,6 +82,13 @@ static void resourceFinalize(void* data)
finalized++;
}
static void badClassAllocate(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);
wrenSetSlotString(vm, 0, "Something went wrong");
wrenAbortFiber(vm, 0);
}
WrenForeignMethodFn foreignClassBindMethod(const char* signature)
{
if (strcmp(signature, "static ForeignClass.finalized") == 0) return apiFinalized;
@ -114,4 +121,10 @@ void foreignClassBindClass(
methods->finalize = resourceFinalize;
return;
}
if (strcmp(className, "BadClass") == 0)
{
methods->allocate = badClassAllocate;
return;
}
}

View File

@ -75,3 +75,13 @@ resources.clear()
System.gc()
System.print(ForeignClass.finalized) // expect: 3
// Class that aborts fiber
foreign class BadClass {
construct new() {}
}
error = Fiber.new {
BadClass.new()
}.try()
System.print(error) // expect: Something went wrong