From: hongzhidao Date: Tue, 8 Jan 2019 00:41:40 +0000 (+0800) Subject: Introduced njs_function_frame(). X-Git-Tag: 0.2.8~78 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=4a90cb61d94aa72f09b0fc175b64c111b23860b5;p=njs.git Introduced njs_function_frame(). --- diff --git a/njs/njs_function.h b/njs/njs_function.h index a0f57a16..f705716a 100644 --- a/njs/njs_function.h +++ b/njs/njs_function.h @@ -179,6 +179,21 @@ njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native, 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) diff --git a/njs/njs_vm.c b/njs/njs_vm.c index 4475b261..00f6d47f 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -1864,9 +1864,15 @@ njs_function_frame_create(njs_vm_t *vm, njs_value_t *value, 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; @@ -1877,20 +1883,9 @@ njs_function_frame_create(njs_vm_t *vm, njs_value_t *value, 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));