Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # HG changeset patch
- # User hongzhidao <hongzhidao@gmail.com>
- # Date 1546891911 -28800
- # Node ID 91b36548e0b136d95b504b8da1cff9405fcadbac
- # Parent c3f59a9933a0e62f02d4a1f7a027b156766361e0
- Introduced njs_function_frame_activate.
- diff -r c3f59a9933a0 -r 91b36548e0b1 njs/njs.c
- --- a/njs/njs.c Tue Jan 08 04:04:02 2019 +0800
- +++ b/njs/njs.c Tue Jan 08 04:11:51 2019 +0800
- @@ -464,48 +464,20 @@
- u_char *current;
- njs_ret_t ret;
- njs_value_t *this;
- - njs_continuation_t *cont;
- -
- - static const njs_vmcode_stop_t stop[] = {
- - { .code = { .operation = njs_vmcode_stop,
- - .operands = NJS_VMCODE_1OPERAND,
- - .retval = NJS_VMCODE_NO_RETVAL },
- - .retval = NJS_INDEX_GLOBAL_RETVAL },
- - };
- this = (njs_value_t *) &njs_value_void;
- current = vm->current;
- +
- + vm->current = (u_char *) njs_continuation_nexus;
- - if (function->native) {
- - ret = njs_function_native_frame(vm, function, this, &args[0],
- - nargs, NJS_CONTINUATION_SIZE, 0);
- - if (ret != NJS_OK) {
- - return NJS_ERROR;
- - }
- + ret = njs_function_frame_activate(vm, function, this, args, nargs,
- + NJS_INDEX_GLOBAL_RETVAL,
- + sizeof(njs_vmcode_generic_t));
- - cont = njs_vm_continuation(vm);
- -
- - cont->function = function->u.native;
- - cont->args_types = function->args_types;
- - cont->retval = NJS_INDEX_GLOBAL_RETVAL;
- -
- - cont->return_address = (u_char *) stop;
- - vm->current = (u_char *) njs_continuation_nexus;
- -
- - } else {
- - ret = njs_function_frame(vm, function, this, args, nargs, 0);
- - if (nxt_slow_path(ret != NXT_OK)) {
- - return ret;
- - }
- -
- - vm->current = (u_char *) stop;
- -
- - ret = njs_function_call(vm, NJS_INDEX_GLOBAL_RETVAL, 0);
- - if (nxt_slow_path(ret == NXT_ERROR)) {
- - return ret;
- - }
- - }
- + if (nxt_slow_path(ret == NXT_ERROR)) {
- + return ret;
- + }
- ret = njs_vmcode_interpreter(vm);
- diff -r c3f59a9933a0 -r 91b36548e0b1 njs/njs_function.c
- --- a/njs/njs_function.c Tue Jan 08 04:04:02 2019 +0800
- +++ b/njs/njs_function.c Tue Jan 08 04:11:51 2019 +0800
- @@ -978,9 +978,9 @@
- }
- -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
- +njs_function_frame_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
- + const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval, size_t advance)
- {
- njs_ret_t ret;
- njs_continuation_t *cont;
- @@ -992,17 +992,13 @@
- return ret;
- }
- - /* Skip the "call/apply" method frame. */
- - vm->top_frame->previous->skip = 1;
- -
- cont = njs_vm_continuation(vm);
- cont->function = function->u.native;
- cont->args_types = function->args_types;
- cont->retval = retval;
- - cont->return_address = vm->current
- - + sizeof(njs_vmcode_function_call_t);
- + cont->return_address = vm->current + advance;
- vm->current = (u_char *) njs_continuation_nexus;
- return NJS_APPLIED;
- @@ -1014,10 +1010,26 @@
- return ret;
- }
- + return njs_function_call(vm, retval, advance);
- +}
- +
- +
- +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;
- +
- + ret = njs_function_frame_activate(vm, function, this, args, nargs, retval,
- + sizeof(njs_vmcode_function_call_t));
- + if (nxt_slow_path(ret == NXT_ERROR)) {
- + return ret;
- + }
- +
- /* Skip the "call/apply" method frame. */
- vm->top_frame->previous->skip = 1;
- - return njs_function_call(vm, retval, sizeof(njs_vmcode_function_call_t));
- + return NJS_APPLIED;
- }
- diff -r c3f59a9933a0 -r 91b36548e0b1 njs/njs_function.h
- --- a/njs/njs_function.h Tue Jan 08 04:04:02 2019 +0800
- +++ b/njs/njs_function.h Tue Jan 08 04:11:51 2019 +0800
- @@ -170,6 +170,9 @@
- njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- nxt_bool_t ctor);
- +njs_ret_t njs_function_frame_activate(njs_vm_t *vm, njs_function_t *function,
- + njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- + njs_index_t retval, size_t advance);
- njs_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
- void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
- njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
- diff -r c3f59a9933a0 -r 91b36548e0b1 njs/njs_vm.c
- --- a/njs/njs_vm.c Tue Jan 08 04:04:02 2019 +0800
- +++ b/njs/njs_vm.c Tue Jan 08 04:11:51 2019 +0800
- @@ -2280,10 +2280,15 @@
- }
- -const njs_vmcode_1addr_t njs_continuation_nexus[] = {
- +const njs_vmcode_generic_t njs_continuation_nexus[] = {
- { .code = { .operation = njs_vmcode_continuation,
- .operands = NJS_VMCODE_NO_OPERAND,
- .retval = NJS_VMCODE_NO_RETVAL } },
- +
- + { .code = { .operation = njs_vmcode_stop,
- + .operands = NJS_VMCODE_1OPERAND,
- + .retval = NJS_VMCODE_NO_RETVAL },
- + .operand1 = NJS_INDEX_GLOBAL_RETVAL },
- };
- diff -r c3f59a9933a0 -r 91b36548e0b1 njs/njs_vm.h
- --- a/njs/njs_vm.h Tue Jan 08 04:04:02 2019 +0800
- +++ b/njs/njs_vm.h Tue Jan 08 04:11:51 2019 +0800
- @@ -1304,7 +1304,7 @@
- extern const nxt_mem_proto_t njs_array_mem_proto;
- extern const nxt_lvlhsh_proto_t njs_object_hash_proto;
- -extern const njs_vmcode_1addr_t njs_continuation_nexus[];
- +extern const njs_vmcode_generic_t njs_continuation_nexus[];
- #endif /* _NJS_VM_H_INCLUDED_ */
- # HG changeset patch
- # User hongzhidao <hongzhidao@gmail.com>
- # Date 1546893308 -28800
- # Node ID 929990ce284c91fcd8d908b31267ea6e9a2c4b2c
- # Parent 91b36548e0b136d95b504b8da1cff9405fcadbac
- Replace njs_function_frame_activate as njs_function_activate.
- diff -r 91b36548e0b1 -r 929990ce284c njs/njs.c
- --- a/njs/njs.c Tue Jan 08 04:11:51 2019 +0800
- +++ b/njs/njs.c Tue Jan 08 04:35:08 2019 +0800
- @@ -471,9 +471,9 @@
- vm->current = (u_char *) njs_continuation_nexus;
- - ret = njs_function_frame_activate(vm, function, this, args, nargs,
- - NJS_INDEX_GLOBAL_RETVAL,
- - sizeof(njs_vmcode_generic_t));
- + ret = njs_function_activate(vm, function, this, args, nargs,
- + NJS_INDEX_GLOBAL_RETVAL,
- + sizeof(njs_vmcode_generic_t));
- if (nxt_slow_path(ret == NXT_ERROR)) {
- return ret;
- diff -r 91b36548e0b1 -r 929990ce284c njs/njs_function.c
- --- a/njs/njs_function.c Tue Jan 08 04:11:51 2019 +0800
- +++ b/njs/njs_function.c Tue Jan 08 04:35:08 2019 +0800
- @@ -8,10 +8,6 @@
- #include <string.h>
- -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)
- {
- @@ -917,6 +913,7 @@
- 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;
- @@ -936,7 +933,16 @@
- function = args[0].data.u.function;
- - return njs_function_activate(vm, function, this, &args[2], nargs, retval);
- + ret = njs_function_activate(vm, function, this, &args[2], nargs, retval,
- + sizeof(njs_vmcode_function_call_t));
- + if (nxt_slow_path(ret == NXT_ERROR)) {
- + return ret;
- + }
- +
- + /* Skip the "call" method frame. */
- + vm->top_frame->previous->skip = 1;
- +
- + return NJS_APPLIED;
- }
- @@ -944,6 +950,7 @@
- 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;
- @@ -974,12 +981,21 @@
- nargs = 0;
- }
- - return njs_function_activate(vm, function, this, args, nargs, retval);
- + ret = njs_function_activate(vm, function, this, args, nargs, retval,
- + sizeof(njs_vmcode_function_call_t));
- + if (nxt_slow_path(ret == NXT_ERROR)) {
- + return ret;
- + }
- +
- + /* Skip the "apply" method frame. */
- + vm->top_frame->previous->skip = 1;
- +
- + return NJS_APPLIED;
- }
- njs_ret_t
- -njs_function_frame_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
- +njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
- const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval, size_t advance)
- {
- njs_ret_t ret;
- @@ -1015,25 +1031,6 @@
- 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;
- -
- - ret = njs_function_frame_activate(vm, function, this, args, nargs, retval,
- - sizeof(njs_vmcode_function_call_t));
- - if (nxt_slow_path(ret == NXT_ERROR)) {
- - return ret;
- - }
- -
- - /* Skip the "call/apply" method frame. */
- - vm->top_frame->previous->skip = 1;
- -
- - return NJS_APPLIED;
- -}
- -
- -
- -static njs_ret_t
- njs_function_prototype_bind(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
- njs_index_t unused)
- {
- diff -r 91b36548e0b1 -r 929990ce284c njs/njs_function.h
- --- a/njs/njs_function.h Tue Jan 08 04:11:51 2019 +0800
- +++ b/njs/njs_function.h Tue Jan 08 04:35:08 2019 +0800
- @@ -170,7 +170,7 @@
- njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- nxt_bool_t ctor);
- -njs_ret_t njs_function_frame_activate(njs_vm_t *vm, njs_function_t *function,
- +njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
- njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- njs_index_t retval, size_t advance);
- njs_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
- # HG changeset patch
- # User hongzhidao <hongzhidao@gmail.com>
- # Date 1546894940 -28800
- # Node ID 14f1b7a9748bec226c9b9e9711d273e96ffb69de
- # Parent 929990ce284c91fcd8d908b31267ea6e9a2c4b2c
- Style
- diff -r 929990ce284c -r 14f1b7a9748b njs/njs.c
- --- a/njs/njs.c Tue Jan 08 04:35:08 2019 +0800
- +++ b/njs/njs.c Tue Jan 08 05:02:20 2019 +0800
- @@ -479,14 +479,10 @@
- return ret;
- }
- - ret = njs_vmcode_interpreter(vm);
- + ret = njs_vm_start(vm);
- vm->current = current;
- - if (ret == NJS_STOP) {
- - ret = NXT_OK;
- - }
- -
- return ret;
- }
- # HG changeset patch
- # User hongzhidao <hongzhidao@gmail.com>
- # Date 1546899276 -28800
- # Node ID 5e16c477ae3df08db0f146e540a62ea390e12b68
- # Parent 14f1b7a9748bec226c9b9e9711d273e96ffb69de
- 1) Fixed njs_vm_call.
- 2) Refactored njs_function_apply.
- 3) Style.
- diff -r 14f1b7a9748b -r 5e16c477ae3d njs/njs.c
- --- a/njs/njs.c Tue Jan 08 05:02:20 2019 +0800
- +++ b/njs/njs.c Tue Jan 08 06:14:36 2019 +0800
- @@ -461,9 +461,9 @@
- njs_vm_call(njs_vm_t *vm, njs_function_t *function, const njs_value_t *args,
- nxt_uint_t nargs)
- {
- - u_char *current;
- - njs_ret_t ret;
- - njs_value_t *this;
- + u_char *current;
- + njs_ret_t ret;
- + njs_value_t *this;
- this = (njs_value_t *) &njs_value_void;
- @@ -476,11 +476,13 @@
- sizeof(njs_vmcode_generic_t));
- if (nxt_slow_path(ret == NXT_ERROR)) {
- - return ret;
- - }
- + goto restore;
- + }
- ret = njs_vm_start(vm);
- +restore:
- +
- vm->current = current;
- return ret;
- diff -r 14f1b7a9748b -r 5e16c477ae3d njs/njs_function.c
- --- a/njs/njs_function.c Tue Jan 08 05:02:20 2019 +0800
- +++ b/njs/njs_function.c Tue Jan 08 06:14:36 2019 +0800
- @@ -425,42 +425,6 @@
- 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)
- -{
- - njs_ret_t ret;
- - njs_continuation_t *cont;
- -
- - if (function->native) {
- - ret = njs_function_native_frame(vm, function, &args[0], &args[1],
- - nargs - 1, NJS_CONTINUATION_SIZE, 0);
- - if (ret != NJS_OK) {
- - return ret;
- - }
- -
- - cont = njs_vm_continuation(vm);
- -
- - cont->function = function->u.native;
- - cont->args_types = function->args_types;
- - cont->retval = retval;
- -
- - cont->return_address = vm->current;
- - vm->current = (u_char *) njs_continuation_nexus;
- -
- - return NJS_APPLIED;
- - }
- -
- - ret = njs_function_frame(vm, function, &args[0], &args[1], nargs - 1, 0);
- -
- - if (nxt_fast_path(ret == NXT_OK)) {
- - return njs_function_call(vm, retval, 0);
- - }
- -
- - return ret;
- -}
- -
- -
- -nxt_noinline njs_ret_t
- njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
- {
- size_t size;
- @@ -995,8 +959,9 @@
- njs_ret_t
- -njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
- - const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval, size_t advance)
- +njs_function_activate(njs_vm_t *vm, njs_function_t *function,
- + njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- + njs_index_t retval, size_t advance)
- {
- njs_ret_t ret;
- njs_continuation_t *cont;
- diff -r 14f1b7a9748b -r 5e16c477ae3d njs/njs_function.h
- --- a/njs/njs_function.h Tue Jan 08 05:02:20 2019 +0800
- +++ b/njs/njs_function.h Tue Jan 08 06:14:36 2019 +0800
- @@ -162,8 +162,6 @@
- njs_value_t *value);
- njs_ret_t njs_function_constructor(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused);
- -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);
- njs_ret_t njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- size_t reserve, nxt_bool_t ctor);
- @@ -177,7 +175,8 @@
- void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
- njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
- 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_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
- + njs_index_t retval);
- extern const njs_object_init_t njs_function_constructor_init;
- extern const njs_object_init_t njs_function_prototype_init;
- @@ -188,4 +187,10 @@
- extern const njs_object_init_t njs_eval_function_init;
- +#define \
- +njs_function_apply(vm, function, args, nargs, retval) \
- + njs_function_activate(vm, function, &(args)[0], &(args)[1], (nargs - 1), \
- + retval, 0)
- +
- +
- #endif /* _NJS_FUNCTION_H_INCLUDED_ */
- diff -r 14f1b7a9748b -r 5e16c477ae3d njs/njs_vm.c
- --- a/njs/njs_vm.c Tue Jan 08 05:02:20 2019 +0800
- +++ b/njs/njs_vm.c Tue Jan 08 06:14:36 2019 +0800
- @@ -2055,8 +2055,9 @@
- return 0;
- }
- - ret = njs_function_native_call(vm, function->u.native, args, function->args_types,
- - nargs, (njs_index_t ) retval);
- + ret = njs_function_native_call(vm, function->u.native, args,
- + function->args_types, nargs,
- + (njs_index_t ) retval);
- switch (ret) {
- case NXT_OK:
- @@ -2286,9 +2287,9 @@
- .retval = NJS_VMCODE_NO_RETVAL } },
- { .code = { .operation = njs_vmcode_stop,
- - .operands = NJS_VMCODE_1OPERAND,
- - .retval = NJS_VMCODE_NO_RETVAL },
- - .operand1 = NJS_INDEX_GLOBAL_RETVAL },
- + .operands = NJS_VMCODE_1OPERAND,
- + .retval = NJS_VMCODE_NO_RETVAL },
- + .operand1 = NJS_INDEX_GLOBAL_RETVAL },
- };
- # HG changeset patch
- # User hongzhidao <hongzhidao@gmail.com>
- # Date 1546902264 -28800
- # Node ID 79ab6dfeb51be7b35b9bbb5d76ed443f5399305a
- # Parent 5e16c477ae3df08db0f146e540a62ea390e12b68
- Refactored function.
- diff -r 5e16c477ae3d -r 79ab6dfeb51b njs/njs_function.c
- --- a/njs/njs_function.c Tue Jan 08 06:14:36 2019 +0800
- +++ b/njs/njs_function.c Tue Jan 08 07:04:24 2019 +0800
- @@ -262,7 +262,7 @@
- nxt_noinline njs_ret_t
- -njs_function_frame(njs_vm_t *vm, njs_function_t *function,
- +njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- nxt_bool_t ctor)
- {
- @@ -425,7 +425,7 @@
- nxt_noinline njs_ret_t
- -njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
- +njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
- {
- size_t size;
- njs_ret_t ret;
- @@ -985,13 +985,13 @@
- return NJS_APPLIED;
- }
- - ret = njs_function_frame(vm, function, this, args, nargs, 0);
- + ret = njs_function_lambda_frame(vm, function, this, args, nargs, 0);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
- }
- - return njs_function_call(vm, retval, advance);
- + return njs_function_lambda_call(vm, retval, advance);
- }
- diff -r 5e16c477ae3d -r 79ab6dfeb51b njs/njs_function.h
- --- a/njs/njs_function.h Tue Jan 08 06:14:36 2019 +0800
- +++ b/njs/njs_function.h Tue Jan 08 07:04:24 2019 +0800
- @@ -162,21 +162,22 @@
- njs_value_t *value);
- njs_ret_t njs_function_constructor(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused);
- +
- +njs_ret_t njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
- + const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- + nxt_bool_t ctor);
- njs_ret_t njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- size_t reserve, nxt_bool_t ctor);
- -njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
- - const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- - nxt_bool_t ctor);
- njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
- njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- njs_index_t retval, size_t advance);
- -njs_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
- -void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
- -njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
- +njs_ret_t njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
- 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_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
- +void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
- extern const njs_object_init_t njs_function_constructor_init;
- extern const njs_object_init_t njs_function_prototype_init;
- diff -r 5e16c477ae3d -r 79ab6dfeb51b njs/njs_vm.c
- --- a/njs/njs_vm.c Tue Jan 08 06:14:36 2019 +0800
- +++ b/njs/njs_vm.c Tue Jan 08 07:04:24 2019 +0800
- @@ -1878,7 +1878,8 @@
- this = &val;
- }
- - return njs_function_frame(vm, function, this, NULL, nargs, ctor);
- + return njs_function_lambda_frame(vm, function, this, NULL,
- + nargs, ctor);
- }
- if (!ctor || function->ctor) {
- @@ -2029,7 +2030,7 @@
- function = frame->function;
- if (!function->native) {
- - ret = njs_function_call(vm, (njs_index_t) retval,
- + ret = njs_function_lambda_call(vm, (njs_index_t) retval,
- sizeof(njs_vmcode_function_call_t));
- if (nxt_fast_path(ret != NJS_ERROR)) {
- # HG changeset patch
- # User hongzhidao <hongzhidao@gmail.com>
- # Date 1546908100 -28800
- # Node ID 77baa7be10923e84058fddfb04b174d68ac33145
- # Parent 79ab6dfeb51be7b35b9bbb5d76ed443f5399305a
- Introduced njs_function_call.
- diff -r 79ab6dfeb51b -r 77baa7be1092 njs/njs_function.c
- --- a/njs/njs_function.c Tue Jan 08 07:04:24 2019 +0800
- +++ b/njs/njs_function.c Tue Jan 08 08:41:40 2019 +0800
- @@ -8,6 +8,9 @@
- #include <string.h>
- +static njs_native_frame_t *njs_function_frame_alloc(njs_vm_t *vm, size_t size);
- +
- +
- njs_function_t *
- njs_function_alloc(njs_vm_t *vm)
- {
- @@ -208,59 +211,6 @@
- }
- -njs_ret_t
- -njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
- - const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- - size_t reserve, nxt_bool_t ctor)
- -{
- - size_t size;
- - nxt_uint_t n;
- - njs_value_t *value, *bound;
- - njs_native_frame_t *frame;
- -
- - reserve = nxt_max(reserve, function->continuation_size);
- -
- - size = NJS_NATIVE_FRAME_SIZE + reserve
- - + (function->args_offset + nargs) * sizeof(njs_value_t);
- -
- - frame = njs_function_frame_alloc(vm, size);
- - if (nxt_slow_path(frame == NULL)) {
- - return NXT_ERROR;
- - }
- -
- - frame->function = function;
- - frame->nargs = function->args_offset + nargs;
- - frame->ctor = ctor;
- -
- - value = (njs_value_t *) (njs_continuation(frame) + reserve);
- - frame->arguments = value;
- -
- - bound = function->bound;
- -
- - if (bound == NULL) {
- - /* GC: njs_retain(this); */
- - *value++ = *this;
- -
- - } else {
- - n = function->args_offset;
- -
- - do {
- - /* GC: njs_retain(bound); */
- - *value++ = *bound++;
- - n--;
- - } while (n != 0);
- - }
- -
- - vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = value;
- -
- - if (args != NULL) {
- - memcpy(value, args, nargs * sizeof(njs_value_t));
- - }
- -
- - return NXT_OK;
- -}
- -
- -
- nxt_noinline njs_ret_t
- njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- @@ -335,7 +285,60 @@
- }
- -nxt_noinline njs_native_frame_t *
- +njs_ret_t
- +njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
- + const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- + size_t reserve, nxt_bool_t ctor)
- +{
- + size_t size;
- + nxt_uint_t n;
- + njs_value_t *value, *bound;
- + njs_native_frame_t *frame;
- +
- + reserve = nxt_max(reserve, function->continuation_size);
- +
- + size = NJS_NATIVE_FRAME_SIZE + reserve
- + + (function->args_offset + nargs) * sizeof(njs_value_t);
- +
- + frame = njs_function_frame_alloc(vm, size);
- + if (nxt_slow_path(frame == NULL)) {
- + return NXT_ERROR;
- + }
- +
- + frame->function = function;
- + frame->nargs = function->args_offset + nargs;
- + frame->ctor = ctor;
- +
- + value = (njs_value_t *) (njs_continuation(frame) + reserve);
- + frame->arguments = value;
- +
- + bound = function->bound;
- +
- + if (bound == NULL) {
- + /* GC: njs_retain(this); */
- + *value++ = *this;
- +
- + } else {
- + n = function->args_offset;
- +
- + do {
- + /* GC: njs_retain(bound); */
- + *value++ = *bound++;
- + n--;
- + } while (n != 0);
- + }
- +
- + vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = value;
- +
- + if (args != NULL) {
- + memcpy(value, args, nargs * sizeof(njs_value_t));
- + }
- +
- + return NXT_OK;
- +}
- +
- +
- +static njs_native_frame_t *
- njs_function_frame_alloc(njs_vm_t *vm, size_t size)
- {
- size_t spare_size, chunk_size;
- @@ -966,13 +969,14 @@
- njs_ret_t ret;
- njs_continuation_t *cont;
- + ret = njs_function_frame(vm, function, this, args, nargs,
- + NJS_CONTINUATION_SIZE, 0);
- +
- + if (nxt_slow_path(ret != NXT_OK)) {
- + return ret;
- + }
- +
- if (function->native) {
- - ret = njs_function_native_frame(vm, function, this, args, nargs,
- - NJS_CONTINUATION_SIZE, 0);
- - if (nxt_slow_path(ret != NXT_OK)) {
- - return ret;
- - }
- -
- cont = njs_vm_continuation(vm);
- cont->function = function->u.native;
- @@ -985,12 +989,6 @@
- return NJS_APPLIED;
- }
- - ret = njs_function_lambda_frame(vm, function, this, args, nargs, 0);
- -
- - if (nxt_slow_path(ret != NXT_OK)) {
- - return ret;
- - }
- -
- return njs_function_lambda_call(vm, retval, advance);
- }
- diff -r 79ab6dfeb51b -r 77baa7be1092 njs/njs_function.h
- --- a/njs/njs_function.h Tue Jan 08 07:04:24 2019 +0800
- +++ b/njs/njs_function.h Tue Jan 08 08:41:40 2019 +0800
- @@ -149,7 +149,6 @@
- njs_function_t *njs_function_alloc(njs_vm_t *vm);
- njs_function_t *njs_function_value_copy(njs_vm_t *vm, njs_value_t *value);
- -njs_native_frame_t *njs_function_frame_alloc(njs_vm_t *vm, size_t size);
- njs_ret_t njs_function_arguments_object_init(njs_vm_t *vm,
- njs_native_frame_t *frame);
- njs_ret_t njs_function_rest_parameters_init(njs_vm_t *vm,
- @@ -194,4 +193,11 @@
- retval, 0)
- +#define \
- +njs_function_frame(vm, function, this, args, nargs, reserve, ctor) \
- + ((function)->native ? \
- + njs_function_native_frame(vm, function, this, args, nargs, reserve, ctor) \
- + : njs_function_lambda_frame(vm, function, this, args, nargs, ctor))
- +
- +
- #endif /* _NJS_FUNCTION_H_INCLUDED_ */
- diff -r 79ab6dfeb51b -r 77baa7be1092 njs/njs_vm.c
- --- a/njs/njs_vm.c Tue Jan 08 07:04:24 2019 +0800
- +++ b/njs/njs_vm.c Tue Jan 08 08:41:40 2019 +0800
- @@ -1864,9 +1864,15 @@
- function = value->data.u.function;
- - if (!function->native) {
- -
- - if (ctor) {
- + if (ctor) {
- + if (function->native) {
- + if (!function->ctor) {
- + njs_type_error(vm, "%s is not a constructor",
- + njs_type_string(value->type));
- + return NXT_ERROR;
- + }
- +
- + } else {
- object = njs_function_new_object(vm, value);
- if (nxt_slow_path(object == NULL)) {
- return NXT_ERROR;
- @@ -1877,20 +1883,9 @@
- val.data.truth = 1;
- this = &val;
- }
- -
- - return njs_function_lambda_frame(vm, function, this, NULL,
- - nargs, ctor);
- }
- - if (!ctor || function->ctor) {
- - return njs_function_native_frame(vm, function, this, NULL,
- - nargs, 0, ctor);
- - }
- -
- - njs_type_error(vm, "%s is not a constructor",
- - njs_type_string(value->type));
- -
- - return NXT_ERROR;
- + return njs_function_frame(vm, function, this, NULL, nargs, 0, ctor);
- }
- njs_type_error(vm, "%s is not a function", njs_type_string(value->type));
Add Comment
Please, Sign In to add comment