From: Igor Sysoev Date: Mon, 22 Feb 2016 09:39:31 +0000 (+0300) Subject: Common parts of Function.call() and Function.apply() have X-Git-Tag: 0.1.0~55 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=93922be26d480b67e9e937107f67af31e6293b6a;p=njs.git Common parts of Function.call() and Function.apply() have been merged. --- diff --git a/njs/njs_function.c b/njs/njs_function.c index 9e24f07f..3112d33e 100644 --- a/njs/njs_function.c +++ b/njs/njs_function.c @@ -19,6 +19,10 @@ #include +static njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function, + njs_value_t *this, njs_value_t *args, nxt_uint_t nargs, njs_index_t retval); + + njs_function_t * njs_function_alloc(njs_vm_t *vm) { @@ -312,7 +316,6 @@ static njs_ret_t njs_function_prototype_call(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t retval) { - njs_ret_t ret; njs_value_t *this; njs_function_t *function; @@ -332,30 +335,7 @@ njs_function_prototype_call(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, function = args[0].data.u.function; - if (function->native) { - - ret = njs_function_native_frame(vm, function, this, &args[2], - nargs, 0, 0); - if (nxt_slow_path(ret != NJS_OK)) { - return ret; - } - - /* Skip the "call" method frame. */ - vm->frame->previous->skip = 1; - - return NJS_APPLIED; - } - - ret = njs_function_frame(vm, function, this, &args[2], nargs, 0); - - if (nxt_slow_path(ret != NXT_OK)) { - return ret; - } - - /* Skip the "call" method frame. */ - vm->frame->previous->skip = 1; - - return njs_function_call(vm, retval, sizeof(njs_vmcode_function_call_t)); + return njs_function_activate(vm, function, this, &args[2], nargs, retval); } @@ -363,7 +343,6 @@ static njs_ret_t njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t retval) { - njs_ret_t ret; njs_array_t *array; njs_value_t *this; njs_function_t *function; @@ -392,6 +371,22 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, nargs = 0; } + return njs_function_activate(vm, function, this, args, nargs, retval); + +type_error: + + vm->exception = &njs_exception_type_error; + + return NXT_ERROR; +} + + +static njs_ret_t +njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this, + njs_value_t *args, nxt_uint_t nargs, njs_index_t retval) +{ + njs_ret_t ret; + if (function->native) { ret = njs_function_native_frame(vm, function, this, args, nargs, 0, 0); @@ -415,12 +410,6 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, vm->frame->previous->skip = 1; return njs_function_call(vm, retval, sizeof(njs_vmcode_function_call_t)); - -type_error: - - vm->exception = &njs_exception_type_error; - - return NXT_ERROR; }