[njs] Introduced njs_function_frame().

Dmitry Volyntsev xeioex at nginx.com
Thu Jan 10 17:25:02 UTC 2019


details:   https://hg.nginx.org/njs/rev/f62736ecfa8f
branches:  
changeset: 724:f62736ecfa8f
user:      hongzhidao <hongzhidao at gmail.com>
date:      Tue Jan 08 08:41:40 2019 +0800
description:
Introduced njs_function_frame().

diffstat:

 njs/njs_function.h |  15 +++++++++++++++
 njs/njs_vm.c       |  25 ++++++++++---------------
 2 files changed, 25 insertions(+), 15 deletions(-)

diffs (69 lines):

diff -r ecf08b8a7dbe -r f62736ecfa8f njs/njs_function.h
--- a/njs/njs_function.h	Tue Jan 08 07:04:24 2019 +0800
+++ b/njs/njs_function.h	Tue Jan 08 08:41:40 2019 +0800
@@ -180,6 +180,21 @@ void njs_function_frame_free(njs_vm_t *v
 
 
 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 -r ecf08b8a7dbe -r f62736ecfa8f njs/njs_vm.c
--- a/njs/njs_vm.c	Tue Jan 08 07:04:24 2019 +0800
+++ b/njs/njs_vm.c	Tue Jan 08 08:41:40 2019 +0800
@@ -1864,9 +1864,15 @@ njs_function_frame_create(njs_vm_t *vm, 
 
         function = value->data.u.function;
 
-        if (!function->native) {
-
-            if (ctor) {
+        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;
+                }
+
+            } 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, 
                 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));


More information about the nginx-devel mailing list