feat: add Fiber.abort() method to abort fiber with error message

Implements a new `Fiber.abort()` static method that allows a fiber to terminate with a custom error message string. The method validates that the argument is a string, then returns a PRIM_ERROR to abort the current fiber. Includes three test cases: basic abort with error message retrieval via `fiber.try`, aborting the main fiber with a runtime error, and type checking that non-string arguments produce an appropriate error message.
This commit is contained in:
Bob Nystrom
2015-01-01 18:40:14 +00:00
parent d287d084ed
commit 0f5eb1885e
4 changed files with 19 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
var fiber = new Fiber {
Fiber.abort("Error message.")
}
IO.print(fiber.try) // expect: Error message.
IO.print(fiber.isDone) // expect: true
IO.print(fiber.error) // expect: Error message.
+1
View File
@@ -0,0 +1 @@
Fiber.abort("Abort!") // expect runtime error: Abort!
+1
View File
@@ -0,0 +1 @@
Fiber.abort(123) // expect runtime error: Error message must be a string.