mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 06:08:41 +01:00
Fix wrenAbortFiber does not work inside of foreign class allocator
This commit is contained in:
@ -1198,6 +1198,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
|||||||
CASE_CODE(FOREIGN_CONSTRUCT):
|
CASE_CODE(FOREIGN_CONSTRUCT):
|
||||||
ASSERT(IS_CLASS(stackStart[0]), "'this' should be a class.");
|
ASSERT(IS_CLASS(stackStart[0]), "'this' should be a class.");
|
||||||
createForeign(vm, fiber, stackStart);
|
createForeign(vm, fiber, stackStart);
|
||||||
|
if (wrenHasError(fiber)) RUNTIME_ERROR();
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
|
|
||||||
CASE_CODE(CLOSURE):
|
CASE_CODE(CLOSURE):
|
||||||
|
|||||||
@ -82,6 +82,13 @@ static void resourceFinalize(void* data)
|
|||||||
finalized++;
|
finalized++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void badClassAllocate(WrenVM* vm)
|
||||||
|
{
|
||||||
|
wrenEnsureSlots(vm, 1);
|
||||||
|
wrenSetSlotString(vm, 0, "Something went wrong");
|
||||||
|
wrenAbortFiber(vm, 0);
|
||||||
|
}
|
||||||
|
|
||||||
WrenForeignMethodFn foreignClassBindMethod(const char* signature)
|
WrenForeignMethodFn foreignClassBindMethod(const char* signature)
|
||||||
{
|
{
|
||||||
if (strcmp(signature, "static ForeignClass.finalized") == 0) return apiFinalized;
|
if (strcmp(signature, "static ForeignClass.finalized") == 0) return apiFinalized;
|
||||||
@ -114,4 +121,10 @@ void foreignClassBindClass(
|
|||||||
methods->finalize = resourceFinalize;
|
methods->finalize = resourceFinalize;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(className, "BadClass") == 0)
|
||||||
|
{
|
||||||
|
methods->allocate = badClassAllocate;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,3 +75,13 @@ resources.clear()
|
|||||||
|
|
||||||
System.gc()
|
System.gc()
|
||||||
System.print(ForeignClass.finalized) // expect: 3
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user