void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
+nxt_inline njs_ret_t
+njs_function_frame(njs_vm_t *vm, njs_function_t *function,
+ const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
+ size_t reserve, nxt_bool_t ctor)
+{
+ if (function->native) {
+ return njs_function_native_frame(vm, function, this, args, nargs,
+ reserve, ctor);
+
+ } else {
+ return njs_function_lambda_frame(vm, function, this, args, nargs, ctor);
+ }
+}
+
+
nxt_inline njs_ret_t
njs_function_apply(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
function = value->data.u.function;
- if (!function->native) {
+ if (ctor) {
+ if (function->native) {
+ if (!function->ctor) {
+ njs_type_error(vm, "%s is not a constructor",
+ njs_type_string(value->type));
+ return NXT_ERROR;
+ }
- if (ctor) {
+ } else {
object = njs_function_new_object(vm, value);
if (nxt_slow_path(object == NULL)) {
return NXT_ERROR;
val.data.truth = 1;
this = &val;
}
-
- return njs_function_lambda_frame(vm, function, this, NULL,
- nargs, ctor);
}
- if (!ctor || function->ctor) {
- return njs_function_native_frame(vm, function, this, NULL,
- nargs, 0, ctor);
- }
-
- njs_type_error(vm, "%s is not a constructor",
- njs_type_string(value->type));
-
- return NXT_ERROR;
+ return njs_function_frame(vm, function, this, NULL, nargs, 0, ctor);
}
njs_type_error(vm, "%s is not a function", njs_type_string(value->type));