Validate number comparison operand types.

This commit is contained in:
Bob Nystrom
2014-01-21 07:44:11 -08:00
parent 7b1b39bd2c
commit 635d695083
5 changed files with 8 additions and 9 deletions

View File

@ -436,35 +436,30 @@ DEF_NATIVE(num_divide)
DEF_NATIVE(num_mod)
{
if (!validateNum(vm, args, 1, "Right operand")) return PRIM_ERROR;
if (!IS_NUM(args[1])) RETURN_NULL;
RETURN_NUM(fmod(AS_NUM(args[0]), AS_NUM(args[1])));
}
DEF_NATIVE(num_lt)
{
// TODO: Error on wrong argument type.
if (!IS_NUM(args[1])) RETURN_NULL;
if (!validateNum(vm, args, 1, "Right operand")) return PRIM_ERROR;
RETURN_BOOL(AS_NUM(args[0]) < AS_NUM(args[1]));
}
DEF_NATIVE(num_gt)
{
// TODO: Error on wrong argument type.
if (!IS_NUM(args[1])) RETURN_NULL;
if (!validateNum(vm, args, 1, "Right operand")) return PRIM_ERROR;
RETURN_BOOL(AS_NUM(args[0]) > AS_NUM(args[1]));
}
DEF_NATIVE(num_lte)
{
// TODO: Error on wrong argument type.
if (!IS_NUM(args[1])) RETURN_NULL;
if (!validateNum(vm, args, 1, "Right operand")) return PRIM_ERROR;
RETURN_BOOL(AS_NUM(args[0]) <= AS_NUM(args[1]));
}
DEF_NATIVE(num_gte)
{
// TODO: Error on wrong argument type.
if (!IS_NUM(args[1])) RETURN_NULL;
if (!validateNum(vm, args, 1, "Right operand")) return PRIM_ERROR;
RETURN_BOOL(AS_NUM(args[0]) >= AS_NUM(args[1]));
}

View File

@ -0,0 +1 @@
1 >= false // expect runtime error: Right operand must be a number.

View File

@ -0,0 +1 @@
1 > false // expect runtime error: Right operand must be a number.

View File

@ -0,0 +1 @@
1 <= false // expect runtime error: Right operand must be a number.

View File

@ -0,0 +1 @@
1 < false // expect runtime error: Right operand must be a number.