]> git.kaiwu.me - njs.git/commitdiff
Introduced njs_function_frame().
authorhongzhidao <hongzhidao@gmail.com>
Tue, 8 Jan 2019 00:41:40 +0000 (08:41 +0800)
committerhongzhidao <hongzhidao@gmail.com>
Tue, 8 Jan 2019 00:41:40 +0000 (08:41 +0800)
njs/njs_function.h
njs/njs_vm.c

index a0f57a1633bbe3e6baad899cec49525977150f16..f705716a5550b6bf2969a2a6641c120dae3d3a73 100644 (file)
@@ -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)
index 4475b261c829dc0e04299da150dec20c9f74609d..00f6d47f0f5ddf920658ee3fb909e3df0db29c22 100644 (file)
@@ -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));