fix: close upvalues before fiber completion and add closure tests

Move upvalue closing logic from the else branch to before the fiber completion check
to ensure upvalues are properly closed when a fiber finishes. Add test cases for
closure behavior across fiber yields and for Fiber.create argument type validation.
This commit is contained in:
Bob Nystrom
2014-02-14 15:16:56 +00:00
parent 00239d37b2
commit 04cb19c605
4 changed files with 34 additions and 13 deletions
+25
View File
@@ -0,0 +1,25 @@
var fiber
var closure
{
var a = "before"
fiber = Fiber.create(fn {
IO.print(a)
Fiber.yield
a = "after"
Fiber.yield
IO.print(a)
a = "final"
})
closure = fn {
IO.print(a)
}
}
fiber.run // expect: before
closure.call // expect: before
fiber.run
closure.call // expect: after
fiber.run // expect: after
closure.call // expect: final
+1
View File
@@ -0,0 +1 @@
var fiber = Fiber.create("not fn") // expect runtime error: Argument must be a function.
-3
View File
@@ -7,6 +7,3 @@ fiber.run // expect: fiber
IO.print("after") // expect: after
// TODO: Test handles error if fiber tries to run itself.
// TODO: Test create is passed right argument type.
// TODO: Test closing over stuff in fiber function.
// TODO: Test running a finished fiber.