]> git.kaiwu.me - njs.git/commitdiff
Functions rearrangement.
authorIgor Sysoev <igor@sysoev.ru>
Mon, 22 Feb 2016 09:26:42 +0000 (12:26 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 22 Feb 2016 09:26:42 +0000 (12:26 +0300)
njs/njs_function.c

index d0c1e280f18ef1559f8af073d3be2ee5c2abbe4f..9e24f07fd816d8d17c723a3495f0b4f399b79e7b 100644 (file)
@@ -92,6 +92,73 @@ njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
 }
 
 
+nxt_noinline njs_ret_t
+njs_function_frame(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
+    njs_value_t *args, nxt_uint_t nargs, nxt_bool_t ctor)
+{
+    size_t              size;
+    nxt_uint_t          n, max_args;
+    njs_value_t         *value, *bound;
+    njs_frame_t         *frame;
+    njs_native_frame_t  *native_frame;
+
+    max_args = nxt_max(nargs, function->u.lambda->nargs);
+
+    size = NJS_FRAME_SIZE
+           + (function->args_offset + max_args) * sizeof(njs_value_t)
+           + function->u.lambda->local_size;
+
+    native_frame = njs_function_frame_alloc(vm, size);
+    if (nxt_slow_path(native_frame == NULL)) {
+        return NXT_ERROR;
+    }
+
+    native_frame->function = function;
+    native_frame->nargs = nargs;
+    native_frame->ctor = ctor;
+
+    value = (njs_value_t *) ((u_char *) native_frame + NJS_FRAME_SIZE);
+
+    bound = function->bound;
+
+    if (bound == NULL) {
+        *value++ = *this;
+
+    } else {
+        n = function->args_offset;
+
+        do {
+            *value++ = *bound++;
+            n--;
+        } while (n != 0);
+    }
+
+    native_frame->arguments = value;
+    vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = value;
+
+    if (args != NULL) {
+        while (nargs != 0) {
+            *value++ = *args++;
+            max_args--;
+            nargs--;
+        }
+    }
+
+    while (max_args != 0) {
+        *value++ = njs_value_void;
+        max_args--;
+    }
+
+    frame = (njs_frame_t *) native_frame;
+    frame->local = value;
+
+    memcpy(frame->local, function->u.lambda->local_scope,
+           function->u.lambda->local_size);
+
+    return NXT_OK;
+}
+
+
 nxt_noinline njs_native_frame_t *
 njs_function_frame_alloc(njs_vm_t *vm, size_t size)
 {
@@ -131,14 +198,6 @@ njs_function_frame_alloc(njs_vm_t *vm, size_t size)
 }
 
 
-njs_ret_t
-njs_function_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
-    njs_index_t unused)
-{
-    return NXT_ERROR;
-}
-
-
 nxt_noinline njs_ret_t
 njs_function_apply(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
     nxt_uint_t nargs, njs_index_t retval)
@@ -183,73 +242,6 @@ njs_function_apply(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
 }
 
 
-nxt_noinline njs_ret_t
-njs_function_frame(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
-    njs_value_t *args, nxt_uint_t nargs, nxt_bool_t ctor)
-{
-    size_t              size;
-    nxt_uint_t          n, max_args;
-    njs_value_t         *value, *bound;
-    njs_frame_t         *frame;
-    njs_native_frame_t  *native_frame;
-
-    max_args = nxt_max(nargs, function->u.lambda->nargs);
-
-    size = NJS_FRAME_SIZE
-           + (function->args_offset + max_args) * sizeof(njs_value_t)
-           + function->u.lambda->local_size;
-
-    native_frame = njs_function_frame_alloc(vm, size);
-    if (nxt_slow_path(native_frame == NULL)) {
-        return NXT_ERROR;
-    }
-
-    native_frame->function = function;
-    native_frame->nargs = nargs;
-    native_frame->ctor = ctor;
-
-    value = (njs_value_t *) ((u_char *) native_frame + NJS_FRAME_SIZE);
-
-    bound = function->bound;
-
-    if (bound == NULL) {
-        *value++ = *this;
-
-    } else {
-        n = function->args_offset;
-
-        do {
-            *value++ = *bound++;
-            n--;
-        } while (n != 0);
-    }
-
-    native_frame->arguments = value;
-    vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = value;
-
-    if (args != NULL) {
-        while (nargs != 0) {
-            *value++ = *args++;
-            max_args--;
-            nargs--;
-        }
-    }
-
-    while (max_args != 0) {
-        *value++ = njs_value_void;
-        max_args--;
-    }
-
-    frame = (njs_frame_t *) native_frame;
-    frame->local = value;
-
-    memcpy(frame->local, function->u.lambda->local_scope,
-           function->u.lambda->local_size);
-
-    return NXT_OK;
-}
-
-
 nxt_noinline njs_ret_t
 njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
 {
@@ -277,6 +269,14 @@ njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
 }
 
 
+njs_ret_t
+njs_function_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+    njs_index_t unused)
+{
+    return NXT_ERROR;
+}
+
+
 static const njs_object_prop_t  njs_function_constructor_properties[] =
 {
     /* Function.name == "Function". */