njs_vm_call(njs_vm_t *vm, njs_function_t *function, const njs_value_t *args,
nxt_uint_t nargs)
{
- return njs_vm_invoke(vm, function, args, nargs, NJS_INDEX_GLOBAL_RETVAL);
+ return njs_vm_invoke(vm, function, args, nargs, (njs_index_t) &vm->retval);
}
njs_vm_invoke(njs_vm_t *vm, njs_function_t *function, const njs_value_t *args,
nxt_uint_t nargs, njs_index_t retval)
{
- u_char *current;
njs_ret_t ret;
njs_value_t *this;
this = (njs_value_t *) &njs_value_undefined;
- current = vm->current;
-
- vm->current = (u_char *) njs_continuation_nexus;
-
- ret = njs_function_activate(vm, function, this, args, nargs, retval,
- sizeof(njs_vmcode_generic_t));
-
- if (nxt_fast_path(ret == NJS_APPLIED)) {
- ret = njs_vmcode_interpreter(vm);
-
- if (ret == NJS_STOP) {
- ret = NXT_OK;
- }
+ ret = njs_function_frame(vm, function, this, (njs_value_t *) args, nargs,
+ 0);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
}
- vm->current = current;
-
- return ret;
+ return njs_function_frame_invoke(vm, retval);
}
#include <stdint.h>
-typedef struct {
- union {
- njs_continuation_t cont;
- u_char padding[NJS_CONTINUATION_SIZE];
- } u;
- /*
- * This retval value must be aligned so the continuation is padded
- * to aligned size.
- */
- njs_value_t length;
-} njs_array_slice_t;
-
-
-typedef struct {
- union {
- njs_continuation_t cont;
- u_char padding[NJS_CONTINUATION_SIZE];
- } u;
-
- njs_value_t length;
- nxt_int_t start;
- nxt_int_t end;
-} njs_array_fill_t;
-
-
-typedef struct {
- njs_continuation_t cont;
- njs_value_t *values;
- uint32_t max;
-} njs_array_join_t;
-
-
-typedef struct {
- union {
- njs_continuation_t cont;
- u_char padding[NJS_CONTINUATION_SIZE];
- } u;
- /*
- * This retval value must be aligned so the continuation is padded
- * to aligned size.
- */
- njs_value_t retval;
-
- uint32_t index;
- uint32_t length;
-} njs_array_iter_t;
-
-
-typedef struct {
- njs_array_iter_t iter;
- njs_value_t value;
- njs_array_t *array;
-} njs_array_filter_t;
-
-
-typedef struct {
- njs_array_iter_t iter;
- njs_value_t value;
-} njs_array_find_t;
-
-
-typedef struct {
- njs_array_iter_t iter;
- njs_array_t *array;
-} njs_array_map_t;
-
-
-typedef struct {
- union {
- njs_continuation_t cont;
- u_char padding[NJS_CONTINUATION_SIZE];
- } u;
- /*
- * This retval value must be aligned so the continuation is padded
- * to aligned size.
- */
- njs_value_t retval;
-
- njs_function_t *function;
- uint32_t index;
- uint32_t current;
-} njs_array_sort_t;
-
-
-static njs_ret_t njs_array_prototype_slice_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
static njs_ret_t njs_array_prototype_slice_copy(njs_vm_t *vm,
njs_value_t *this, int64_t start, int64_t length);
-static njs_ret_t njs_array_prototype_join_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
static njs_value_t *njs_array_copy(njs_value_t *dst, njs_value_t *src);
-static njs_ret_t njs_array_prototype_fill_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static njs_ret_t njs_array_prototype_fill_object_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static njs_ret_t njs_array_prototype_for_each_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static njs_ret_t njs_array_prototype_some_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static njs_ret_t njs_array_prototype_every_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static njs_ret_t njs_array_prototype_filter_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static njs_ret_t njs_array_prototype_find_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static njs_ret_t njs_array_prototype_find_index_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static njs_ret_t njs_array_prototype_map_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static uint32_t njs_array_prototype_map_index(njs_array_t *array,
- njs_array_map_t *map);
-static njs_ret_t njs_array_iterator_args(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs);
-static uint32_t njs_array_iterator_index(njs_array_t *array,
- njs_array_iter_t *iter);
-static njs_ret_t njs_array_iterator_apply(njs_vm_t *vm,
- njs_array_iter_t *iter, njs_value_t *args, nxt_uint_t nargs);
-static njs_ret_t njs_array_prototype_find_apply(njs_vm_t *vm,
- njs_array_iter_t *iter, njs_value_t *args, nxt_uint_t nargs);
-static njs_ret_t njs_array_prototype_reduce_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static njs_ret_t njs_array_prototype_reduce_right_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static uint32_t njs_array_reduce_right_index(njs_array_t *array,
- njs_array_iter_t *iter);
-static njs_ret_t njs_array_prototype_sort_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
njs_array_t *
{
.type = NJS_METHOD,
.name = njs_string("isArray"),
- .value = njs_native_function(njs_array_is_array, 0, 0),
+ .value = njs_native_function(njs_array_is_array, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("of"),
- .value = njs_native_function(njs_array_of, 0, 0),
+ .value = njs_native_function(njs_array_of, 0),
.writable = 1,
.configurable = 1,
},
njs_array_prototype_slice(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
{
- njs_ret_t ret;
- njs_array_slice_t *slice;
-
- static const njs_value_t njs_string_length = njs_string("length");
-
- slice = njs_vm_continuation(vm);
- slice->u.cont.function = njs_array_prototype_slice_continuation;
+ int64_t start, end, length;
+ njs_ret_t ret;
+ njs_value_t prop_length;
- ret = njs_value_property(vm, &args[0], &njs_string_length, &slice->length,
- 0);
+ static const njs_value_t string_length = njs_string("length");
- if (nxt_slow_path(ret == NXT_ERROR || ret == NJS_APPLIED)) {
+ ret = njs_value_property(vm, &args[0], &string_length, &prop_length);
+ if (nxt_slow_path(ret == NXT_ERROR)) {
return ret;
}
- return njs_array_prototype_slice_continuation(vm, args, nargs, unused);
-}
-
-
-static njs_ret_t
-njs_array_prototype_slice_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- int64_t start, end, length;
- njs_ret_t ret;
- njs_array_slice_t *slice;
-
- slice = njs_vm_continuation(vm);
-
- if (nxt_slow_path(!njs_is_primitive(&slice->length))) {
- ret = njs_value_to_numeric(vm, &slice->length, &slice->length);
+ if (nxt_slow_path(!njs_is_primitive(&prop_length))) {
+ ret = njs_value_to_numeric(vm, &prop_length, &prop_length);
if (ret != NXT_OK) {
return ret;
}
}
start = njs_primitive_value_to_integer(njs_arg(args, nargs, 1));
- length = njs_primitive_value_to_length(&slice->length);
+ length = njs_primitive_value_to_length(&prop_length);
if (start < 0) {
start += length;
njs_uint32_to_string(&name, start++);
value = &array->start[n++];
- ret = njs_value_property(vm, this, &name, value, 0);
+ ret = njs_value_property(vm, this, &name, value);
if (ret != NXT_OK) {
*value = njs_value_invalid;
prop = njs_object_property(vm, njs_object(&args[0]), &lhq);
if (nxt_fast_path(prop != NULL && njs_is_function(&prop->value))) {
- return njs_function_call(vm, njs_function(&prop->value), args,
- nargs, (njs_index_t) &vm->retval);
+ return njs_function_apply(vm, njs_function(&prop->value), args,
+ nargs, &vm->retval);
}
}
njs_array_prototype_join(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
{
- uint32_t max;
- nxt_uint_t i, n;
- njs_array_t *array;
- njs_value_t *value, *values;
- njs_array_join_t *join;
+ u_char *p;
+ uint32_t max;
+ size_t size, length, mask;
+ njs_ret_t ret;
+ nxt_uint_t i, n;
+ njs_array_t *array;
+ njs_value_t *value, *values;
+ njs_string_prop_t separator, string;
- if (!njs_is_array(&args[0])) {
- goto empty;
+ if (!njs_is_array(&args[0]) || njs_array_len(&args[0]) == 0) {
+ vm->retval = njs_string_empty;
+ return NXT_OK;
}
array = njs_array(&args[0]);
- if (array->length == 0) {
- goto empty;
- }
-
- join = njs_vm_continuation(vm);
- join->values = NULL;
- join->max = 0;
max = 0;
+ values = NULL;
for (i = 0; i < array->length; i++) {
value = &array->start[i];
return NXT_ERROR;
}
- join = njs_vm_continuation(vm);
- join->cont.function = njs_array_prototype_join_continuation;
- join->values = values;
- join->max = max;
-
n = 0;
for (i = 0; i < array->length; i++) {
}
}
- return njs_array_prototype_join_continuation(vm, args, nargs, unused);
-
-empty:
-
- vm->retval = njs_string_empty;
-
- return NXT_OK;
-}
-
-
-static njs_ret_t
-njs_array_prototype_join_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- u_char *p;
- size_t size, length, mask;
- uint32_t max;
- njs_ret_t ret;
- nxt_uint_t i, n;
- njs_array_t *array;
- njs_value_t *value, *values;
- njs_array_join_t *join;
- njs_string_prop_t separator, string;
-
- join = njs_vm_continuation(vm);
- values = join->values;
- max = join->max;
-
size = 0;
length = 0;
n = 0;
njs_array_prototype_fill(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
{
- njs_ret_t ret;
- njs_value_t *this;
- njs_array_fill_t *fill;
+ njs_ret_t ret;
+ nxt_int_t i, start, end, length;
+ njs_array_t *array;
+ njs_value_t name, prop_length;
+ njs_object_t *object;
+ const njs_value_t *this, *value;
- static const njs_value_t njs_string_length = njs_string("length");
+ static const njs_value_t string_length = njs_string("length");
this = (njs_value_t *) njs_arg(args, nargs, 0);
return NJS_ERROR;
}
- } else if (!njs_is_array(this)) {
- fill = njs_vm_continuation(vm);
- fill->u.cont.function = njs_array_prototype_fill_continuation;
-
- ret = njs_value_property(vm, this, &njs_string_length, &fill->length,
- 0);
-
- if (nxt_slow_path(ret == NXT_ERROR || ret == NJS_APPLIED)) {
- return ret;
- }
- }
-
- return njs_array_prototype_fill_continuation(vm, args, nargs, unused);
-}
-
-
-static njs_ret_t
-njs_array_prototype_fill_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- nxt_int_t i, start, end, length;
- njs_ret_t ret;
- njs_array_t *array;
- njs_object_t *object;
- njs_array_fill_t *fill;
- const njs_value_t *this, *value;
-
- array = NULL;
-
- this = njs_arg(args, nargs, 0);
-
- if (njs_is_primitive(this)) {
object = njs_object_value_alloc(vm, this, this->type);
if (nxt_slow_path(object == NULL)) {
return NXT_ERROR;
return NXT_OK;
}
- fill = njs_vm_continuation(vm);
+ array = NULL;
if (njs_is_array(this)) {
array = njs_array(this);
length = array->length;
} else {
+ ret = njs_value_property(vm, this, &string_length, &prop_length);
+ if (nxt_slow_path(ret == NXT_ERROR)) {
+ return ret;
+ }
- if (nxt_slow_path(!njs_is_primitive(&fill->length))) {
- ret = njs_value_to_numeric(vm, &fill->length, &fill->length);
+ if (nxt_slow_path(!njs_is_primitive(&prop_length))) {
+ ret = njs_value_to_numeric(vm, &prop_length, &prop_length);
if (ret != NXT_OK) {
return ret;
}
}
- length = njs_primitive_value_to_length(&fill->length);
+ length = njs_primitive_value_to_length(&prop_length);
}
start = njs_primitive_value_to_integer(njs_arg(args, nargs, 2));
return NXT_OK;
}
- fill->u.cont.function = njs_array_prototype_fill_object_continuation;
- fill->start = start;
- fill->end = end;
-
- return njs_array_prototype_fill_object_continuation(vm, args, nargs,
- unused);
-}
-
-
-static njs_ret_t
-njs_array_prototype_fill_object_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- njs_ret_t ret;
- nxt_int_t end;
- njs_value_t name;
- njs_array_fill_t *fill;
- const njs_value_t *value;
-
- fill = njs_vm_continuation(vm);
- end = fill->end;
-
- vm->retval = *njs_arg(args, nargs, 0);
value = njs_arg(args, nargs, 1);
- while (fill->start < end) {
- njs_uint32_to_string(&name, fill->start++);
+ while (start < end) {
+ njs_uint32_to_string(&name, start++);
- ret = njs_value_property_set(vm, &vm->retval, &name,
- (njs_value_t *) value, 0);
- if (nxt_slow_path(ret == NXT_ERROR || ret == NJS_APPLIED)) {
+ ret = njs_value_property_set(vm, (njs_value_t *) this, &name,
+ (njs_value_t *) value);
+ if (nxt_slow_path(ret == NXT_ERROR)) {
return ret;
}
}
+ vm->retval = *this;
+
return NXT_OK;
}
-static njs_ret_t
-njs_array_prototype_for_each(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
- njs_index_t unused)
+nxt_inline njs_ret_t
+njs_array_iterator_call(njs_vm_t *vm, njs_function_t *function,
+ const njs_value_t *this_arg, njs_value_t *value, uint32_t n,
+ njs_value_t *array)
{
- nxt_int_t ret;
- njs_array_iter_t *iter;
+ njs_value_t arguments[3];
- ret = njs_array_iterator_args(vm, args, nargs);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
- }
+ /* GC: array elt, array */
- iter = njs_vm_continuation(vm);
- iter->u.cont.function = njs_array_prototype_for_each_continuation;
+ arguments[0] = *value;
+ njs_set_number(&arguments[1], n);
+ arguments[2] = *array;
- return njs_array_prototype_for_each_continuation(vm, args, nargs, unused);
+ return njs_function_call(vm, function, (njs_value_t *) this_arg,
+ arguments, 3, &vm->retval);
}
static njs_ret_t
-njs_array_prototype_for_each_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
+njs_array_prototype_for_each(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
{
- uint32_t index;
- njs_array_iter_t *iter;
-
- iter = njs_vm_continuation(vm);
-
- index = njs_array_iterator_index(njs_array(&args[0]), iter);
-
- if (index == NJS_ARRAY_INVALID_INDEX) {
- vm->retval = njs_value_undefined;
- return NXT_OK;
+ uint32_t i, length;
+ nxt_int_t ret;
+ njs_value_t *array, *value;
+ njs_function_t *function;
+ const njs_value_t *this_arg;
+
+ if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
+ njs_type_error(vm, "unexpected iterator arguments");
+ return NXT_ERROR;
}
- return njs_array_iterator_apply(vm, iter, args, nargs);
-}
+ array = &args[0];
+ length = njs_array_len(array);
+ function = njs_function(&args[1]);
+ this_arg = njs_arg(args, nargs, 2);
+ for (i = 0; i < length; i++) {
+ value = &njs_array_start(array)[i];
-static njs_ret_t
-njs_array_prototype_some(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
- njs_index_t unused)
-{
- nxt_int_t ret;
- njs_array_iter_t *iter;
+ if (njs_is_valid(value)) {
+ ret = njs_array_iterator_call(vm, function, this_arg, value, i,
+ array);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+ }
- ret = njs_array_iterator_args(vm, args, nargs);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
+ length = nxt_min(length, njs_array_len(array));
}
- iter = njs_vm_continuation(vm);
- iter->u.cont.function = njs_array_prototype_some_continuation;
+ vm->retval = njs_value_undefined;
- return njs_array_prototype_some_continuation(vm, args, nargs, unused);
+ return NXT_OK;
}
static njs_ret_t
-njs_array_prototype_some_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
+njs_array_prototype_some(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
{
- uint32_t index;
- njs_array_iter_t *iter;
- const njs_value_t *retval;
+ uint32_t i, length;
+ nxt_int_t ret;
+ njs_value_t *array, *value;
+ njs_function_t *function;
+ const njs_value_t *this_arg, *retval;
+
+ if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
+ njs_type_error(vm, "unexpected iterator arguments");
+ return NXT_ERROR;
+ }
- iter = njs_vm_continuation(vm);
+ array = &args[0];
+ length = njs_array_len(array);
+ function = njs_function(&args[1]);
+ this_arg = njs_arg(args, nargs, 2);
- if (njs_is_true(&iter->retval)) {
- retval = &njs_value_true;
+ retval = &njs_value_false;
- } else {
- index = njs_array_iterator_index(njs_array(&args[0]), iter);
+ for (i = 0; i < length; i++) {
+ value = &njs_array_start(array)[i];
- if (index == NJS_ARRAY_INVALID_INDEX) {
- retval = &njs_value_false;
+ if (njs_is_valid(value)) {
+ ret = njs_array_iterator_call(vm, function, this_arg, value, i,
+ array);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
- } else {
- return njs_array_iterator_apply(vm, iter, args, nargs);
+ if (njs_is_true(&vm->retval)) {
+ retval = &njs_value_true;
+ break;
+ }
}
+
+ length = nxt_min(length, njs_array_len(array));
}
vm->retval = *retval;
njs_array_prototype_every(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
{
- nxt_int_t ret;
- njs_array_iter_t *iter;
-
- ret = njs_array_iterator_args(vm, args, nargs);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
+ uint32_t i, length;
+ nxt_int_t ret;
+ njs_value_t *array, *value;
+ njs_function_t *function;
+ const njs_value_t *this_arg, *retval;
+
+ if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
+ njs_type_error(vm, "unexpected iterator arguments");
+ return NXT_ERROR;
}
- iter = njs_vm_continuation(vm);
- iter->u.cont.function = njs_array_prototype_every_continuation;
- iter->retval.data.truth = 1;
+ array = &args[0];
+ length = njs_array_len(array);
+ function = njs_function(&args[1]);
+ this_arg = njs_arg(args, nargs, 2);
- return njs_array_prototype_every_continuation(vm, args, nargs, unused);
-}
-
-
-static njs_ret_t
-njs_array_prototype_every_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- uint32_t index;
- njs_array_iter_t *iter;
- const njs_value_t *retval;
-
- iter = njs_vm_continuation(vm);
-
- if (!njs_is_true(&iter->retval)) {
- retval = &njs_value_false;
+ retval = &njs_value_true;
- } else {
- index = njs_array_iterator_index(njs_array(&args[0]), iter);
+ for (i = 0; i < length; i++) {
+ value = &njs_array_start(array)[i];
- if (index == NJS_ARRAY_INVALID_INDEX) {
- retval = &njs_value_true;
+ if (njs_is_valid(value)) {
+ ret = njs_array_iterator_call(vm, function, this_arg, value, i,
+ array);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
- } else {
- return njs_array_iterator_apply(vm, iter, args, nargs);
+ if (!njs_is_true(&vm->retval)) {
+ retval = &njs_value_false;
+ break;
+ }
}
+
+ length = nxt_min(length, njs_array_len(array));
}
vm->retval = *retval;
njs_array_prototype_filter(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
{
- nxt_int_t ret;
- njs_array_filter_t *filter;
-
- ret = njs_array_iterator_args(vm, args, nargs);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
+ uint32_t i, length;
+ nxt_int_t ret;
+ njs_array_t *retval;
+ njs_value_t *array, value;
+ njs_function_t *function;
+ const njs_value_t *this_arg;
+
+ if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
+ njs_type_error(vm, "unexpected iterator arguments");
+ return NXT_ERROR;
}
- filter = njs_vm_continuation(vm);
- filter->iter.u.cont.function = njs_array_prototype_filter_continuation;
+ array = &args[0];
+ length = njs_array_len(array);
+ function = njs_function(&args[1]);
+ this_arg = njs_arg(args, nargs, 2);
- filter->array = njs_array_alloc(vm, 0, NJS_ARRAY_SPARE);
- if (nxt_slow_path(filter->array == NULL)) {
+ retval = njs_array_alloc(vm, 0, NJS_ARRAY_SPARE);
+ if (nxt_slow_path(retval == NULL)) {
return NXT_ERROR;
}
- return njs_array_prototype_filter_continuation(vm, args, nargs, unused);
-}
-
-
-static njs_ret_t
-njs_array_prototype_filter_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- uint32_t index;
- nxt_int_t ret;
- njs_array_t *array;
- njs_array_filter_t *filter;
+ for (i = 0; i < length; i++) {
+ value = njs_array_start(array)[i];
- filter = njs_vm_continuation(vm);
+ if (njs_is_valid(&value)) {
+ ret = njs_array_iterator_call(vm, function, this_arg, &value, i,
+ array);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
- if (njs_is_true(&filter->iter.retval)) {
- ret = njs_array_add(vm, filter->array, &filter->value);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
+ if (njs_is_true(&vm->retval)) {
+ ret = njs_array_add(vm, retval, &value);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+ }
}
- }
- array = njs_array(&args[0]);
- index = njs_array_iterator_index(array, &filter->iter);
-
- if (index == NJS_ARRAY_INVALID_INDEX) {
- njs_set_array(&vm->retval, filter->array);
-
- return NXT_OK;
+ length = nxt_min(length, njs_array_len(array));
}
- /* GC: filter->value */
- filter->value = array->start[index];
+ njs_set_array(&vm->retval, retval);
- return njs_array_iterator_apply(vm, &filter->iter, args, nargs);
+ return NXT_OK;
}
njs_array_prototype_find(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
{
- nxt_int_t ret;
- njs_array_find_t *find;
-
- ret = njs_array_iterator_args(vm, args, nargs);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
+ uint32_t i, length;
+ nxt_int_t ret;
+ njs_value_t *array, value;
+ njs_function_t *function;
+ const njs_value_t *this_arg, *retval;
+
+ if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
+ njs_type_error(vm, "unexpected iterator arguments");
+ return NXT_ERROR;
}
- find = njs_vm_continuation(vm);
- find->iter.u.cont.function = njs_array_prototype_find_continuation;
-
- return njs_array_prototype_find_continuation(vm, args, nargs, unused);
-}
-
-
-static njs_ret_t
-njs_array_prototype_find_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- njs_array_t *array;
- njs_array_iter_t *iter;
- njs_array_find_t *find;
- const njs_value_t *retval;
+ array = &args[0];
+ length = njs_array_len(array);
+ function = njs_function(&args[1]);
+ this_arg = njs_arg(args, nargs, 2);
retval = &njs_value_undefined;
- find = njs_vm_continuation(vm);
- iter = &find->iter;
-
- if (!njs_is_true(&iter->retval)) {
- array = njs_array(&args[0]);
- iter->index++;
+ for (i = 0; i < length; i++) {
+ value = njs_array_start(array)[i];
- if (iter->index < iter->length && iter->index < array->length) {
- /* GC: find->value */
- find->value = array->start[iter->index];
+ if (!njs_is_valid(&value)) {
+ value = njs_value_undefined;
+ }
- return njs_array_prototype_find_apply(vm, iter, args, nargs);
+ ret = njs_array_iterator_call(vm, function, this_arg, &value, i, array);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
}
- } else {
- if (njs_is_valid(&find->value)) {
- retval = &find->value;
+ if (njs_is_true(&vm->retval)) {
+ retval = &value;
+ break;
}
+
+ length = nxt_min(length, njs_array_len(array));
}
vm->retval = *retval;
njs_array_prototype_find_index(njs_vm_t *vm, njs_value_t *args,
nxt_uint_t nargs, njs_index_t unused)
{
- nxt_int_t ret;
- njs_array_iter_t *iter;
-
- ret = njs_array_iterator_args(vm, args, nargs);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
+ double index;
+ uint32_t i, length;
+ nxt_int_t ret;
+ njs_value_t *array, value;
+ njs_function_t *function;
+ const njs_value_t *this_arg;
+
+ if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
+ njs_type_error(vm, "unexpected iterator arguments");
+ return NXT_ERROR;
}
- iter = njs_vm_continuation(vm);
- iter->u.cont.function = njs_array_prototype_find_index_continuation;
-
- return njs_array_prototype_find_index_continuation(vm, args, nargs, unused);
-}
+ array = &args[0];
+ length = njs_array_len(array);
+ function = njs_function(&args[1]);
+ this_arg = njs_arg(args, nargs, 2);
+ index = -1;
-static njs_ret_t
-njs_array_prototype_find_index_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- double index;
- njs_array_iter_t *iter;
+ for (i = 0; i < length; i++) {
+ value = njs_array_start(array)[i];
- iter = njs_vm_continuation(vm);
- index = iter->index;
+ if (!njs_is_valid(&value)) {
+ value = njs_value_undefined;
+ }
- if (!njs_is_true(&iter->retval)) {
- iter->index++;
+ ret = njs_array_iterator_call(vm, function, this_arg, &value, i, array);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
- if (iter->index < iter->length
- && iter->index < njs_array_len(&args[0]))
- {
- return njs_array_prototype_find_apply(vm, iter, args, nargs);
+ if (njs_is_true(&vm->retval)) {
+ index = i;
+ break;
}
- index = -1;
+ length = nxt_min(length, njs_array_len(array));
}
njs_set_number(&vm->retval, index);
}
-static njs_ret_t
-njs_array_prototype_find_apply(njs_vm_t *vm, njs_array_iter_t *iter,
- njs_value_t *args, nxt_uint_t nargs)
-{
- uint32_t n;
- const njs_value_t *value;
- njs_value_t arguments[4];
-
- /* GC: array elt, array */
-
- value = njs_arg(args, nargs, 2);
- arguments[0] = *value;
-
- n = iter->index;
- value = &njs_array_start(&args[0])[n];
-
- if (!njs_is_valid(value)) {
- value = &njs_value_undefined;
- }
-
- arguments[1] = *value;
-
- njs_set_number(&arguments[2], n);
-
- arguments[3] = args[0];
-
- return njs_function_apply(vm, njs_function(&args[1]), arguments, 4,
- (njs_index_t) &iter->retval);
-}
-
-
static njs_ret_t
njs_array_prototype_map(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
{
- nxt_int_t ret;
- njs_array_map_t *map;
-
- ret = njs_array_iterator_args(vm, args, nargs);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
- }
-
- map = njs_vm_continuation(vm);
- map->iter.u.cont.function = njs_array_prototype_map_continuation;
- njs_set_invalid(&map->iter.retval);
-
- map->array = njs_array_alloc(vm, njs_array_len(&args[0]), 0);
- if (nxt_slow_path(map->array == NULL)) {
+ uint32_t i, length, size;
+ nxt_int_t ret;
+ njs_array_t *retval;
+ njs_value_t *array, *value;
+ njs_function_t *function;
+ const njs_value_t *this_arg;
+
+ if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
+ njs_type_error(vm, "unexpected iterator arguments");
return NXT_ERROR;
}
- return njs_array_prototype_map_continuation(vm, args, nargs, unused);
-}
-
-
-static njs_ret_t
-njs_array_prototype_map_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- uint32_t index;
- njs_array_map_t *map;
+ array = &args[0];
+ length = njs_array_len(array);
+ function = njs_function(&args[1]);
+ this_arg = njs_arg(args, nargs, 2);
- map = njs_vm_continuation(vm);
+ size = length;
- if (njs_is_valid(&map->iter.retval)) {
- map->array->start[map->iter.index] = map->iter.retval;
- }
-
- index = njs_array_prototype_map_index(njs_array(&args[0]), map);
-
- if (index == NJS_ARRAY_INVALID_INDEX) {
- njs_set_array(&vm->retval, map->array);
-
- return NXT_OK;
+ retval = njs_array_alloc(vm, length, 0);
+ if (nxt_slow_path(retval == NULL)) {
+ return NXT_ERROR;
}
- return njs_array_iterator_apply(vm, &map->iter, args, nargs);
-}
-
+ for (i = 0; i < length; i++) {
+ njs_set_invalid(&retval->start[i]);
-static uint32_t
-njs_array_prototype_map_index(njs_array_t *array, njs_array_map_t *map)
-{
- uint32_t i, length;
- njs_value_t *start;
+ value = &njs_array_start(array)[i];
- start = map->array->start;
- length = nxt_min(array->length, map->iter.length);
+ if (njs_is_valid(value)) {
+ ret = njs_array_iterator_call(vm, function, this_arg, value, i,
+ array);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
- for (i = map->iter.index + 1; i < length; i++) {
- if (njs_is_valid(&array->start[i])) {
- map->iter.index = i;
- return i;
+ if (njs_is_valid(&vm->retval)) {
+ retval->start[i] = vm->retval;
+ }
}
- njs_set_invalid(&start[i]);
+ length = nxt_min(length, njs_array_len(array));
}
- while (i < map->iter.length) {
- njs_set_invalid(&start[i++]);
+ for ( ; i < size; i++) {
+ njs_set_invalid(&retval->start[i]);
}
- return NJS_ARRAY_INVALID_INDEX;
-}
-
-
-static njs_ret_t
-njs_array_prototype_reduce(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
- njs_index_t unused)
-{
- uint32_t n;
- nxt_int_t ret;
- njs_array_t *array;
- njs_array_iter_t *iter;
-
- ret = njs_array_iterator_args(vm, args, nargs);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
- }
-
- iter = njs_vm_continuation(vm);
- iter->u.cont.function = njs_array_prototype_reduce_continuation;
-
- if (nargs > 2) {
- iter->retval = args[2];
-
- } else {
- array = njs_array(&args[0]);
- n = njs_array_iterator_index(array, iter);
-
- if (n == NJS_ARRAY_INVALID_INDEX) {
- njs_type_error(vm, "invalid index");
- return NXT_ERROR;
- }
-
- iter->retval = array->start[n];
- }
+ njs_set_array(&vm->retval, retval);
- return njs_array_prototype_reduce_continuation(vm, args, nargs, unused);
+ return NXT_OK;
}
-static njs_ret_t
-njs_array_prototype_reduce_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
+nxt_inline njs_ret_t
+njs_array_iterator_reduce(njs_vm_t *vm, njs_function_t *function,
+ njs_value_t *accumulator, njs_value_t *value, uint32_t n,
+ njs_value_t *array)
{
- uint32_t n;
- njs_array_t *array;
- njs_value_t arguments[5];
- njs_array_iter_t *iter;
-
- iter = njs_vm_continuation(vm);
- array = njs_array(&args[0]);
-
- n = njs_array_iterator_index(array, iter);
-
- if (n == NJS_ARRAY_INVALID_INDEX) {
- vm->retval = iter->retval;
- return NXT_OK;
- }
-
- arguments[0] = njs_value_undefined;
+ njs_value_t arguments[5];
/* GC: array elt, array */
- arguments[1] = iter->retval;
-
- arguments[2] = array->start[n];
+ arguments[0] = njs_value_undefined;
+ arguments[1] = *accumulator;
+ arguments[2] = *value;
njs_set_number(&arguments[3], n);
+ arguments[4] = *array;
- arguments[4] = args[0];
-
- return njs_function_apply(vm, njs_function(&args[1]), arguments, 5,
- (njs_index_t) &iter->retval);
+ return njs_function_apply(vm, function, arguments, 5, accumulator);
}
static njs_ret_t
-njs_array_iterator_args(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs)
+njs_array_prototype_reduce(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
{
- njs_array_iter_t *iter;
-
- if (nargs > 1 && njs_is_array(&args[0]) && njs_is_function(&args[1])) {
-
- iter = njs_vm_continuation(vm);
- iter->length = njs_array_len(&args[0]);
- iter->retval.data.truth = 0;
- iter->index = NJS_ARRAY_INVALID_INDEX;
+ uint32_t i, length;
+ nxt_int_t ret;
+ njs_value_t accumulator, *array, *value;
+ njs_function_t *function;
- return NXT_OK;
+ if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
+ njs_type_error(vm, "unexpected iterator arguments");
+ return NXT_ERROR;
}
- njs_type_error(vm, "unexpected iterator arguments");
-
- return NXT_ERROR;
-}
-
+ array = &args[0];
+ length = njs_array_len(array);
+ function = njs_function(&args[1]);
-static uint32_t
-njs_array_iterator_index(njs_array_t *array, njs_array_iter_t *iter)
-{
- uint32_t i, length;
-
- length = nxt_min(array->length, iter->length);
+ njs_set_invalid(&accumulator);
- for (i = iter->index + 1; i < length; i++) {
- if (njs_is_valid(&array->start[i])) {
- iter->index = i;
- return i;
- }
+ if (nargs > 2) {
+ accumulator = args[2];
}
- return NJS_ARRAY_INVALID_INDEX;
-}
-
+ for (i = 0; i < length; i++) {
+ value = &njs_array_start(array)[i];
-static njs_ret_t
-njs_array_iterator_apply(njs_vm_t *vm, njs_array_iter_t *iter,
- njs_value_t *args, nxt_uint_t nargs)
-{
- uint32_t n;
- const njs_value_t *value;
- njs_value_t arguments[4];
+ if (njs_is_valid(value)) {
- /* GC: array elt, array */
+ if (!njs_is_valid(&accumulator)) {
+ accumulator = njs_array_start(array)[i];
+ continue;
+ }
- value = njs_arg(args, nargs, 2);
- arguments[0] = *value;
+ ret = njs_array_iterator_reduce(vm, function, &accumulator, value,
+ i, array);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+ }
- n = iter->index;
- arguments[1] = njs_array_start(&args[0])[n];
+ length = nxt_min(length, njs_array_len(array));
+ }
- njs_set_number(&arguments[2], n);
+ if (!njs_is_valid(&accumulator)) {
+ njs_type_error(vm, "invalid index");
+ return NXT_ERROR;
+ }
- arguments[3] = args[0];
+ vm->retval = accumulator;
- return njs_function_apply(vm, njs_function(&args[1]), arguments, 4,
- (njs_index_t) &iter->retval);
+ return NXT_OK;
}
njs_array_prototype_reduce_right(njs_vm_t *vm, njs_value_t *args,
nxt_uint_t nargs, njs_index_t unused)
{
- uint32_t n;
- njs_ret_t ret;
- njs_array_t *array;
- njs_array_iter_t *iter;
-
- ret = njs_array_iterator_args(vm, args, nargs);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
+ int32_t i;
+ uint32_t length;
+ nxt_int_t ret;
+ njs_value_t accumulator, *array, *value;
+ njs_function_t *function;
+
+ if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
+ njs_type_error(vm, "unexpected iterator arguments");
+ return NXT_ERROR;
}
- iter = njs_vm_continuation(vm);
- iter->u.cont.function = njs_array_prototype_reduce_right_continuation;
-
- if (nargs > 2) {
- iter->retval = args[2];
-
- } else {
- array = njs_array(&args[0]);
- n = njs_array_reduce_right_index(array, iter);
-
- if (n == NJS_ARRAY_INVALID_INDEX) {
- njs_type_error(vm, "invalid index");
+ array = &args[0];
+ length = njs_array_len(array);
+ function = njs_function(&args[1]);
- return NXT_ERROR;
- }
+ njs_set_invalid(&accumulator);
- iter->retval = array->start[n];
+ if (nargs > 2) {
+ accumulator = args[2];
}
- return njs_array_prototype_reduce_right_continuation(vm, args, nargs,
- unused);
-}
-
+ for (i = length - 1; i >= 0; i--) {
+ value = &njs_array_start(array)[i];
-static njs_ret_t
-njs_array_prototype_reduce_right_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- uint32_t n;
- njs_array_t *array;
- njs_value_t arguments[5];
- njs_array_iter_t *iter;
+ if (njs_is_valid(value)) {
- iter = njs_vm_continuation(vm);
- array = njs_array(&args[0]);
+ if (!njs_is_valid(&accumulator)) {
+ accumulator = njs_array_start(array)[i];
+ continue;
+ }
- n = njs_array_reduce_right_index(array, iter);
+ ret = njs_array_iterator_reduce(vm, function, &accumulator, value,
+ i, array);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+ }
- if (n == NJS_ARRAY_INVALID_INDEX) {
- vm->retval = iter->retval;
- return NXT_OK;
+ length = nxt_min(length, njs_array_len(array));
}
- arguments[0] = njs_value_undefined;
-
- /* GC: array elt, array */
- arguments[1] = iter->retval;
-
- arguments[2] = array->start[n];
-
- njs_set_number(&arguments[3], n);
-
- arguments[4] = args[0];
-
- return njs_function_apply(vm, njs_function(&args[1]), arguments, 5,
- (njs_index_t) &iter->retval);
-}
-
-
-static uint32_t
-njs_array_reduce_right_index(njs_array_t *array, njs_array_iter_t *iter)
-{
- uint32_t n;
-
- n = nxt_min(iter->index, array->length) - 1;
-
- while (n != NJS_ARRAY_INVALID_INDEX) {
-
- if (njs_is_valid(&array->start[n])) {
- iter->index = n;
- break;
- }
-
- n--;
+ if (!njs_is_valid(&accumulator)) {
+ njs_type_error(vm, "invalid index");
+ return NXT_ERROR;
}
- return n;
+ vm->retval = accumulator;
+
+ return NXT_OK;
}
static const njs_function_t njs_array_string_sort_function = {
.object = { .type = NJS_FUNCTION, .shared = 1, .extensible = 1 },
.native = 1,
- .continuation_size = NJS_CONTINUATION_SIZE,
.args_types = { NJS_SKIP_ARG, NJS_STRING_ARG, NJS_STRING_ARG },
.args_offset = 1,
.u.native = njs_array_string_sort,
njs_array_prototype_sort(njs_vm_t *vm, njs_value_t *args,
nxt_uint_t nargs, njs_index_t unused)
{
- njs_array_sort_t *sort;
-
- if (njs_is_array(&args[0]) && njs_array_len(&args[0]) > 1) {
-
- sort = njs_vm_continuation(vm);
- sort->u.cont.function = njs_array_prototype_sort_continuation;
- sort->current = 0;
- sort->retval = njs_value_zero;
+ uint32_t n, index, current;
+ nxt_int_t ret;
+ njs_array_t *array;
+ njs_value_t retval, value, *start, arguments[3];;
+ njs_function_t *function;
- if (nargs > 1 && njs_is_function(&args[1])) {
- sort->function = njs_function(&args[1]);
-
- } else {
- sort->function = (njs_function_t *) &njs_array_string_sort_function;
- }
-
- return njs_array_prototype_sort_continuation(vm, args, nargs, unused);
+ if (!njs_is_array(&args[0]) || njs_array_len(&args[0]) == 0) {
+ vm->retval = args[0];
+ return NXT_OK;
}
- vm->retval = args[0];
-
- return NXT_OK;
-}
-
+ if (nargs > 1 && njs_is_function(&args[1])) {
+ function = njs_function(&args[1]);
-static njs_ret_t
-njs_array_prototype_sort_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- uint32_t n;
- njs_array_t *array;
- njs_value_t value, *start, arguments[3];
- njs_array_sort_t *sort;
+ } else {
+ function = (njs_function_t *) &njs_array_string_sort_function;
+ }
+ index = 0;
+ current = 0;
+ retval = njs_value_zero;
array = njs_array(&args[0]);
start = array->start;
- sort = njs_vm_continuation(vm);
+start:
- if (njs_is_number(&sort->retval)) {
+ if (njs_is_number(&retval)) {
/*
* The sort function is implemented with the insertion sort algorithm.
* "goto next" moves control to the appropriate step of the algorithm.
* The first iteration also goes there because sort->retval is zero.
*/
- if (njs_number(&sort->retval) <= 0) {
+ if (njs_number(&retval) <= 0) {
goto next;
}
- n = sort->index;
+ n = index;
swap:
arguments[1] = start[n - 1];
arguments[2] = start[n];
- sort->index = n;
+ index = n;
+
+ ret = njs_function_apply(vm, function, arguments, 3,
+ &retval);
+
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
- return njs_function_apply(vm, sort->function,
- arguments, 3,
- (njs_index_t) &sort->retval);
+ goto start;
}
/* Move invalid values to the end of array. */
next:
- sort->current++;
- n = sort->current;
+ current++;
+ n = current;
} while (n < array->length);
}
.type = NJS_METHOD,
.name = njs_string("slice"),
.value = njs_native_function(njs_array_prototype_slice,
- njs_continuation_size(njs_array_slice_t),
NJS_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("push"),
- .value = njs_native_function(njs_array_prototype_push, 0, 0),
+ .value = njs_native_function(njs_array_prototype_push, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("pop"),
- .value = njs_native_function(njs_array_prototype_pop, 0, 0),
+ .value = njs_native_function(njs_array_prototype_pop, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("unshift"),
- .value = njs_native_function(njs_array_prototype_unshift, 0, 0),
+ .value = njs_native_function(njs_array_prototype_unshift, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("shift"),
- .value = njs_native_function(njs_array_prototype_shift, 0, 0),
+ .value = njs_native_function(njs_array_prototype_shift, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("splice"),
- .value = njs_native_function(njs_array_prototype_splice, 0,
+ .value = njs_native_function(njs_array_prototype_splice,
NJS_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("reverse"),
- .value = njs_native_function(njs_array_prototype_reverse, 0,
- NJS_OBJECT_ARG),
+ .value = njs_native_function(njs_array_prototype_reverse,
+ NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_array_prototype_to_string,
- NJS_CONTINUATION_SIZE, 0),
+ .value = njs_native_function(njs_array_prototype_to_string, 0),
.writable = 1,
.configurable = 1,
},
.type = NJS_METHOD,
.name = njs_string("join"),
.value = njs_native_function(njs_array_prototype_join,
- njs_continuation_size(njs_array_join_t),
NJS_OBJECT_ARG, NJS_STRING_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("concat"),
- .value = njs_native_function(njs_array_prototype_concat, 0, 0),
+ .value = njs_native_function(njs_array_prototype_concat, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("indexOf"),
- .value = njs_native_function(njs_array_prototype_index_of, 0,
+ .value = njs_native_function(njs_array_prototype_index_of,
NJS_OBJECT_ARG, NJS_SKIP_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("lastIndexOf"),
- .value = njs_native_function(njs_array_prototype_last_index_of, 0,
+ .value = njs_native_function(njs_array_prototype_last_index_of,
NJS_OBJECT_ARG, NJS_SKIP_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("includes"),
- .value = njs_native_function(njs_array_prototype_includes, 0,
+ .value = njs_native_function(njs_array_prototype_includes,
NJS_OBJECT_ARG, NJS_SKIP_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("forEach"),
- .value = njs_native_function(njs_array_prototype_for_each,
- njs_continuation_size(njs_array_iter_t), 0),
+ .value = njs_native_function(njs_array_prototype_for_each, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("some"),
- .value = njs_native_function(njs_array_prototype_some,
- njs_continuation_size(njs_array_iter_t), 0),
+ .value = njs_native_function(njs_array_prototype_some, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("every"),
- .value = njs_native_function(njs_array_prototype_every,
- njs_continuation_size(njs_array_iter_t), 0),
+ .value = njs_native_function(njs_array_prototype_every, 0),
.writable = 1,
.configurable = 1,
},
.type = NJS_METHOD,
.name = njs_string("fill"),
.value = njs_native_function(njs_array_prototype_fill,
- njs_continuation_size(njs_array_fill_t),
NJS_OBJECT_ARG, NJS_SKIP_ARG, NJS_NUMBER_ARG,
NJS_NUMBER_ARG),
.writable = 1,
{
.type = NJS_METHOD,
.name = njs_string("filter"),
- .value = njs_native_function(njs_array_prototype_filter,
- njs_continuation_size(njs_array_filter_t), 0),
+ .value = njs_native_function(njs_array_prototype_filter, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("find"),
- .value = njs_native_function(njs_array_prototype_find,
- njs_continuation_size(njs_array_find_t), 0),
+ .value = njs_native_function(njs_array_prototype_find, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("findIndex"),
- .value = njs_native_function(njs_array_prototype_find_index,
- njs_continuation_size(njs_array_iter_t), 0),
+ .value = njs_native_function(njs_array_prototype_find_index, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("map"),
- .value = njs_native_function(njs_array_prototype_map,
- njs_continuation_size(njs_array_map_t), 0),
+ .value = njs_native_function(njs_array_prototype_map, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("reduce"),
- .value = njs_native_function(njs_array_prototype_reduce,
- njs_continuation_size(njs_array_iter_t), 0),
+ .value = njs_native_function(njs_array_prototype_reduce, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("reduceRight"),
- .value = njs_native_function(njs_array_prototype_reduce_right,
- njs_continuation_size(njs_array_iter_t), 0),
+ .value = njs_native_function(njs_array_prototype_reduce_right, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("sort"),
- .value = njs_native_function(njs_array_prototype_sort,
- njs_continuation_size(njs_array_iter_t), 0),
+ .value = njs_native_function(njs_array_prototype_sort, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("valueOf"),
- .value = njs_native_function(njs_boolean_prototype_value_of, 0, 0),
+ .value = njs_native_function(njs_boolean_prototype_value_of, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_boolean_prototype_to_string, 0, 0),
+ .value = njs_native_function(njs_boolean_prototype_to_string, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("dump"),
- .value = njs_native_function(njs_dump_value, 0,
+ .value = njs_native_function(njs_dump_value,
NJS_SKIP_ARG, NJS_SKIP_ARG, NJS_NUMBER_ARG),
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_hash_prototype_to_string, 0, 0),
+ .value = njs_native_function(njs_hash_prototype_to_string, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("update"),
- .value = njs_native_function(njs_hash_prototype_update, 0,
+ .value = njs_native_function(njs_hash_prototype_update,
NJS_OBJECT_ARG, NJS_SKIP_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("digest"),
- .value = njs_native_function(njs_hash_prototype_digest, 0,
+ .value = njs_native_function(njs_hash_prototype_digest,
NJS_OBJECT_ARG, NJS_SKIP_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_hmac_prototype_to_string, 0, 0),
+ .value = njs_native_function(njs_hmac_prototype_to_string, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("update"),
- .value = njs_native_function(njs_hmac_prototype_update, 0,
+ .value = njs_native_function(njs_hmac_prototype_update,
NJS_OBJECT_ARG, NJS_SKIP_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("digest"),
- .value = njs_native_function(njs_hmac_prototype_digest, 0,
+ .value = njs_native_function(njs_hmac_prototype_digest,
NJS_OBJECT_ARG, NJS_SKIP_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("createHash"),
- .value = njs_native_function(njs_crypto_create_hash, 0,
+ .value = njs_native_function(njs_crypto_create_hash,
NJS_SKIP_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("createHmac"),
- .value = njs_native_function(njs_crypto_create_hmac, 0,
+ .value = njs_native_function(njs_crypto_create_hmac,
NJS_SKIP_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("UTC"),
- .value = njs_native_function(njs_date_utc, 0, 0),
+ .value = njs_native_function(njs_date_utc, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("now"),
- .value = njs_native_function(njs_date_now, 0, 0),
+ .value = njs_native_function(njs_date_now, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("parse"),
- .value = njs_native_function(njs_date_parse, 0,
- NJS_SKIP_ARG, NJS_STRING_ARG),
+ .value = njs_native_function(njs_date_parse,
+ NJS_SKIP_ARG, NJS_STRING_ARG),
.writable = 1,
.configurable = 1,
},
prop = njs_object_property(vm, njs_object(&args[0]), &lhq);
if (nxt_fast_path(prop != NULL && njs_is_function(&prop->value))) {
- return njs_function_call(vm, njs_function(&prop->value), args,
- nargs, (njs_index_t) &vm->retval);
+ return njs_function_apply(vm, njs_function(&prop->value), args,
+ nargs, &vm->retval);
}
}
{
.type = NJS_METHOD,
.name = njs_string("valueOf"),
- .value = njs_native_function(njs_date_prototype_value_of, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_value_of, NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_date_prototype_to_string, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_to_string,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toDateString"),
- .value = njs_native_function(njs_date_prototype_to_date_string, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_to_date_string,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toTimeString"),
- .value = njs_native_function(njs_date_prototype_to_time_string, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_to_time_string,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toLocaleString"),
- .value = njs_native_function(njs_date_prototype_to_string, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_to_string,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_long_string("toLocaleDateString"),
- .value = njs_native_function(njs_date_prototype_to_date_string, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_to_date_string,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_long_string("toLocaleTimeString"),
- .value = njs_native_function(njs_date_prototype_to_time_string, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_to_time_string,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toUTCString"),
- .value = njs_native_function(njs_date_prototype_to_utc_string, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_to_utc_string,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toISOString"),
- .value = njs_native_function(njs_date_prototype_to_iso_string, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_to_iso_string,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getTime"),
- .value = njs_native_function(njs_date_prototype_value_of, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_value_of, NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getFullYear"),
- .value = njs_native_function(njs_date_prototype_get_full_year, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_full_year,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getUTCFullYear"),
- .value = njs_native_function(njs_date_prototype_get_utc_full_year, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_utc_full_year,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getMonth"),
- .value = njs_native_function(njs_date_prototype_get_month, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_month,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getUTCMonth"),
- .value = njs_native_function(njs_date_prototype_get_utc_month, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_utc_month,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getDate"),
- .value = njs_native_function(njs_date_prototype_get_date, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_date,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getUTCDate"),
- .value = njs_native_function(njs_date_prototype_get_utc_date, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_utc_date,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getDay"),
- .value = njs_native_function(njs_date_prototype_get_day, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_day, NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getUTCDay"),
- .value = njs_native_function(njs_date_prototype_get_utc_day, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_utc_day,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getHours"),
- .value = njs_native_function(njs_date_prototype_get_hours, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_hours,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getUTCHours"),
- .value = njs_native_function(njs_date_prototype_get_utc_hours, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_utc_hours,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getMinutes"),
- .value = njs_native_function(njs_date_prototype_get_minutes, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_minutes,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getUTCMinutes"),
- .value = njs_native_function(njs_date_prototype_get_utc_minutes, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_utc_minutes,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getSeconds"),
- .value = njs_native_function(njs_date_prototype_get_seconds, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_seconds,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("getUTCSeconds"),
- .value = njs_native_function(njs_date_prototype_get_seconds, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_seconds,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_long_string("getMilliseconds"),
- .value = njs_native_function(njs_date_prototype_get_milliseconds, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_milliseconds,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_long_string("getUTCMilliseconds"),
- .value = njs_native_function(njs_date_prototype_get_milliseconds, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_milliseconds,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_long_string("getTimezoneOffset"),
- .value = njs_native_function(njs_date_prototype_get_timezone_offset, 0,
- NJS_DATE_ARG),
+ .value = njs_native_function(njs_date_prototype_get_timezone_offset,
+ NJS_DATE_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("setTime"),
- .value = njs_native_function(njs_date_prototype_set_time, 0,
- NJS_DATE_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_date_prototype_set_time,
+ NJS_DATE_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_long_string("setMilliseconds"),
- .value = njs_native_function(njs_date_prototype_set_milliseconds, 0,
- NJS_DATE_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_date_prototype_set_milliseconds,
+ NJS_DATE_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_long_string("setUTCMilliseconds"),
- .value = njs_native_function(njs_date_prototype_set_milliseconds, 0,
- NJS_DATE_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_date_prototype_set_milliseconds,
+ NJS_DATE_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("setSeconds"),
- .value = njs_native_function(njs_date_prototype_set_seconds, 0,
- NJS_DATE_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_date_prototype_set_seconds,
+ NJS_DATE_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("setUTCSeconds"),
- .value = njs_native_function(njs_date_prototype_set_seconds, 0,
+ .value = njs_native_function(njs_date_prototype_set_seconds,
NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("setMinutes"),
- .value = njs_native_function(njs_date_prototype_set_minutes, 0,
+ .value = njs_native_function(njs_date_prototype_set_minutes,
NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
NJS_NUMBER_ARG),
.writable = 1,
{
.type = NJS_METHOD,
.name = njs_string("setUTCMinutes"),
- .value = njs_native_function(njs_date_prototype_set_utc_minutes, 0,
+ .value = njs_native_function(njs_date_prototype_set_utc_minutes,
NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
NJS_NUMBER_ARG),
.writable = 1,
{
.type = NJS_METHOD,
.name = njs_string("setHours"),
- .value = njs_native_function(njs_date_prototype_set_hours, 0,
+ .value = njs_native_function(njs_date_prototype_set_hours,
NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
NJS_NUMBER_ARG, NJS_NUMBER_ARG),
.writable = 1,
{
.type = NJS_METHOD,
.name = njs_string("setUTCHours"),
- .value = njs_native_function(njs_date_prototype_set_utc_hours, 0,
+ .value = njs_native_function(njs_date_prototype_set_utc_hours,
NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
NJS_NUMBER_ARG, NJS_NUMBER_ARG),
.writable = 1,
{
.type = NJS_METHOD,
.name = njs_string("setDate"),
- .value = njs_native_function(njs_date_prototype_set_date, 0,
+ .value = njs_native_function(njs_date_prototype_set_date,
NJS_DATE_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("setUTCDate"),
- .value = njs_native_function(njs_date_prototype_set_utc_date, 0,
+ .value = njs_native_function(njs_date_prototype_set_utc_date,
NJS_DATE_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("setMonth"),
- .value = njs_native_function(njs_date_prototype_set_month, 0,
+ .value = njs_native_function(njs_date_prototype_set_month,
NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("setUTCMonth"),
- .value = njs_native_function(njs_date_prototype_set_utc_month, 0,
+ .value = njs_native_function(njs_date_prototype_set_utc_month,
NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("setFullYear"),
- .value = njs_native_function(njs_date_prototype_set_full_year, 0,
+ .value = njs_native_function(njs_date_prototype_set_full_year,
NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
NJS_NUMBER_ARG),
.writable = 1,
{
.type = NJS_METHOD,
.name = njs_string("setUTCFullYear"),
- .value = njs_native_function(njs_date_prototype_set_utc_full_year, 0,
+ .value = njs_native_function(njs_date_prototype_set_utc_full_year,
NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
NJS_NUMBER_ARG),
.writable = 1,
{
.type = NJS_METHOD,
.name = njs_string("toJSON"),
- .value = njs_native_function(njs_date_prototype_to_json,
- NJS_CONTINUATION_SIZE, 0),
+ .value = njs_native_function(njs_date_prototype_to_json, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("valueOf"),
- .value = njs_native_function(njs_error_prototype_value_of, 0, 0),
+ .value = njs_native_function(njs_error_prototype_value_of, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_error_prototype_to_string, 0, 0),
+ .value = njs_native_function(njs_error_prototype_to_string, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_internal_error_prototype_to_string,
- 0, 0),
+ .value = njs_native_function(njs_internal_error_prototype_to_string, 0),
.writable = 1,
.configurable = 1,
},
#include <errno.h>
-typedef struct {
- union {
- njs_continuation_t cont;
- u_char padding[NJS_CONTINUATION_SIZE];
- } u;
-
- nxt_bool_t done;
-} njs_fs_cont_t;
-
-
typedef struct {
nxt_str_t name;
int value;
nxt_uint_t nargs, int default_flags);
static njs_ret_t njs_fs_write_file_sync_internal(njs_vm_t *vm,
njs_value_t *args, nxt_uint_t nargs, int default_flags);
-static njs_ret_t njs_fs_done(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused);
static njs_ret_t njs_fs_error(njs_vm_t *vm, const char *syscall,
const char *description, njs_value_t *path, int errn, njs_value_t *retval);
const char *path, *syscall, *description;
struct stat sb;
njs_value_t *callback, arguments[3];
- njs_fs_cont_t *cont;
njs_object_prop_t *prop;
nxt_lvlhsh_query_t lhq;
arguments[0] = njs_value_undefined;
- cont = njs_vm_continuation(vm);
- cont->u.cont.function = njs_fs_done;
+ ret = njs_function_apply(vm, njs_function(callback), arguments, 3,
+ &vm->retval);
+
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ vm->retval = njs_value_undefined;
- return njs_function_apply(vm, njs_function(callback),
- arguments, 3, (njs_index_t) &vm->retval);
+ return NXT_OK;
fail:
njs_ret_t ret;
const char *path, *syscall, *description;
njs_value_t *callback, *mode, arguments[2];
- njs_fs_cont_t *cont;
njs_object_prop_t *prop;
nxt_lvlhsh_query_t lhq;
arguments[0] = njs_value_undefined;
- cont = njs_vm_continuation(vm);
- cont->u.cont.function = njs_fs_done;
+ ret = njs_function_apply(vm, njs_function(callback), arguments, 2,
+ &vm->retval);
- return njs_function_apply(vm, njs_function(callback),
- arguments, 2, (njs_index_t) &vm->retval);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ vm->retval = njs_value_undefined;
+
+ return NXT_OK;
}
}
-static njs_ret_t njs_fs_done(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- vm->retval = njs_value_undefined;
-
- return NJS_OK;
-}
-
-
static njs_ret_t njs_fs_error(njs_vm_t *vm, const char *syscall,
const char *description, njs_value_t *path, int errn, njs_value_t *retval)
{
{
.type = NJS_METHOD,
.name = njs_string("readFile"),
- .value = njs_native_function(njs_fs_read_file,
- njs_continuation_size(njs_fs_cont_t), 0),
+ .value = njs_native_function(njs_fs_read_file, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("readFileSync"),
- .value = njs_native_function(njs_fs_read_file_sync, 0, 0),
+ .value = njs_native_function(njs_fs_read_file_sync, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("appendFile"),
- .value = njs_native_function(njs_fs_append_file,
- njs_continuation_size(njs_fs_cont_t), 0),
+ .value = njs_native_function(njs_fs_append_file, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("appendFileSync"),
- .value = njs_native_function(njs_fs_append_file_sync,
- njs_continuation_size(njs_fs_cont_t), 0),
+ .value = njs_native_function(njs_fs_append_file_sync, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("writeFile"),
- .value = njs_native_function(njs_fs_write_file,
- njs_continuation_size(njs_fs_cont_t), 0),
+ .value = njs_native_function(njs_fs_write_file, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("writeFileSync"),
- .value = njs_native_function(njs_fs_write_file_sync,
- njs_continuation_size(njs_fs_cont_t), 0),
+ .value = njs_native_function(njs_fs_write_file_sync, 0),
.writable = 1,
.configurable = 1,
},
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 continuation_size, nxt_bool_t ctor)
+ nxt_bool_t ctor)
{
size_t size;
- u_char *continuation;
nxt_uint_t n;
njs_value_t *value, *bound;
njs_native_frame_t *frame;
- continuation_size = nxt_max(continuation_size, function->continuation_size);
-
- size = NJS_NATIVE_FRAME_SIZE + continuation_size
+ size = NJS_NATIVE_FRAME_SIZE
+ (function->args_offset + nargs) * sizeof(njs_value_t);
frame = njs_function_frame_alloc(vm, size);
frame->nargs = function->args_offset + nargs;
frame->ctor = ctor;
- continuation = (u_char *) frame + NJS_NATIVE_FRAME_SIZE;
-
- if (continuation_size > 0) {
- frame->continuation = (njs_continuation_t *) continuation;
- }
-
- value = (njs_value_t *) (continuation + continuation_size);
+ value = (njs_value_t *) ((u_char *) frame + NJS_NATIVE_FRAME_SIZE);
frame->arguments = value;
bound = function->bound;
njs_ret_t
-njs_function_call(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t retval)
+njs_function_call(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
+ njs_value_t *args, nxt_uint_t nargs, njs_value_t *retval)
{
- u_char *return_address;
- njs_ret_t ret;
- njs_native_frame_t *frame;
- njs_continuation_t *cont;
+ njs_ret_t ret;
+ njs_value_t dst nxt_aligned(16);
- ret = njs_function_frame(vm, function, &args[0], &args[1], nargs - 1, 0, 0);
+ ret = njs_function_frame(vm, function, this, args, nargs, 0);
if (nxt_slow_path(ret != NXT_OK)) {
return ret;
}
- frame = vm->top_frame;
- frame->call = 1;
-
- return_address = vm->current;
-
- if (function->native) {
+ ret = njs_function_frame_invoke(vm, (njs_index_t) &dst);
- if (function->continuation_size != 0) {
- cont = njs_vm_continuation(vm);
- cont->return_address = return_address;
- }
-
- ret = njs_function_native_call(vm, function->u.native, frame->arguments,
- function->args_types, frame->nargs,
- (njs_index_t) retval, return_address);
-
- } else {
- ret = njs_function_lambda_call(vm, retval, return_address);
-
- if (nxt_fast_path(ret == NJS_APPLIED)) {
- ret = njs_vmcode_run(vm);
- }
+ if (ret == NXT_OK) {
+ *retval = dst;
}
return ret;
njs_ret_t
-njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval,
- u_char *return_address)
+njs_function_lambda_call(njs_vm_t *vm)
{
size_t size;
njs_ret_t ret;
njs_function_lambda_t *lambda;
frame = (njs_frame_t *) vm->top_frame;
-
- frame->retval = retval;
- frame->return_address = return_address;
-
function = frame->native.function;
+ frame->return_address = vm->current;
+
lambda = function->u.lambda;
vm->current = lambda->start;
vm->active_frame = frame;
- return NJS_APPLIED;
+ return njs_vmcode_run(vm);
}
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, u_char *return_address)
+njs_function_native_call(njs_vm_t *vm)
{
njs_ret_t ret;
njs_value_t *value;
+ njs_frame_t *frame;
njs_function_t *function;
- njs_native_frame_t *frame;
+ njs_native_frame_t *native, *previous;
+
+ native = vm->top_frame;
+ frame = (njs_frame_t *) native;
+ function = native->function;
- ret = njs_normalize_args(vm, args, args_types, nargs);
+ ret = njs_normalize_args(vm, native->arguments, function->args_types,
+ native->nargs);
if (ret != NJS_OK) {
return ret;
}
- ret = native(vm, args, nargs, retval);
-
- /*
- * A native method can return:
- * NXT_OK on method success;
- * NJS_APPLIED by Function.apply() and Function.call();
- * NXT_AGAIN to postpone nJSVM processing;
- * NXT_ERROR.
- *
- * The callee arguments must be preserved
- * for NJS_APPLIED and NXT_AGAIN cases.
- */
- frame = vm->top_frame;
-
- if (ret == NXT_OK || (frame->call && ret == NXT_ERROR)) {
- vm->top_frame = njs_function_previous_frame(frame);
+ ret = function->u.native(vm, native->arguments, native->nargs,
+ frame->retval);
- /*
- * If a retval is in a callee arguments scope it
- * must be in the previous callee arguments scope.
- */
- args = vm->top_frame->arguments;
- function = vm->top_frame->function;
-
- if (function != NULL) {
- args += function->args_offset;
- }
-
- vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = args;
+ if (nxt_slow_path(ret == NXT_ERROR)) {
+ return ret;
+ }
- if (!frame->skip) {
- value = njs_vmcode_operand(vm, retval);
- /*
- * GC: value external/internal++ depending
- * on vm->retval and retval type
- */
- *value = vm->retval;
- }
+ if (ret == NJS_DECLINED) {
+ return NXT_OK;
+ }
- vm->current = return_address;
+ previous = njs_function_previous_frame(native);
- njs_function_frame_free(vm, frame);
+ njs_vm_scopes_restore(vm, frame, previous);
- return ret;
+ if (!native->skip) {
+ value = njs_vmcode_operand(vm, frame->retval);
+ /*
+ * GC: value external/internal++ depending
+ * on vm->retval and retval type
+ */
+ *value = vm->retval;
}
- return ret;
+ njs_function_frame_free(vm, native);
+
+ return NXT_OK;
}
void
-njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame)
+njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *native)
{
njs_native_frame_t *previous;
do {
- previous = frame->previous;
-
- if (frame->continuation != NULL) {
- vm->current = frame->continuation->return_address;
- }
+ previous = native->previous;
/* GC: free frame->local, etc. */
- if (frame->size != 0) {
- vm->stack_size -= frame->size;
- nxt_mp_free(vm->mem_pool, frame);
+ if (native->size != 0) {
+ vm->stack_size -= native->size;
+ nxt_mp_free(vm->mem_pool, native);
}
- frame = previous;
-
- } while (frame->skip);
+ native = previous;
+ } while (native->skip);
}
function = njs_function(&args[0]);
- ret = njs_function_activate(vm, function, this, &args[2], nargs, retval,
- sizeof(njs_vmcode_function_call_t));
- if (nxt_slow_path(ret == NXT_ERROR)) {
+ /* Skip the "call" method frame. */
+ vm->top_frame->skip = 1;
+
+ 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->top_frame->previous->skip = 1;
+ ret = njs_function_frame_invoke(vm, retval);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
- return NJS_APPLIED;
+ return NJS_DECLINED;
}
return NXT_ERROR;
}
- ret = njs_value_property(vm, arr_like, &njs_string_length, &length, 0);
+ ret = njs_value_property(vm, arr_like, &njs_string_length, &length);
if (nxt_slow_path(ret == NXT_ERROR)) {
return ret;
}
for (i = 0; i < nargs; i++) {
njs_uint32_to_string(&name, i);
- ret = njs_value_property(vm, arr_like, &name, &args[i], 0);
+ ret = njs_value_property(vm, arr_like, &name, &args[i]);
if (nxt_slow_path(ret == NXT_ERROR)) {
return ret;
}
activate:
- ret = njs_function_activate(vm, func, 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;
+ vm->top_frame->skip = 1;
- return NJS_APPLIED;
-}
-
-
-njs_ret_t
-njs_function_activate(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- njs_index_t retval, size_t advance)
-{
- u_char *return_address;
- njs_ret_t ret;
- njs_continuation_t *cont;
-
- ret = njs_function_frame(vm, function, this, args, nargs,
- NJS_CONTINUATION_SIZE, 0);
+ ret = njs_function_frame(vm, func, (njs_value_t *) this, args, nargs, 0);
if (nxt_slow_path(ret != NXT_OK)) {
return ret;
}
- return_address = vm->current + advance;
-
- if (function->native) {
- cont = njs_vm_continuation(vm);
-
- cont->function = function->u.native;
- cont->args_types = function->args_types;
- cont->retval = retval;
- cont->return_address = return_address;
-
- vm->current = (u_char *) njs_continuation_nexus;
-
- ret = NJS_APPLIED;
-
- } else {
- ret = njs_function_lambda_call(vm, retval, return_address);
+ ret = njs_function_frame_invoke(vm, retval);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
}
- return ret;
+ return NJS_DECLINED;
}
{
.type = NJS_METHOD,
.name = njs_string("call"),
- .value = njs_native_function(njs_function_prototype_call, 0, 0),
+ .value = njs_native_function(njs_function_prototype_call, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("apply"),
- .value = njs_native_function(njs_function_prototype_apply, 0, 0),
+ .value = njs_native_function(njs_function_prototype_apply, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("bind"),
- .value = njs_native_function(njs_function_prototype_bind, 0, 0),
+ .value = njs_native_function(njs_function_prototype_bind, 0),
.writable = 1,
.configurable = 1,
},
#define NJS_FRAME_SPARE_SIZE 512
-typedef struct {
- njs_function_native_t function;
- uint8_t *args_types;
- u_char *return_address;
- njs_index_t retval;
-} njs_continuation_t;
-
-
-#define njs_vm_continuation(vm) \
- (void *) ((vm)->top_frame->continuation)
-
-#define njs_continuation_size(size) \
- nxt_align_size(sizeof(size), sizeof(njs_value_t))
-
-#define NJS_CONTINUATION_SIZE njs_continuation_size(njs_continuation_t)
-
-
typedef struct njs_exception_s njs_exception_t;
struct njs_exception_s {
njs_function_t *function;
njs_native_frame_t *previous;
- njs_continuation_t *continuation;
-
njs_value_t *arguments;
njs_object_t *arguments_object;
nxt_uint_t nargs, njs_index_t unused);
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 continuation_size, nxt_bool_t ctor);
+ nxt_bool_t ctor);
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_activate(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- njs_index_t retval, size_t advance);
njs_ret_t njs_function_call(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_lambda_call(njs_vm_t *vm, njs_index_t retval,
- u_char *return_address);
-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, u_char *return_address);
+ njs_value_t *this, njs_value_t *args, nxt_uint_t nargs,
+ njs_value_t *retval);
+njs_ret_t njs_function_lambda_call(njs_vm_t *vm);
+njs_ret_t njs_function_native_call(njs_vm_t *vm);
void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
nxt_inline 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,
- size_t continuation_size, nxt_bool_t ctor)
+ nxt_bool_t ctor)
{
if (function->native) {
- return njs_function_native_frame(vm, function, this, args, nargs,
- continuation_size, ctor);
+ return njs_function_native_frame(vm, function, this, args, nargs, ctor);
} else {
return njs_function_lambda_frame(vm, function, this, args, nargs, ctor);
}
-nxt_inline njs_ret_t
-njs_function_apply(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
-{
- return njs_function_activate(vm, function, &args[0], &args[1], nargs - 1,
- retval, 0);
-}
-
-
nxt_inline njs_native_frame_t *
njs_function_previous_frame(njs_native_frame_t *frame)
{
}
+nxt_inline njs_ret_t
+njs_function_frame_invoke(njs_vm_t *vm, njs_index_t retval)
+{
+ njs_frame_t *frame;
+
+ frame = (njs_frame_t *) vm->top_frame;
+
+ frame->retval = retval;
+
+ if (frame->native.function->native) {
+ return njs_function_native_call(vm);
+
+ } else {
+ return njs_function_lambda_call(vm);
+ }
+}
+
+
+nxt_inline njs_ret_t
+njs_function_apply(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
+ nxt_uint_t nargs, njs_value_t *retval)
+{
+ return njs_function_call(vm, function, &args[0], &args[1], nargs - 1,
+ retval);
+}
+
+
extern const njs_object_init_t njs_function_constructor_init;
extern const njs_object_init_t njs_function_prototype_init;
extern const njs_object_init_t njs_function_instance_init;
typedef struct {
- union {
- njs_continuation_t cont;
- u_char padding[NJS_CONTINUATION_SIZE];
- } u;
- /*
- * This retval value must be aligned so the continuation is padded
- * to aligned size.
- */
njs_value_t retval;
nxt_array_t stack;
typedef struct {
- union {
- njs_continuation_t cont;
- u_char padding[NJS_CONTINUATION_SIZE];
- } u;
- /*
- * This retval value must be aligned so the continuation is padded
- * to aligned size.
- */
njs_value_t retval;
njs_value_t key;
static const u_char *njs_json_skip_space(const u_char *start,
const u_char *end);
-static njs_ret_t njs_json_parse_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t unused, njs_index_t unused2);
-static njs_ret_t njs_json_parse_continuation_apply(njs_vm_t *vm,
+static njs_ret_t njs_json_parse_iterator(njs_vm_t *vm, njs_json_parse_t *parse);
+static njs_ret_t njs_json_parse_iterator_call(njs_vm_t *vm,
njs_json_parse_t *parse);
static njs_json_state_t *njs_json_push_parse_state(njs_vm_t *vm,
njs_json_parse_t *parse, njs_value_t *value);
static void njs_json_parse_exception(njs_json_parse_ctx_t *ctx,
const char *msg, const u_char *pos);
-static njs_ret_t njs_json_stringify_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t unused, njs_index_t unused2);
+static njs_ret_t njs_json_stringify_iterator(njs_vm_t *vm,
+ njs_json_stringify_t *stringify);
static njs_function_t *njs_object_to_json_function(njs_vm_t *vm,
njs_value_t *value);
static njs_ret_t njs_json_stringify_to_json(njs_vm_t *vm,
njs_value_t *value, *wrapper;
const njs_value_t *text, *reviver;
const u_char *p, *end;
- njs_json_parse_t *parse;
+ njs_json_parse_t *parse, json_parse;
njs_string_prop_t string;
njs_json_parse_ctx_t ctx;
+ parse = &json_parse;
+
value = nxt_mp_alloc(vm->mem_pool, sizeof(njs_value_t));
if (nxt_slow_path(value == NULL)) {
njs_memory_error(vm);
goto memory_error;
}
- parse = njs_vm_continuation(vm);
- parse->u.cont.function = njs_json_parse_continuation;
parse->function = njs_function(reviver);
if (nxt_array_init(&parse->stack, NULL, 4, sizeof(njs_json_state_t),
goto memory_error;
}
- return njs_json_parse_continuation(vm, args, nargs, unused);
+ return njs_json_parse_iterator(vm, parse);
}
vm->retval = *value;
njs_ret_t ret;
njs_value_t *wrapper;
const njs_value_t *replacer, *space;
- njs_json_stringify_t *stringify;
+ njs_json_stringify_t *stringify, json_stringify;
+
+ stringify = &json_stringify;
- stringify = njs_vm_continuation(vm);
stringify->vm = vm;
stringify->pool = vm->mem_pool;
- stringify->u.cont.function = njs_json_stringify_continuation;
stringify->nodes = NULL;
stringify->last = NULL;
goto memory_error;
}
- return njs_json_stringify_continuation(vm, args, nargs, unused);
+ return njs_json_stringify_iterator(vm, stringify);
memory_error:
#define njs_json_is_non_empty(_value) \
(((_value)->type == NJS_OBJECT) \
- && !nxt_lvlhsh_is_empty(njs_object_hash(_value))) \
+ && !nxt_lvlhsh_is_empty(njs_object_hash(_value))) \
|| (((_value)->type == NJS_ARRAY) && njs_array_len(_value) != 0)
static njs_ret_t
-njs_json_parse_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t unused,
- njs_index_t unused2)
+njs_json_parse_iterator(njs_vm_t *vm, njs_json_parse_t *parse)
{
nxt_int_t ret;
njs_value_t *key, *value;
njs_json_state_t *state;
- njs_json_parse_t *parse;
njs_object_prop_t *prop;
nxt_lvlhsh_query_t lhq;
- parse = njs_vm_continuation(vm);
+start:
+
state = parse->state;
for ( ;; ) {
}
}
- return njs_json_parse_continuation_apply(vm, parse);
+ ret = njs_json_parse_iterator_call(vm, parse);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ goto start;
case NJS_JSON_OBJECT_REPLACED:
key = &state->keys->start[state->index];
(void) njs_json_pop_parse_state(parse);
}
- return njs_json_parse_continuation_apply(vm, parse);
+ ret = njs_json_parse_iterator_call(vm, parse);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ goto start;
case NJS_JSON_ARRAY_REPLACED:
value = &njs_array_start(&state->value)[state->index];
static njs_ret_t
-njs_json_parse_continuation_apply(njs_vm_t *vm, njs_json_parse_t *parse)
+njs_json_parse_iterator_call(njs_vm_t *vm, njs_json_parse_t *parse)
{
njs_value_t arguments[3];
njs_json_state_t *state;
njs_set_invalid(&parse->retval);
return njs_function_apply(vm, parse->function, arguments, 3,
- (njs_index_t) &parse->retval);
+ &parse->retval);
}
static njs_ret_t
-njs_json_stringify_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t unused, njs_index_t unused2)
+njs_json_stringify_iterator(njs_vm_t *vm, njs_json_stringify_t *stringify)
{
- u_char *start;
- size_t size;
- ssize_t length;
- nxt_int_t i;
- njs_ret_t ret;
- nxt_str_t str;
- njs_value_t *key, *value;
- njs_function_t *to_json;
- njs_json_state_t *state;
- njs_object_prop_t *prop;
- nxt_lvlhsh_query_t lhq;
- njs_json_stringify_t *stringify;
+ u_char *start;
+ size_t size;
+ ssize_t length;
+ nxt_int_t i;
+ njs_ret_t ret;
+ nxt_str_t str;
+ njs_value_t *key, *value;
+ njs_function_t *to_json;
+ njs_json_state_t *state;
+ njs_object_prop_t *prop;
+ nxt_lvlhsh_query_t lhq;
+
+start:
- stringify = njs_vm_continuation(vm);
state = stringify->state;
for ( ;; ) {
if (njs_is_object(&prop->value)) {
to_json = njs_object_to_json_function(vm, &prop->value);
if (to_json != NULL) {
- return njs_json_stringify_to_json(vm, stringify, to_json,
- &prop->name,
- &prop->value);
+ ret = njs_json_stringify_to_json(vm, stringify, to_json,
+ &prop->name,
+ &prop->value);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ goto start;
}
}
if (njs_is_function(&stringify->replacer)) {
- return njs_json_stringify_replacer(vm, stringify, &prop->name,
- &prop->value);
+ ret = njs_json_stringify_replacer(vm, stringify, &prop->name,
+ &prop->value);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ goto start;
}
njs_json_stringify_append_key(&prop->name);
}
if (njs_is_function(&stringify->replacer)) {
- return njs_json_stringify_replacer(vm, stringify,
- &stringify->key,
- &stringify->retval);
+ ret = njs_json_stringify_replacer(vm, stringify,
+ &stringify->key,
+ &stringify->retval);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ goto start;
}
/* Fall through. */
if (njs_is_object(value)) {
to_json = njs_object_to_json_function(vm, value);
if (to_json != NULL) {
- return njs_json_stringify_to_json(vm, stringify, to_json,
- NULL, value);
- }
+ ret = njs_json_stringify_to_json(vm, stringify, to_json,
+ NULL, value);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+ goto start;
+ }
}
if (njs_is_function(&stringify->replacer)) {
- return njs_json_stringify_replacer(vm, stringify, NULL, value);
+ ret = njs_json_stringify_replacer(vm, stringify, NULL, value);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ goto start;
}
if (njs_json_is_object(value)) {
if (!njs_is_undefined(&stringify->retval)
&& njs_is_function(&stringify->replacer))
{
- return njs_json_stringify_replacer(vm, stringify, NULL,
- &stringify->retval);
+ ret = njs_json_stringify_replacer(vm, stringify, NULL,
+ &stringify->retval);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ goto start;
}
/* Fall through. */
return NXT_ERROR;
}
- return njs_function_apply(vm, function, arguments, 2,
- (njs_index_t) &stringify->retval);
+ return njs_function_apply(vm, function, arguments, 2, &stringify->retval);
}
njs_set_invalid(&stringify->retval);
return njs_function_apply(vm, njs_function(&stringify->replacer),
- arguments, 3, (njs_index_t) &stringify->retval);
+ arguments, 3, &stringify->retval);
}
.type = NJS_METHOD,
.name = njs_string("parse"),
.value = njs_native_function(njs_json_parse,
- njs_continuation_size(njs_json_parse_t),
- NJS_SKIP_ARG, NJS_STRING_ARG,
- NJS_OBJECT_ARG),
+ NJS_SKIP_ARG, NJS_STRING_ARG,
+ NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
},
.type = NJS_METHOD,
.name = njs_string("stringify"),
.value = njs_native_function(njs_json_stringify,
- njs_continuation_size(njs_json_stringify_t),
- NJS_SKIP_ARG, NJS_SKIP_ARG, NJS_SKIP_ARG,
- NJS_SKIP_ARG),
+ NJS_SKIP_ARG, NJS_SKIP_ARG, NJS_SKIP_ARG,
+ NJS_SKIP_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("abs"),
- .value = njs_native_function(njs_object_math_abs, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_abs,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("acos"),
- .value = njs_native_function(njs_object_math_acos, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_acos,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("acosh"),
- .value = njs_native_function(njs_object_math_acosh, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_acosh,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("asin"),
- .value = njs_native_function(njs_object_math_asin, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_asin,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("asinh"),
- .value = njs_native_function(njs_object_math_asinh, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_asinh,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("atan"),
- .value = njs_native_function(njs_object_math_atan, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_atan,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("atan2"),
- .value = njs_native_function(njs_object_math_atan2, 0,
+ .value = njs_native_function(njs_object_math_atan2,
NJS_SKIP_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("atanh"),
- .value = njs_native_function(njs_object_math_atanh, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_atanh,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("cbrt"),
- .value = njs_native_function(njs_object_math_cbrt, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_cbrt,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("ceil"),
- .value = njs_native_function(njs_object_math_ceil, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_ceil,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("clz32"),
- .value = njs_native_function(njs_object_math_clz32, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_clz32,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("cos"),
- .value = njs_native_function(njs_object_math_cos, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_cos,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("cosh"),
- .value = njs_native_function(njs_object_math_cosh, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_cosh,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("exp"),
- .value = njs_native_function(njs_object_math_exp, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_exp,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("expm1"),
- .value = njs_native_function(njs_object_math_expm1, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_expm1,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("floor"),
- .value = njs_native_function(njs_object_math_floor, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_floor,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("fround"),
- .value = njs_native_function(njs_object_math_fround, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_fround,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("hypot"),
- .value = njs_native_function(njs_object_math_hypot, 0, 0),
+ .value = njs_native_function(njs_object_math_hypot, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("imul"),
- .value = njs_native_function(njs_object_math_imul, 0,
+ .value = njs_native_function(njs_object_math_imul,
NJS_SKIP_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("log"),
- .value = njs_native_function(njs_object_math_log, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_log,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("log10"),
- .value = njs_native_function(njs_object_math_log10, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_log10,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("log1p"),
- .value = njs_native_function(njs_object_math_log1p, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_log1p,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("log2"),
- .value = njs_native_function(njs_object_math_log2, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_log2,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("max"),
- .value = njs_native_function(njs_object_math_max, 0, 0),
+ .value = njs_native_function(njs_object_math_max, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("min"),
- .value = njs_native_function(njs_object_math_min, 0, 0),
+ .value = njs_native_function(njs_object_math_min, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("pow"),
- .value = njs_native_function(njs_object_math_pow, 0,
+ .value = njs_native_function(njs_object_math_pow,
NJS_SKIP_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("random"),
- .value = njs_native_function(njs_object_math_random, 0, 0),
+ .value = njs_native_function(njs_object_math_random, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("round"),
- .value = njs_native_function(njs_object_math_round, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_round,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("sign"),
- .value = njs_native_function(njs_object_math_sign, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_sign,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("sin"),
- .value = njs_native_function(njs_object_math_sin, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_sin,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("sinh"),
- .value = njs_native_function(njs_object_math_sinh, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_sinh,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("sqrt"),
- .value = njs_native_function(njs_object_math_sqrt, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_sqrt,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("tan"),
- .value = njs_native_function(njs_object_math_tan, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_tan,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("tanh"),
- .value = njs_native_function(njs_object_math_tanh, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_tanh,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("trunc"),
- .value = njs_native_function(njs_object_math_trunc, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_object_math_trunc,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("isFinite"),
- .value = njs_native_function(njs_number_is_finite, 0, 0),
+ .value = njs_native_function(njs_number_is_finite, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("isInteger"),
- .value = njs_native_function(njs_number_is_integer, 0, 0),
+ .value = njs_native_function(njs_number_is_integer, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("isSafeInteger"),
- .value = njs_native_function(njs_number_is_safe_integer, 0, 0),
+ .value = njs_native_function(njs_number_is_safe_integer, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("isNaN"),
- .value = njs_native_function(njs_number_is_nan, 0, 0),
+ .value = njs_native_function(njs_number_is_nan, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("parseFloat"),
- .value = njs_native_function(njs_number_parse_float, 0,
- NJS_SKIP_ARG, NJS_STRING_ARG),
+ .value = njs_native_function(njs_number_parse_float,
+ NJS_SKIP_ARG, NJS_STRING_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("parseInt"),
- .value = njs_native_function(njs_number_parse_int, 0,
+ .value = njs_native_function(njs_number_parse_int,
NJS_SKIP_ARG, NJS_STRING_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("valueOf"),
- .value = njs_native_function(njs_number_prototype_value_of, 0, 0),
+ .value = njs_native_function(njs_number_prototype_value_of, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_number_prototype_to_string, 0,
- NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ .value = njs_native_function(njs_number_prototype_to_string,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("create"),
- .value = njs_native_function(njs_object_create, 0, 0),
+ .value = njs_native_function(njs_object_create, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("keys"),
- .value = njs_native_function(njs_object_keys, 0,
+ .value = njs_native_function(njs_object_keys,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("values"),
- .value = njs_native_function(njs_object_values, 0,
+ .value = njs_native_function(njs_object_values,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("entries"),
- .value = njs_native_function(njs_object_entries, 0,
+ .value = njs_native_function(njs_object_entries,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("defineProperty"),
- .value = njs_native_function(njs_object_define_property, 0,
+ .value = njs_native_function(njs_object_define_property,
NJS_SKIP_ARG, NJS_OBJECT_ARG,
NJS_STRING_ARG, NJS_OBJECT_ARG),
.writable = 1,
{
.type = NJS_METHOD,
.name = njs_long_string("defineProperties"),
- .value = njs_native_function(njs_object_define_properties, 0,
+ .value = njs_native_function(njs_object_define_properties,
NJS_SKIP_ARG, NJS_OBJECT_ARG,
NJS_OBJECT_ARG),
.writable = 1,
{
.type = NJS_METHOD,
.name = njs_long_string("getOwnPropertyDescriptor"),
- .value = njs_native_function(njs_object_get_own_property_descriptor, 0,
+ .value = njs_native_function(njs_object_get_own_property_descriptor,
NJS_SKIP_ARG, NJS_SKIP_ARG,
NJS_STRING_ARG),
.writable = 1,
{
.type = NJS_METHOD,
.name = njs_long_string("getOwnPropertyDescriptors"),
- .value = njs_native_function(njs_object_get_own_property_descriptors, 0,
+ .value = njs_native_function(njs_object_get_own_property_descriptors,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_long_string("getOwnPropertyNames"),
- .value = njs_native_function(njs_object_get_own_property_names, 0,
+ .value = njs_native_function(njs_object_get_own_property_names,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("getPrototypeOf"),
- .value = njs_native_function(njs_object_get_prototype_of, 0,
+ .value = njs_native_function(njs_object_get_prototype_of,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("freeze"),
- .value = njs_native_function(njs_object_freeze, 0,
+ .value = njs_native_function(njs_object_freeze,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("isFrozen"),
- .value = njs_native_function(njs_object_is_frozen, 0,
+ .value = njs_native_function(njs_object_is_frozen,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("seal"),
- .value = njs_native_function(njs_object_seal, 0,
+ .value = njs_native_function(njs_object_seal,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("isSealed"),
- .value = njs_native_function(njs_object_is_sealed, 0,
+ .value = njs_native_function(njs_object_is_sealed,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_long_string("preventExtensions"),
- .value = njs_native_function(njs_object_prevent_extensions, 0,
+ .value = njs_native_function(njs_object_prevent_extensions,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("isExtensible"),
- .value = njs_native_function(njs_object_is_extensible, 0,
+ .value = njs_native_function(njs_object_is_extensible,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("valueOf"),
- .value = njs_native_function(njs_object_prototype_value_of, 0, 0),
+ .value = njs_native_function(njs_object_prototype_value_of, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_object_prototype_to_string, 0, 0),
+ .value = njs_native_function(njs_object_prototype_to_string, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("hasOwnProperty"),
- .value = njs_native_function(njs_object_prototype_has_own_property, 0,
+ .value = njs_native_function(njs_object_prototype_has_own_property,
NJS_OBJECT_ARG, NJS_STRING_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_long_string("propertyIsEnumerable"),
- .value = njs_native_function(njs_object_prototype_prop_is_enumerable, 0,
+ .value = njs_native_function(njs_object_prototype_prop_is_enumerable,
NJS_OBJECT_ARG, NJS_STRING_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("isPrototypeOf"),
- .value = njs_native_function(njs_object_prototype_is_prototype_of, 0,
+ .value = njs_native_function(njs_object_prototype_is_prototype_of,
NJS_OBJECT_ARG, NJS_OBJECT_ARG),
.writable = 1,
.configurable = 1,
njs_ret_t njs_property_query(njs_vm_t *vm, njs_property_query_t *pq,
njs_value_t *object, const njs_value_t *property);
njs_ret_t njs_value_property(njs_vm_t *vm, const njs_value_t *value,
- const njs_value_t *property, njs_value_t *retval, size_t advance);
+ const njs_value_t *property, njs_value_t *retval);
njs_ret_t njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
- const njs_value_t *property, njs_value_t *value, size_t advance);
+ const njs_value_t *property, njs_value_t *value);
njs_object_prop_t *njs_object_prop_alloc(njs_vm_t *vm, const njs_value_t *name,
const njs_value_t *value, uint8_t attributes);
njs_object_prop_t *njs_object_property(njs_vm_t *vm, const njs_object_t *obj,
* retval will contain the property's value
*
* NXT_DECLINED property was not found in object
- * NJS_APPLIED the property getter was applied
* NXT_ERROR exception has been thrown.
* retval will contain undefined
*/
njs_ret_t
njs_value_property(njs_vm_t *vm, const njs_value_t *value,
- const njs_value_t *property, njs_value_t *retval, size_t advance)
+ const njs_value_t *property, njs_value_t *retval)
{
njs_ret_t ret;
njs_object_prop_t *prop;
break;
}
- return njs_function_activate(vm, njs_function(&prop->getter),
- value, NULL, 0, (njs_index_t) retval,
- advance);
+ return njs_function_apply(vm, njs_function(&prop->getter),
+ (njs_value_t *) value, 1, retval);
case NJS_PROPERTY_HANDLER:
pq.scratch = *prop;
/*
* NXT_OK property has been set successfully
- * NJS_APPLIED the property setter was applied
* NXT_ERROR exception has been thrown.
*/
njs_ret_t
njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
- const njs_value_t *property, njs_value_t *value, size_t advance)
+ const njs_value_t *property, njs_value_t *value)
{
njs_ret_t ret;
njs_object_prop_t *prop, *shared;
}
if (njs_is_function(&prop->setter)) {
- return njs_function_activate(vm,
- njs_function(&prop->setter),
- object, value, 1,
- (njs_index_t) &vm->retval,
- advance);
+ return njs_function_call(vm, njs_function(&prop->setter),
+ object, value, 1, &vm->retval);
}
goto found;
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_regexp_prototype_to_string, 0, 0),
+ .value = njs_native_function(njs_regexp_prototype_to_string, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("test"),
- .value = njs_native_function(njs_regexp_prototype_test, 0,
- NJS_OBJECT_ARG, NJS_STRING_ARG),
+ .value = njs_native_function(njs_regexp_prototype_test,
+ NJS_OBJECT_ARG, NJS_STRING_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("exec"),
- .value = njs_native_function(njs_regexp_prototype_exec, 0,
- NJS_OBJECT_ARG, NJS_STRING_ARG),
+ .value = njs_native_function(njs_regexp_prototype_exec,
+ NJS_OBJECT_ARG, NJS_STRING_ARG),
.writable = 1,
.configurable = 1,
},
typedef struct {
- union {
- njs_continuation_t cont;
- u_char padding[NJS_CONTINUATION_SIZE];
- } u;
- /*
- * This retval value must be aligned so the continuation
- * is padded to aligned size.
- */
njs_value_t retval;
nxt_array_t parts;
njs_string_replace_t *r);
static njs_ret_t njs_string_replace_regexp_function(njs_vm_t *vm,
njs_value_t *args, njs_string_replace_t *r, int *captures, nxt_uint_t n);
-static njs_ret_t njs_string_replace_regexp_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
static njs_ret_t njs_string_replace_regexp_join(njs_vm_t *vm,
njs_string_replace_t *r);
static njs_ret_t njs_string_replace_search(njs_vm_t *vm, njs_value_t *args,
njs_string_replace_t *r);
static njs_ret_t njs_string_replace_search_function(njs_vm_t *vm,
njs_value_t *args, njs_string_replace_t *r);
-static njs_ret_t njs_string_replace_search_continuation(njs_vm_t *vm,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
static njs_ret_t njs_string_replace_parse(njs_vm_t *vm,
njs_string_replace_t *r, u_char *p, u_char *end, size_t size,
nxt_uint_t ncaptures);
{
.type = NJS_METHOD,
.name = njs_string("bytesFrom"),
- .value = njs_native_function(njs_string_bytes_from, 0, NJS_SKIP_ARG,
+ .value = njs_native_function(njs_string_bytes_from, NJS_SKIP_ARG,
NJS_SKIP_ARG, NJS_STRING_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("fromCharCode"),
- .value = njs_native_function(njs_string_from_char_code, 0, 0),
+ .value = njs_native_function(njs_string_from_char_code, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("fromCodePoint"),
- .value = njs_native_function(njs_string_from_char_code, 0, 0),
+ .value = njs_native_function(njs_string_from_char_code, 0),
.writable = 1,
.configurable = 1,
},
nxt_uint_t ncaptures;
nxt_regex_t *regex;
njs_string_prop_t string;
- njs_string_replace_t *r;
+ njs_string_replace_t *r, string_replace;
if (nargs == 1) {
goto original;
goto original;
}
- r = njs_vm_continuation(vm);
+ r = &string_replace;
r->utf8 = NJS_STRING_BYTE;
r->type = NJS_REGEXP_BYTE;
njs_value_t *arguments;
njs_string_prop_t string;
- r->u.cont.function = njs_string_replace_regexp_continuation;
njs_set_invalid(&r->retval);
arguments = nxt_mp_alloc(vm->mem_pool, (n + 3) * sizeof(njs_value_t));
r->part[0].size = captures[0];
- return njs_function_apply(vm, r->function, arguments, n + 3,
- (njs_index_t) &r->retval);
-}
-
-
-static njs_ret_t
-njs_string_replace_regexp_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- njs_string_prop_t string;
- njs_string_replace_t *r;
+ ret = njs_function_apply(vm, r->function, arguments, n + 3, &r->retval);
- r = njs_vm_continuation(vm);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
(void) njs_string_prop(&string, &args[0]);
nxt_regex_match_data_free(r->match_data, vm->regex_context);
- njs_internal_error(vm, "unexpected continuation retval type:%s",
+ njs_internal_error(vm, "unexpected retval type:%s",
njs_type_string(r->retval.type));
return NXT_ERROR;
njs_string_replace_search_function(njs_vm_t *vm, njs_value_t *args,
njs_string_replace_t *r)
{
+ njs_ret_t ret;
+ njs_value_t string;
njs_value_t arguments[4];
- r->u.cont.function = njs_string_replace_search_continuation;
-
arguments[0] = njs_value_undefined;
/* GC, args[0], args[1] */
/* The whole string being examined. */
arguments[3] = args[0];
- return njs_function_apply(vm, r->function, arguments, 4,
- (njs_index_t) &r->retval);
-}
-
+ ret = njs_function_apply(vm, r->function, arguments, 4, &r->retval);
-static njs_ret_t
-njs_string_replace_search_continuation(njs_vm_t *vm, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t unused)
-{
- njs_ret_t ret;
- njs_value_t string;
- njs_string_replace_t *r;
-
- r = njs_vm_continuation(vm);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
if (!njs_is_primitive(&r->retval)) {
ret = njs_value_to_string(vm, &r->retval, &r->retval);
{
.type = NJS_METHOD,
.name = njs_string("valueOf"),
- .value = njs_native_function(njs_string_prototype_value_of, 0, 0),
+ .value = njs_native_function(njs_string_prototype_value_of, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toString"),
- .value = njs_native_function(njs_string_prototype_to_string, 0, 0),
+ .value = njs_native_function(njs_string_prototype_to_string, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("concat"),
- .value = njs_native_function(njs_string_prototype_concat, 0, 0),
+ .value = njs_native_function(njs_string_prototype_concat, 0),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("fromUTF8"),
- .value = njs_native_function(njs_string_prototype_from_utf8, 0,
+ .value = njs_native_function(njs_string_prototype_from_utf8,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("toUTF8"),
- .value = njs_native_function(njs_string_prototype_to_utf8, 0,
+ .value = njs_native_function(njs_string_prototype_to_utf8,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("fromBytes"),
- .value = njs_native_function(njs_string_prototype_from_bytes, 0,
+ .value = njs_native_function(njs_string_prototype_from_bytes,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("toBytes"),
- .value = njs_native_function(njs_string_prototype_to_bytes, 0,
+ .value = njs_native_function(njs_string_prototype_to_bytes,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("slice"),
- .value = njs_native_function(njs_string_prototype_slice, 0,
+ .value = njs_native_function(njs_string_prototype_slice,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("substring"),
- .value = njs_native_function(njs_string_prototype_substring, 0,
+ .value = njs_native_function(njs_string_prototype_substring,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("substr"),
- .value = njs_native_function(njs_string_prototype_substr, 0,
+ .value = njs_native_function(njs_string_prototype_substr,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("charAt"),
- .value = njs_native_function(njs_string_prototype_char_at, 0,
+ .value = njs_native_function(njs_string_prototype_char_at,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("charCodeAt"),
- .value = njs_native_function(njs_string_prototype_char_code_at, 0,
+ .value = njs_native_function(njs_string_prototype_char_code_at,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("codePointAt"),
- .value = njs_native_function(njs_string_prototype_char_code_at, 0,
+ .value = njs_native_function(njs_string_prototype_char_code_at,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("indexOf"),
- .value = njs_native_function(njs_string_prototype_index_of, 0,
+ .value = njs_native_function(njs_string_prototype_index_of,
NJS_STRING_OBJECT_ARG, NJS_STRING_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("lastIndexOf"),
- .value = njs_native_function(njs_string_prototype_last_index_of, 0,
+ .value = njs_native_function(njs_string_prototype_last_index_of,
NJS_STRING_OBJECT_ARG, NJS_STRING_ARG, NJS_NUMBER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("includes"),
- .value = njs_native_function(njs_string_prototype_includes, 0,
+ .value = njs_native_function(njs_string_prototype_includes,
NJS_STRING_OBJECT_ARG, NJS_STRING_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("startsWith"),
- .value = njs_native_function(njs_string_prototype_starts_with, 0,
+ .value = njs_native_function(njs_string_prototype_starts_with,
NJS_STRING_OBJECT_ARG, NJS_STRING_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("endsWith"),
- .value = njs_native_function(njs_string_prototype_ends_with, 0,
+ .value = njs_native_function(njs_string_prototype_ends_with,
NJS_STRING_OBJECT_ARG, NJS_STRING_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("toLowerCase"),
- .value = njs_native_function(njs_string_prototype_to_lower_case, 0,
- NJS_STRING_OBJECT_ARG),
+ .value = njs_native_function(njs_string_prototype_to_lower_case,
+ NJS_STRING_OBJECT_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("toUpperCase"),
- .value = njs_native_function(njs_string_prototype_to_upper_case, 0,
- NJS_STRING_OBJECT_ARG),
+ .value = njs_native_function(njs_string_prototype_to_upper_case,
+ NJS_STRING_OBJECT_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("trim"),
- .value = njs_native_function(njs_string_prototype_trim, 0,
- NJS_STRING_OBJECT_ARG),
+ .value = njs_native_function(njs_string_prototype_trim,
+ NJS_STRING_OBJECT_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("repeat"),
- .value = njs_native_function(njs_string_prototype_repeat, 0,
- NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG),
+ .value = njs_native_function(njs_string_prototype_repeat,
+ NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("padStart"),
- .value = njs_native_function(njs_string_prototype_pad_start, 0,
+ .value = njs_native_function(njs_string_prototype_pad_start,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG, NJS_STRING_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("padEnd"),
- .value = njs_native_function(njs_string_prototype_pad_end, 0,
+ .value = njs_native_function(njs_string_prototype_pad_end,
NJS_STRING_OBJECT_ARG, NJS_INTEGER_ARG, NJS_STRING_ARG),
.writable = 1,
.configurable = 1,
{
.type = NJS_METHOD,
.name = njs_string("search"),
- .value = njs_native_function(njs_string_prototype_search, 0,
- NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG),
+ .value = njs_native_function(njs_string_prototype_search,
+ NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("match"),
- .value = njs_native_function(njs_string_prototype_match, 0,
- NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG),
+ .value = njs_native_function(njs_string_prototype_match,
+ NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_METHOD,
.name = njs_string("split"),
- .value = njs_native_function(njs_string_prototype_split, 0,
+ .value = njs_native_function(njs_string_prototype_split,
NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG, NJS_INTEGER_ARG),
.writable = 1,
.configurable = 1,
.type = NJS_METHOD,
.name = njs_string("replace"),
.value = njs_native_function(njs_string_prototype_replace,
- njs_continuation_size(njs_string_replace_t),
NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG, NJS_FUNCTION_ARG),
.writable = 1,
.configurable = 1,
{
njs_ret_t ret;
nxt_uint_t tries;
+ njs_value_t retval;
njs_object_prop_t *prop;
nxt_lvlhsh_query_t lhq;
- njs_value_t retval nxt_aligned(16);
-
static const uint32_t hashes[] = {
NJS_VALUE_OF_HASH,
NJS_TO_STRING_HASH,
continue;
}
- ret = njs_function_call(vm, njs_function(&prop->value), value, 1,
- (njs_index_t) &retval);
+ ret = njs_function_apply(vm, njs_function(&prop->value), value, 1,
+ &retval);
if (nxt_fast_path(ret == NXT_OK)) {
if (njs_is_primitive(&retval)) {
}
-#define njs_native_function(_function, _size, ...) { \
+#define njs_native_function(_function, ...) { \
.data = { \
.type = NJS_FUNCTION, \
.truth = 1, \
.u.function = & (njs_function_t) { \
.native = 1, \
- .continuation_size = _size, \
.args_types = { __VA_ARGS__ }, \
.args_offset = 1, \
.u.native = _function, \
static njs_ret_t njs_function_frame_create(njs_vm_t *vm, njs_value_t *value,
const njs_value_t *this, uintptr_t nargs, nxt_bool_t ctor);
static njs_object_t *njs_function_new_object(njs_vm_t *vm, njs_value_t *value);
-static void njs_vm_scopes_restore(njs_vm_t *vm, njs_frame_t *frame,
- njs_native_frame_t *previous);
-static njs_ret_t njs_vmcode_continuation(njs_vm_t *vm, njs_value_t *invld1,
- njs_value_t *invld2);
static njs_ret_t njs_vm_add_backtrace_entry(njs_vm_t *vm, njs_frame_t *frame);
{
njs_ret_t ret;
+ vm->top_frame->call = 1;
+
if (nxt_slow_path(vm->count > 128)) {
njs_range_error(vm, "Maximum call stack size exceeded");
return NXT_ERROR;
if (!njs_is_primitive(value)) {
array = njs_array(value);
- ret = njs_function_activate(vm, (njs_function_t *) &concat,
- &njs_string_empty, array->start,
- array->length, (njs_index_t) retval, 0);
- if (ret == NJS_APPLIED) {
- return 0;
+ ret = njs_function_frame(vm, (njs_function_t *) &concat,
+ (njs_value_t *) &njs_string_empty,
+ array->start, array->length, 0);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
}
- return NXT_ERROR;
+ ret = njs_function_frame_invoke(vm, (njs_index_t) retval);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
}
return sizeof(njs_vmcode_template_literal_t);
code = (njs_vmcode_prop_get_t *) vm->current;
retval = njs_vmcode_operand(vm, code->value);
- ret = njs_value_property(vm, object, property, retval,
- sizeof(njs_vmcode_prop_get_t));
- if (ret == NXT_OK || ret == NXT_DECLINED) {
- vm->retval = *retval;
- return sizeof(njs_vmcode_prop_get_t);
+ ret = njs_value_property(vm, object, property, retval);
+ if (nxt_slow_path(ret == NXT_ERROR)) {
+ return ret;
}
- return (ret == NJS_APPLIED) ? 0 : ret;
+ vm->retval = *retval;
+
+ return sizeof(njs_vmcode_prop_get_t);
}
code = (njs_vmcode_prop_set_t *) vm->current;
value = njs_vmcode_operand(vm, code->value);
- ret = njs_value_property_set(vm, object, property, value,
- sizeof(njs_vmcode_prop_set_t));
- if (ret == NXT_OK) {
- return sizeof(njs_vmcode_prop_set_t);
+ ret = njs_value_property_set(vm, object, property, value);
+ if (nxt_slow_path(ret == NXT_ERROR)) {
+ return ret;
}
- return (ret == NJS_APPLIED) ? 0 : ret;
+ return sizeof(njs_vmcode_prop_set_t);
}
if (njs_is_object(object)) {
value = njs_value_undefined;
- ret = njs_value_property(vm, constructor, &prototype_string, &value, 0);
+ ret = njs_value_property(vm, constructor, &prototype_string, &value);
- if (nxt_slow_path(ret == NJS_APPLIED)) {
- njs_internal_error(vm, "getter is not supported in instanceof");
- return NXT_ERROR;
+ if (nxt_slow_path(ret == NXT_ERROR)) {
+ return ret;
}
if (nxt_fast_path(ret == NXT_OK)) {
}
}
- return njs_function_frame(vm, function, this, NULL, nargs, 0, ctor);
+ return njs_function_frame(vm, function, this, NULL, nargs, ctor);
}
njs_type_error(vm, "%s is not a function", njs_type_string(value->type));
njs_ret_t
njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
{
- u_char *return_address;
- njs_ret_t ret;
- njs_function_t *function;
- njs_continuation_t *cont;
- njs_native_frame_t *frame;
-
- frame = vm->top_frame;
- function = frame->function;
-
- return_address = vm->current + sizeof(njs_vmcode_function_call_t);
-
- if (function->native) {
- if (function->continuation_size != 0) {
- cont = njs_vm_continuation(vm);
-
- cont->function = function->u.native;
- cont->args_types = function->args_types;
- cont->retval = (njs_index_t) retval;
- cont->return_address = return_address;
-
- vm->current = (u_char *) njs_continuation_nexus;
-
- ret = NJS_APPLIED;
-
- } else {
- ret = njs_function_native_call(vm, function->u.native,
- frame->arguments,
- function->args_types, frame->nargs,
- (njs_index_t) retval,
- return_address);
- }
+ njs_ret_t ret;
- } else {
- ret = njs_function_lambda_call(vm, (njs_index_t) retval,
- return_address);
+ ret = njs_function_frame_invoke(vm, (njs_index_t) retval);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
}
- return (ret == NJS_APPLIED) ? 0 : ret;
+ return sizeof(njs_vmcode_function_call_t);
}
njs_ret_t
njs_vmcode_return(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
{
- nxt_int_t ret;
njs_value_t *value;
njs_frame_t *frame;
njs_native_frame_t *previous;
}
}
+ vm->current = frame->return_address;
+
previous = njs_function_previous_frame(&frame->native);
njs_vm_scopes_restore(vm, frame, previous);
/* GC: value external/internal++ depending on value and retval type */
*retval = *value;
- vm->current = frame->return_address;
-
- ret = frame->native.call ? NJS_STOP : 0;
-
njs_function_frame_free(vm, &frame->native);
- return ret;
+ return NJS_STOP;
}
-static void
+void
njs_vm_scopes_restore(njs_vm_t *vm, njs_frame_t *frame,
njs_native_frame_t *previous)
{
}
-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 },
-};
-
-
-static njs_ret_t
-njs_vmcode_continuation(njs_vm_t *vm, njs_value_t *invld1, njs_value_t *invld2)
-{
- njs_ret_t ret;
- njs_native_frame_t *frame;
- njs_continuation_t *cont;
-
- frame = vm->top_frame;
- cont = njs_vm_continuation(vm);
-
- ret = njs_function_native_call(vm, cont->function, frame->arguments,
- cont->args_types, frame->nargs,
- cont->retval, cont->return_address);
-
- return (ret == NJS_APPLIED) ? 0 : ret;
-}
-
-
njs_ret_t
njs_vmcode_stop(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
{
#define NJS_PREEMPT (-11)
-/*
- * A user-defined function is prepared to run. This code is never
- * returned to interpreter, so the value can be shared with NJS_STOP.
- */
-#define NJS_APPLIED NXT_DONE
-
-
/*
* NJS_PROPERTY_QUERY_GET must be less to NJS_PROPERTY_QUERY_SET
* and NJS_PROPERTY_QUERY_DELETE.
nxt_int_t njs_vmcode_interpreter(njs_vm_t *vm);
nxt_int_t njs_vmcode_run(njs_vm_t *vm);
+void njs_vm_scopes_restore(njs_vm_t *vm, njs_frame_t *frame,
+ njs_native_frame_t *previous);
njs_ret_t njs_vmcode_object(njs_vm_t *vm, njs_value_t *inlvd1,
njs_value_t *inlvd2);
extern const nxt_mem_proto_t njs_array_mem_proto;
extern const nxt_lvlhsh_proto_t njs_object_hash_proto;
-extern const njs_vmcode_generic_t njs_continuation_nexus[];
-
#endif /* _NJS_VM_H_INCLUDED_ */
{ nxt_string("Object.defineProperty(Function.prototype, \"prototype\", {get: ()=>Array.prototype});"
"[] instanceof Function.prototype"),
- nxt_string("InternalError: getter is not supported in instanceof") },
+ nxt_string("true") },
+
+ { nxt_string("Object.defineProperty(Function.prototype, \"prototype\", {get: ()=>{throw Error('Oops')}});"
+ "[] instanceof Function.prototype"),
+ nxt_string("Error: Oops") },
/* global this. */
{ nxt_string("var s = new String('αβ'); s[4] = 'ab'; s[4]"),
nxt_string("ab") },
-
-#if 0
{ nxt_string("Object.create(new String('αβ')).length"),
nxt_string("2") },
-#endif
{ nxt_string("var s = new String('αβ'); s.valueOf()[1]"),
nxt_string("β") },