diff --git a/src/ant.c b/src/ant.c index d631ea8..21aa1a9 100644 --- a/src/ant.c +++ b/src/ant.c @@ -5024,7 +5024,7 @@ static ant_value_t iter_close_iterator(ant_t *js, ant_value_t iterator) { ant_offset_t return_off = lkp_proto(js, iterator, "return", 6); if (return_off == 0) return js_mkundef(); ant_value_t return_method = propref_load(js, return_off); - if (vtype(return_method) != T_FUNC && vtype(return_method) != T_CFUNC) { + if (!is_callable(return_method)) { return js_mkerr(js, "iterator.return is not a function"); } return iter_call_noargs_with_this(js, iterator, return_method); @@ -5046,7 +5046,7 @@ static ant_value_t iter_foreach(ant_t *js, ant_value_t iterable, iter_callback_t if (next_off == 0) { return js_mkerr(js, "iterator.next is not a function"); } ant_value_t next_method = propref_load(js, next_off); - if (vtype(next_method) != T_FUNC && vtype(next_method) != T_CFUNC) { + if (!is_callable(next_method)) { return js_mkerr(js, "iterator.next is not a function"); } diff --git a/src/modules/symbol.c b/src/modules/symbol.c index 0870cda..654f67b 100644 --- a/src/modules/symbol.c +++ b/src/modules/symbol.c @@ -266,7 +266,7 @@ ant_value_t maybe_call_symbol_method( uint8_t mt = vtype(method); if (mt == T_UNDEF || mt == T_NULL) return js_mkundef(); - if (mt != T_FUNC && mt != T_CFUNC) { + if (!is_callable(method)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Symbol method is not callable"); } diff --git a/src/silver/glue.c b/src/silver/glue.c index 1d6ac79..fb79248 100644 --- a/src/silver/glue.c +++ b/src/silver/glue.c @@ -344,8 +344,7 @@ static ant_value_t jit_iter_advance_from_buf( ant_value_t next_method = iter_buf[1]; GC_ROOT_PIN(js, iterator); GC_ROOT_PIN(js, next_method); - uint8_t ft = vtype(next_method); - if (ft != T_FUNC && ft != T_CFUNC) { + if (!is_callable(next_method)) { GC_ROOT_RESTORE(js, root_mark); return js_mkerr(js, "iterator.next is not a function"); } @@ -388,8 +387,7 @@ void jit_helper_destructure_close( GC_ROOT_PIN(js, iterator); ant_value_t return_fn = js_getprop_fallback(js, iterator, "return"); GC_ROOT_PIN(js, return_fn); - uint8_t ft = vtype(return_fn); - if (ft == T_FUNC || ft == T_CFUNC) + if (is_callable(return_fn)) sv_vm_call(vm, js, return_fn, iterator, NULL, 0, NULL, false); } @@ -429,8 +427,7 @@ ant_value_t jit_helper_for_of( ant_value_t iter_fn = js_get_sym(js, iterable, get_iterator_sym()); GC_ROOT_PIN(js, iter_fn); - uint8_t ft = vtype(iter_fn); - if (ft != T_FUNC && ft != T_CFUNC) { + if (!is_callable(iter_fn)) { GC_ROOT_RESTORE(js, root_mark); return js_mkerr(js, "not iterable"); } diff --git a/src/silver/ops/iteration.h b/src/silver/ops/iteration.h index d221368..d9ab44e 100644 --- a/src/silver/ops/iteration.h +++ b/src/silver/ops/iteration.h @@ -261,8 +261,7 @@ static inline ant_value_t sv_iter_advance( default: { ant_value_t next_method = vm->stack[vm->sp - 2]; ant_value_t iterator = vm->stack[vm->sp - 3]; - uint8_t ft = vtype(next_method); - if (ft != T_FUNC && ft != T_CFUNC) + if (!is_callable(next_method)) return js_mkerr(js, "iterator.next is not a function"); ant_value_t result = sv_vm_call(vm, js, next_method, iterator, NULL, 0, NULL, false); if (is_err(result)) return result; @@ -304,8 +303,7 @@ static inline void sv_op_iter_close(sv_vm_t *vm, ant_t *js) { if (tag == SV_ITER_GENERIC) { ant_value_t iterator = vm->stack[vm->sp - 3]; ant_value_t return_fn = js_getprop_fallback(js, iterator, "return"); - uint8_t ft = vtype(return_fn); - if (ft == T_FUNC || ft == T_CFUNC) + if (is_callable(return_fn)) sv_vm_call(vm, js, return_fn, iterator, NULL, 0, NULL, false); } vm->sp -= 3; @@ -347,8 +345,7 @@ static inline ant_value_t sv_op_destructure_rest(sv_vm_t *vm, ant_t *js) { static inline ant_value_t sv_op_iter_call(sv_vm_t *vm, ant_t *js, uint8_t *ip) { ant_value_t method = vm->stack[vm->sp - 1]; ant_value_t iterator = vm->stack[vm->sp - 4]; - uint8_t ft = vtype(method); - if (ft != T_FUNC && ft != T_CFUNC) + if (!is_callable(method)) return js_mkerr(js, "iterator method is not callable"); ant_value_t result = sv_vm_call(vm, js, method, iterator, NULL, 0, NULL, false); if (is_err(result)) return result; @@ -364,8 +361,7 @@ static inline sv_await_result_t sv_op_await_iter_next(sv_vm_t *vm, ant_t *js) { }; ant_value_t next_method = vm->stack[vm->sp - 2]; ant_value_t iterator = vm->stack[vm->sp - 3]; - uint8_t ft = vtype(next_method); - if (ft != T_FUNC && ft != T_CFUNC) + if (!is_callable(next_method)) return (sv_await_result_t){ .state = SV_AWAIT_ERROR, .value = js_mkerr(js, "iterator.next is not a function"), .handoff = false }; ant_value_t result = sv_vm_call(vm, js, next_method, iterator, NULL, 0, NULL, false); if (is_err(result))