1
0
forked from Mirror/wren

Reset API stack a fiber is aborted from wrenCall().

This commit is contained in:
Bob Nystrom
2016-11-01 08:40:16 -07:00
parent 51e50e6cc4
commit b9f53f71fb
8 changed files with 68 additions and 7 deletions

View File

@ -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);
}

View 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);
}

View File

@ -0,0 +1,3 @@
#include "wren.h"
void resetStackAfterCallAbortRunTests(WrenVM* vm);

View 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
}
}

View File

@ -1,7 +1,7 @@
#include <stdio.h>
#include <string.h>
#include "foreign_class.h"
#include "wren.h"
static void counterAllocate(WrenVM* vm)
{