{
njs_int_t ret;
njs_function_t *function;
- njs_native_frame_t *native, *previous;
+ njs_native_frame_t *native;
njs_function_native_t call;
native = vm->top_frame;
return ret;
}
- if (ret == NJS_DECLINED) {
- return NJS_OK;
- }
-
- previous = njs_function_previous_frame(native);
+ njs_vm_scopes_restore(vm, native);
- njs_vm_scopes_restore(vm, native, previous);
-
- if (!native->skip) {
- *native->retval = vm->retval;
- }
+ *native->retval = vm->retval;
njs_function_frame_free(vm, native);
void
njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *native)
{
- njs_native_frame_t *previous;
-
- do {
- previous = native->previous;
-
- /* GC: free frame->local, etc. */
-
- if (native->size != 0) {
- vm->spare_stack_size += native->size;
- njs_mp_free(vm->mem_pool, native);
- }
-
- native = previous;
- } while (native->skip);
+ if (native->size != 0) {
+ vm->spare_stack_size += native->size;
+ njs_mp_free(vm->mem_pool, native);
+ }
}
njs_function_prototype_call(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- njs_int_t ret;
- njs_function_t *function;
- const njs_value_t *this;
- njs_native_frame_t *frame;
+ njs_int_t ret;
+ njs_value_t retval;
+ const njs_value_t *this;
if (!njs_is_function(&args[0])) {
njs_type_error(vm, "\"this\" argument is not a function");
nargs = 0;
}
- frame = vm->top_frame;
-
- /* Skip the "call" method frame. */
- frame->skip = 1;
-
- function = njs_function(&args[0]);
-
- ret = njs_function_frame(vm, function, this, &args[2], nargs, 0);
+ ret = njs_function_call(vm, njs_function(&args[0]), this, &args[2], nargs,
+ &retval);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
- ret = njs_function_frame_invoke(vm, frame->retval);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
+ njs_value_assign(&vm->retval, &retval);
- return NJS_DECLINED;
+ return NJS_OK;
}
{
int64_t i, length;
njs_int_t ret;
- njs_frame_t *frame;
- njs_value_t *this, *arr_like;
+ njs_value_t retval, *this, *arr_like;
njs_array_t *arr;
njs_function_t *func;
activate:
- /* Skip the "apply" method frame. */
- vm->top_frame->skip = 1;
-
- frame = (njs_frame_t *) vm->top_frame;
-
- ret = njs_function_frame(vm, func, this, args, length, 0);
+ ret = njs_function_call(vm, func, this, args, length, &retval);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
- ret = njs_function_frame_invoke(vm, frame->native.retval);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
+ njs_value_assign(&vm->retval, &retval);
- return NJS_DECLINED;
+ return NJS_OK;
}
uint8_t native; /* 1 bit */
/* Function is called as constructor with "new" keyword. */
uint8_t ctor; /* 1 bit */
-
- /* Skip the Function.call() and Function.apply() methods frames. */
- uint8_t skip; /* 1 bit */
};
}
-njs_inline njs_native_frame_t *
-njs_function_previous_frame(njs_native_frame_t *frame)
-{
- njs_native_frame_t *previous;
-
- do {
- previous = frame->previous;
- frame = previous;
-
- } while (frame->skip);
-
- return frame;
-}
-
-
njs_inline njs_int_t
njs_function_call(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args,
lambda_call = (native == &vm->active_frame->native);
- njs_vm_scopes_restore(vm, native, previous);
+ njs_vm_scopes_restore(vm, native);
if (native->size != 0) {
vm->spare_stack_size += native->size;
static njs_jump_off_t
njs_vmcode_return(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
{
- njs_frame_t *frame;
- njs_native_frame_t *previous;
+ njs_frame_t *frame;
frame = (njs_frame_t *) vm->top_frame;
}
}
- previous = njs_function_previous_frame(&frame->native);
-
- njs_vm_scopes_restore(vm, &frame->native, previous);
+ njs_vm_scopes_restore(vm, &frame->native);
*frame->native.retval = *retval;