details: http://hg.nginx.org/njs/rev/eba4f3a30bb4 branches: changeset: 272:eba4f3a30bb4 user: Igor Sysoev <i...@sysoev.ru> date: Mon Dec 05 17:35:33 2016 +0300 description: Native methods called by iterators should run via continuation to normilize arguments.
diffstat: njs/njs_function.c | 12 ++---------- njs/njs_function.h | 1 + njs/njs_vm.c | 8 ++++++++ njs/test/njs_unit_test.c | 3 +++ 4 files changed, 14 insertions(+), 10 deletions(-) diffs (83 lines): diff -r 7275165c3832 -r eba4f3a30bb4 njs/njs_function.c --- a/njs/njs_function.c Fri Dec 02 17:11:57 2016 +0300 +++ b/njs/njs_function.c Mon Dec 05 17:35:33 2016 +0300 @@ -252,21 +252,12 @@ 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) { - size_t reserve; njs_ret_t ret; njs_continuation_t *cont; if (function->native) { - - if (function->continuation_size == 0 && function->bound == NULL) { - return function->u.native(vm, args, nargs, retval); - } - - reserve = nxt_align_size(sizeof(njs_continuation_t), - sizeof(njs_value_t)), - ret = njs_function_native_frame(vm, function, &args[0], &args[1], - nargs - 1, reserve, 0); + nargs - 1, NJS_CONTINUATION_SIZE, 0); if (ret != NJS_OK) { return ret; } @@ -274,6 +265,7 @@ njs_function_apply(njs_vm_t *vm, njs_fun cont = njs_continuation(vm->frame); cont->function = function->u.native; + cont->args_types = function->args_types; cont->retval = retval; cont->return_address = vm->current; diff -r 7275165c3832 -r eba4f3a30bb4 njs/njs_function.h --- a/njs/njs_function.h Fri Dec 02 17:11:57 2016 +0300 +++ b/njs/njs_function.h Mon Dec 05 17:35:33 2016 +0300 @@ -50,6 +50,7 @@ struct njs_function_lambda_s { typedef struct { njs_function_native_t function; + uint8_t *args_types; u_char *return_address; njs_index_t retval; } njs_continuation_t; diff -r 7275165c3832 -r eba4f3a30bb4 njs/njs_vm.c --- a/njs/njs_vm.c Fri Dec 02 17:11:57 2016 +0300 +++ b/njs/njs_vm.c Mon Dec 05 17:35:33 2016 +0300 @@ -2358,6 +2358,7 @@ njs_vmcode_function_call(njs_vm_t *vm, n cont = njs_continuation(vm->frame); cont->function = function->u.native; + cont->args_types = function->args_types; cont->retval = (njs_index_t) retval; cont->return_address = vm->current + sizeof(njs_vmcode_function_call_t); @@ -2609,6 +2610,13 @@ njs_vmcode_continuation(njs_vm_t *vm, nj cont = njs_continuation(frame); args = frame->arguments - frame->function->args_offset; + if (cont->args_types != NULL) { + ret = njs_normalize_args(vm, args, cont->args_types, frame->nargs); + if (ret != NJS_OK) { + return ret; + } + } + ret = cont->function(vm, args, frame->nargs, cont->retval); switch (ret) { diff -r 7275165c3832 -r eba4f3a30bb4 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Fri Dec 02 17:11:57 2016 +0300 +++ b/njs/test/njs_unit_test.c Mon Dec 05 17:35:33 2016 +0300 @@ -5461,6 +5461,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("var d = new Date(); d.__proto__ === Date.prototype"), nxt_string("true") }, + { nxt_string("[0].map(new Date().getDate)"), + nxt_string("TypeError") }, + { nxt_string("new Date(eval)"), nxt_string("Invalid Date") }, _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel