feat: add input validation and stack trace filtering for Timer.sleep
Add type and range checks to Timer.sleep() in both C source and Wren implementation, aborting with descriptive errors for non-numeric or negative arguments. Introduce six new test files covering sleep with fibers, float durations, main fiber, zero milliseconds, negative values, and non-numeric input. Fix stack trace parsing in test runner to skip builtin library frames by iterating through error lines until a main-line match is found.
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
static const char* timerLibSource =
|
||||
"class Timer {\n"
|
||||
" static sleep(milliseconds) {\n"
|
||||
" if (!(milliseconds is Num)) Fiber.abort(\"Milliseconds must be a number.\")\n"
|
||||
" if (milliseconds < 0) Fiber.abort(\"Milliseconds cannot be negative.\")\n"
|
||||
" startTimer_(milliseconds, Fiber.current)\n"
|
||||
" Fiber.yield()\n"
|
||||
" }\n"
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "wren.h"
|
||||
|
||||
// TODO: Coherent naming scheme.
|
||||
char* timerGetSource();
|
||||
|
||||
WrenForeignMethodFn timerBindForeign(
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
class Timer {
|
||||
static sleep(milliseconds) {
|
||||
if (!(milliseconds is Num)) Fiber.abort("Milliseconds must be a number.")
|
||||
if (milliseconds < 0) Fiber.abort("Milliseconds cannot be negative.")
|
||||
startTimer_(milliseconds, Fiber.current)
|
||||
Fiber.yield()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user