]> git.kaiwu.me - njs.git/commitdiff
nJSVM current instruction pointer is updated now in
authorIgor Sysoev <igor@sysoev.ru>
Mon, 25 Jan 2016 12:15:00 +0000 (15:15 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 25 Jan 2016 12:15:00 +0000 (15:15 +0300)
njs_function_call().

njs/njs_array.c
njs/njs_function.c
njs/njs_function.h
njs/njs_vm.c

index 9b4e6f65013071215effd01cd4e6374255107a89..8425c3e3ba7362771b2cdfb5a45f27fb585b95b3 100644 (file)
@@ -732,8 +732,8 @@ njs_array_prototype_for_each(njs_vm_t *vm, njs_param_t *param)
     n = njs_array_next(array->start, ++n, next->length);
     next->index = n;
 
-    if (n > 0) {
-        vm->current -= sizeof(njs_vmcode_function_call_t);
+    if (n < 0) {
+        vm->current += sizeof(njs_vmcode_function_call_t);
     }
 
     nargs = param->nargs;
@@ -810,8 +810,6 @@ njs_array_prototype_some(njs_vm_t *vm, njs_param_t *param)
 
     func = (nargs != 0) ? &args[0] : (njs_value_t *) &njs_value_void;
 
-    vm->current -= sizeof(njs_vmcode_function_call_t);
-
     return njs_function_apply(vm, func, &p);
 }
 
@@ -876,8 +874,6 @@ njs_array_prototype_every(njs_vm_t *vm, njs_param_t *param)
 
     func = (nargs != 0) ? &args[0] : (njs_value_t *) &njs_value_void;
 
-    vm->current -= sizeof(njs_vmcode_function_call_t);
-
     return njs_function_apply(vm, func, &p);
 }
 
index 59912702516bc3fb9c6871b15e032e6c9f3b9742..8eacc35ac3e2ed81be99ed5c7ffa7d1fedb4b9e0 100644 (file)
@@ -139,7 +139,7 @@ njs_function_apply(njs_vm_t *vm, njs_value_t *value, njs_param_t *param)
         if (nxt_fast_path(ret == NXT_OK)) {
             vm->retval = njs_value_void;
 
-            return njs_function_call(vm, param->retval);
+            return njs_function_call(vm, param->retval, 0);
         }
     }
 
@@ -207,7 +207,7 @@ njs_function_frame(njs_vm_t *vm, njs_function_t *function, njs_param_t *param,
 
 
 nxt_noinline njs_ret_t
-njs_function_call(njs_vm_t *vm, njs_index_t retval)
+njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
 {
     njs_frame_t     *frame;
     njs_function_t  *function;
@@ -217,7 +217,7 @@ njs_function_call(njs_vm_t *vm, njs_index_t retval)
     frame->retval = retval;
 
     function = frame->native.u.function;
-    frame->native.u.return_address = vm->current;
+    frame->native.u.return_address = vm->current + advance;
     vm->current = function->u.lambda->u.start;
 
     frame->prev_arguments = vm->scopes[NJS_SCOPE_ARGUMENTS];
@@ -312,7 +312,8 @@ njs_function_prototype_call(njs_vm_t *vm, njs_param_t *param)
 
     call = (njs_vmcode_function_call_t *) vm->current;
 
-    return njs_function_call(vm, call->retval);
+    return njs_function_call(vm, call->retval,
+                             sizeof(njs_vmcode_function_call_t));
 }
 
 
@@ -378,7 +379,8 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_param_t *param)
 
         code = (njs_vmcode_function_call_t *) vm->current;
 
-        return njs_function_call(vm, code->retval);
+        return njs_function_call(vm, code->retval,
+                                 sizeof(njs_vmcode_function_call_t));
     }
 
     return NXT_ERROR;
index 7fa31ad5baa9bc6541e5607d27540343f11ea4a1..3dc32e6c3cb35de459086476f5a88e16bd2ce6b5 100644 (file)
@@ -123,7 +123,7 @@ njs_value_t *njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
     njs_vmcode_t *code);
 njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
     njs_param_t *param, nxt_bool_t ctor);
-njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval);
+njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
 
 extern const njs_object_init_t  njs_function_constructor_init;
 extern const njs_object_init_t  njs_function_prototype_init;
index 3db49495c1a529720f4319da090e2893c6e158a8..10efda320c9bfa054521d58d585efa798c8814b8 100644 (file)
@@ -2230,16 +2230,14 @@ njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
     njs_native_frame_t          *frame, *previous, *skip;
     njs_vmcode_function_call_t  *call;
 
-    call = (njs_vmcode_function_call_t *) vm->current;
-    /* Update code pointer here to store it as return address in call frame. */
-    vm->current += sizeof(njs_vmcode_function_call_t);
-
     if (!vm->frame->u.function->native) {
-        (void) njs_function_call(vm, (njs_index_t) retval);
+        (void) njs_function_call(vm, (njs_index_t) retval,
+                                 sizeof(njs_vmcode_function_call_t));
         return 0;
     }
 
     param.retval = (njs_index_t) retval;
+    call = (njs_vmcode_function_call_t *) vm->current;
     param.nargs = call->code.nargs - 1;
     args = vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS];
     param.args = args;
@@ -2287,12 +2285,19 @@ njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
          */
         *retval = vm->retval;
 
+        ret = sizeof(njs_vmcode_function_call_t);
+
     } else if (ret == NJS_APPLIED) {
         /* A user-defined method has been prepared to run. */
         ret = 0;
 
     } else if (ret == NXT_AGAIN) {
+        /*
+         * Revert nJSVM current address, execution will
+         * continue on the same function after resumption.
+         */
         vm->frame->reentrant = 1;
+        vm->current -= sizeof(njs_vmcode_function_call_t);
     }
 
     return ret;