From e9a61ecb5cd11c839d545ecc1d7e632662b7ff73 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Mon, 22 Feb 2016 12:26:42 +0300 Subject: [PATCH] Functions rearrangement. --- njs/njs_function.c | 150 ++++++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/njs/njs_function.c b/njs/njs_function.c index d0c1e280..9e24f07f 100644 --- a/njs/njs_function.c +++ b/njs/njs_function.c @@ -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". */ -- 2.47.3