[njs] Native methods called with Function.prototype.call() and
Igor Sysoev
igor at sysoev.ru
Mon Dec 5 15:17:46 UTC 2016
details: http://hg.nginx.org/njs/rev/15ec6a09cece
branches:
changeset: 273:15ec6a09cece
user: Igor Sysoev <igor at sysoev.ru>
date: Mon Dec 05 17:45:02 2016 +0300
description:
Native methods called with Function.prototype.call() and
Functon.prototype.apply() should run via continuation to
normilize arguments.
diffstat:
njs/njs_function.c | 21 ++++++++++++++++-----
1 files changed, 16 insertions(+), 5 deletions(-)
diffs (46 lines):
diff -r eba4f3a30bb4 -r 15ec6a09cece njs/njs_function.c
--- a/njs/njs_function.c Mon Dec 05 17:35:33 2016 +0300
+++ b/njs/njs_function.c Mon Dec 05 17:45:02 2016 +0300
@@ -484,18 +484,29 @@ 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;
+ njs_ret_t ret;
+ njs_continuation_t *cont;
if (function->native) {
- ret = njs_function_native_frame(vm, function, this, args,
- nargs, 0, 0);
+ ret = njs_function_native_frame(vm, function, this, args, nargs,
+ NJS_CONTINUATION_SIZE, 0);
if (nxt_slow_path(ret != NXT_OK)) {
return ret;
}
- /* Skip the "apply" method frame. */
+ /* Skip the "call/apply" method frame. */
vm->frame->previous->skip = 1;
+ cont = njs_continuation(vm->frame);
+
+ 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);;
+ vm->current = (u_char *) njs_continuation_nexus;
+
return NJS_APPLIED;
}
@@ -505,7 +516,7 @@ njs_function_activate(njs_vm_t *vm, njs_
return ret;
}
- /* Skip the "apply" method frame. */
+ /* Skip the "call/apply" method frame. */
vm->frame->previous->skip = 1;
return njs_function_call(vm, retval, sizeof(njs_vmcode_function_call_t));
More information about the nginx-devel
mailing list