forked from Mirror/wren
Reset API stack a fiber is aborted from wrenCall().
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
#include "handle.h"
|
||||
#include "lists.h"
|
||||
#include "new_vm.h"
|
||||
#include "reset_stack_after_call_abort.h"
|
||||
#include "reset_stack_after_foreign_construct.h"
|
||||
#include "slots.h"
|
||||
|
||||
@ -87,8 +88,15 @@ static WrenForeignClassMethods bindForeignClass(
|
||||
}
|
||||
|
||||
static void afterLoad(WrenVM* vm) {
|
||||
if (strstr(testName, "/call.wren") != NULL) callRunTests(vm);
|
||||
if (strstr(testName, "/reset_stack_after_foreign_construct.wren") != NULL)
|
||||
if (strstr(testName, "/call.wren") != NULL)
|
||||
{
|
||||
callRunTests(vm);
|
||||
}
|
||||
else if (strstr(testName, "/reset_stack_after_call_abort.wren") != NULL)
|
||||
{
|
||||
resetStackAfterCallAbortRunTests(vm);
|
||||
}
|
||||
else if (strstr(testName, "/reset_stack_after_foreign_construct.wren") != NULL)
|
||||
{
|
||||
resetStackAfterForeignConstructRunTests(vm);
|
||||
}
|
||||
|
||||
28
test/api/reset_stack_after_call_abort.c
Normal file
28
test/api/reset_stack_after_call_abort.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wren.h"
|
||||
|
||||
void resetStackAfterCallAbortRunTests(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenGetVariable(vm, "main", "Test", 0);
|
||||
WrenHandle* testClass = wrenGetSlotHandle(vm, 0);
|
||||
|
||||
WrenHandle* abortFiber = wrenMakeCallHandle(vm, "abortFiber()");
|
||||
WrenHandle* afterConstruct = wrenMakeCallHandle(vm, "afterAbort(_,_)");
|
||||
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotHandle(vm, 0, testClass);
|
||||
wrenCall(vm, abortFiber);
|
||||
|
||||
wrenEnsureSlots(vm, 3);
|
||||
wrenSetSlotHandle(vm, 0, testClass);
|
||||
wrenSetSlotDouble(vm, 1, 1.0);
|
||||
wrenSetSlotDouble(vm, 2, 2.0);
|
||||
wrenCall(vm, afterConstruct);
|
||||
|
||||
wrenReleaseHandle(vm, testClass);
|
||||
wrenReleaseHandle(vm, abortFiber);
|
||||
wrenReleaseHandle(vm, afterConstruct);
|
||||
}
|
||||
3
test/api/reset_stack_after_call_abort.h
Normal file
3
test/api/reset_stack_after_call_abort.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include "wren.h"
|
||||
|
||||
void resetStackAfterCallAbortRunTests(WrenVM* vm);
|
||||
14
test/api/reset_stack_after_call_abort.wren
Normal file
14
test/api/reset_stack_after_call_abort.wren
Normal file
@ -0,0 +1,14 @@
|
||||
// Regression test.
|
||||
//
|
||||
// If you invoked some code with wrenCall() and that code aborted the current
|
||||
// fiber, it did not reset the API stack. If you tried to immediately reuse the
|
||||
// API stack by calling wrenCall(), it would be in a broken state.
|
||||
class Test {
|
||||
static abortFiber() {
|
||||
Fiber.abort("Abort!") // expect handled runtime error: Abort!
|
||||
}
|
||||
|
||||
static afterAbort(a, b) {
|
||||
System.print(a + b) // expect: 3
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "foreign_class.h"
|
||||
#include "wren.h"
|
||||
|
||||
static void counterAllocate(WrenVM* vm)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user