]> git.kaiwu.me - njs.git/commitdiff
Improved njs_function_native_call().
authorhongzhidao <hongzhidao@gmail.com>
Fri, 26 Apr 2019 11:57:54 +0000 (19:57 +0800)
committerhongzhidao <hongzhidao@gmail.com>
Fri, 26 Apr 2019 11:57:54 +0000 (19:57 +0800)
njs/njs_function.c
njs/njs_function.h
njs/njs_vm.c

index 6d36f9ff19b695a77ebaafaf25ceb85d615e49c6..a4bbdba3fe6fc9248ec35e7030f0738b9bda9179 100644 (file)
@@ -566,7 +566,7 @@ njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval,
 njs_ret_t
 njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
     njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
-    njs_index_t retval)
+    njs_index_t retval, u_char *return_address)
 {
     njs_ret_t           ret;
     njs_value_t         *value;
@@ -617,6 +617,8 @@ njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
             *value = vm->retval;
         }
 
+        vm->current = return_address;
+
         njs_function_frame_free(vm, frame);
 
         return NXT_OK;
index e07578a9eb029b4d2db99b91bb510f9b1f8600ed..1d7b388bf3fc7bfec2e93d973f12c94f28d71633 100644 (file)
@@ -173,7 +173,7 @@ njs_ret_t njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval,
     u_char *return_address);
 njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
     njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
-    njs_index_t retval);
+    njs_index_t retval, u_char *return_address);
 void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
 
 
index c28cb88de284335fc9c95edee11c7cc629ab5d3b..0e9675d0fc3fa56da61a6098352a8679dff2dd49 100644 (file)
@@ -2047,7 +2047,8 @@ njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
             ret = njs_function_native_call(vm, function->u.native,
                                            frame->arguments,
                                            function->args_types, frame->nargs,
-                                           (njs_index_t) retval);
+                                           (njs_index_t) retval,
+                                           return_address);
         }
 
     } else {
@@ -2055,16 +2056,7 @@ njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
                                        return_address);
     }
 
-    switch (ret) {
-    case NXT_OK:
-        return sizeof(njs_vmcode_function_call_t);
-
-    case NJS_APPLIED:
-        return 0;
-
-    default:
-        return ret;
-    }
+    return (ret == NJS_APPLIED) ? 0 : ret;
 }
 
 
@@ -2292,31 +2284,18 @@ const njs_vmcode_generic_t  njs_continuation_nexus[] = {
 static njs_ret_t
 njs_vmcode_continuation(njs_vm_t *vm, njs_value_t *invld1, njs_value_t *invld2)
 {
-    u_char              *return_address;
     njs_ret_t           ret;
     njs_native_frame_t  *frame;
     njs_continuation_t  *cont;
 
     frame = vm->top_frame;
-
     cont = njs_vm_continuation(vm);
-    return_address = cont->return_address;
 
     ret = njs_function_native_call(vm, cont->function, frame->arguments,
                                    cont->args_types, frame->nargs,
-                                   cont->retval);
+                                   cont->retval, cont->return_address);
 
-    switch (ret) {
-    case NXT_OK:
-        vm->current = return_address;
-        /* Fall through. */
-
-    case NJS_APPLIED:
-        return 0;
-
-    default:
-        return ret;
-    }
+    return (ret == NJS_APPLIED) ? 0 : ret;
 }