]> git.kaiwu.me - njs.git/commitdiff
Refactored working with function calls.
authorhongzhidao <hongzhidao@gmail.com>
Wed, 17 Jul 2019 02:44:16 +0000 (22:44 -0400)
committerhongzhidao <hongzhidao@gmail.com>
Wed, 17 Jul 2019 02:44:16 +0000 (22:44 -0400)
    1) njs_continuation_t is removed (appropriate functions
       are rewritten).
    2) all function calls are made syncronous.

    This closes #190 issue on Github.

23 files changed:
njs/njs.c
njs/njs_array.c
njs/njs_boolean.c
njs/njs_builtin.c
njs/njs_crypto.c
njs/njs_date.c
njs/njs_error.c
njs/njs_fs.c
njs/njs_function.c
njs/njs_function.h
njs/njs_json.c
njs/njs_math.c
njs/njs_number.c
njs/njs_object.c
njs/njs_object.h
njs/njs_object_property.c
njs/njs_regexp.c
njs/njs_string.c
njs/njs_value.c
njs/njs_value.h
njs/njs_vm.c
njs/njs_vm.h
njs/test/njs_unit_test.c

index 0cd35733cfbb3e368c248bb962edd54278eff3da..25fecca0dcc8d2279783f935469474dfff4ac404 100644 (file)
--- a/njs/njs.c
+++ b/njs/njs.c
@@ -456,7 +456,7 @@ nxt_int_t
 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);
 }
 
 
@@ -464,30 +464,18 @@ nxt_int_t
 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);
 }
 
 
index 70da49541fedbb627cf6fafc5b5f6f79fd69b02f..7b43153fcf5e85f4627c1995e5d079e9254261bf 100644 (file)
@@ -9,133 +9,9 @@
 #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 *
@@ -407,7 +283,7 @@ static const njs_object_prop_t  njs_array_constructor_properties[] =
     {
         .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,
     },
@@ -417,7 +293,7 @@ static const njs_object_prop_t  njs_array_constructor_properties[] =
     {
         .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,
     },
@@ -517,44 +393,26 @@ static njs_ret_t
 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;
@@ -675,7 +533,7 @@ njs_array_prototype_slice_copy(njs_vm_t *vm, njs_value_t *this,
                 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;
@@ -970,8 +828,8 @@ njs_array_prototype_to_string(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         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);
         }
     }
 
@@ -983,26 +841,24 @@ static njs_ret_t
 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];
@@ -1023,11 +879,6 @@ njs_array_prototype_join(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
             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++) {
@@ -1046,34 +897,6 @@ njs_array_prototype_join(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         }
     }
 
-    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;
@@ -1422,11 +1245,14 @@ static njs_ret_t
 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);
 
@@ -1437,38 +1263,6 @@ njs_array_prototype_fill(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
             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;
@@ -1479,22 +1273,26 @@ njs_array_prototype_fill_continuation(njs_vm_t *vm, njs_value_t *args,
         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));
@@ -1521,125 +1319,121 @@ njs_array_prototype_fill_continuation(njs_vm_t *vm, njs_value_t *args,
         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;
@@ -1652,44 +1446,41 @@ static njs_ret_t
 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;
@@ -1702,57 +1493,52 @@ static njs_ret_t
 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;
 }
 
 
@@ -1760,50 +1546,42 @@ static njs_ret_t
 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;
@@ -1816,41 +1594,43 @@ static njs_ret_t
 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);
@@ -1859,245 +1639,135 @@ njs_array_prototype_find_index_continuation(njs_vm_t *vm, njs_value_t *args,
 }
 
 
-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;
 }
 
 
@@ -2105,93 +1775,55 @@ static njs_ret_t
 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;
 }
 
 
@@ -2222,7 +1854,6 @@ njs_array_string_sort(njs_vm_t *vm, njs_value_t *args,
 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,
@@ -2233,46 +1864,33 @@ static njs_ret_t
 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.
@@ -2281,11 +1899,11 @@ njs_array_prototype_sort_continuation(njs_vm_t *vm, njs_value_t *args,
          * "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:
 
@@ -2306,11 +1924,16 @@ njs_array_prototype_sort_continuation(njs_vm_t *vm, njs_value_t *args,
                         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. */
@@ -2320,8 +1943,8 @@ njs_array_prototype_sort_continuation(njs_vm_t *vm, njs_value_t *args,
 
         next:
 
-            sort->current++;
-            n = sort->current;
+            current++;
+            n = current;
 
         } while (n < array->length);
     }
@@ -2353,7 +1976,6 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
         .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,
@@ -2362,7 +1984,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2370,7 +1992,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2378,7 +2000,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2386,7 +2008,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2394,7 +2016,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
@@ -2403,8 +2025,8 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2412,8 +2034,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2422,7 +2043,6 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
         .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,
@@ -2431,7 +2051,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2439,7 +2059,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
@@ -2448,7 +2068,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
@@ -2458,7 +2078,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
@@ -2467,8 +2087,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2476,8 +2095,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2485,8 +2103,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2496,7 +2113,6 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
         .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,
@@ -2506,8 +2122,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2516,8 +2131,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2526,8 +2140,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2535,8 +2148,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2544,8 +2156,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2553,8 +2164,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
@@ -2562,8 +2172,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
     {
         .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,
     },
index 4c194a5895c1ac8b97c61b8064ad20cfa9e91295..441829d7ee6d8367eb00bc3894a7caa28b5316a1 100644 (file)
@@ -144,7 +144,7 @@ static const njs_object_prop_t  njs_boolean_prototype_properties[] =
     {
         .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,
     },
@@ -152,7 +152,7 @@ static const njs_object_prop_t  njs_boolean_prototype_properties[] =
     {
         .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,
     },
index 833ba43442cd89410d0fbc35e062c1ad31ca49a8..acdd7a0bd2db9a7ae3f2391ca234e6026da9b418 100644 (file)
@@ -1127,7 +1127,7 @@ static const njs_object_prop_t  njs_njs_object_properties[] =
     {
         .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,
     },
index d4ca5f6746a33a5824609724364ea709820a5d5f..cb58b73bf4474c677f542aad7d6af9899319d56a 100644 (file)
@@ -328,7 +328,7 @@ static const njs_object_prop_t  njs_hash_prototype_properties[] =
     {
         .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,
     },
@@ -336,7 +336,7 @@ static const njs_object_prop_t  njs_hash_prototype_properties[] =
     {
         .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,
@@ -345,7 +345,7 @@ static const njs_object_prop_t  njs_hash_prototype_properties[] =
     {
         .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,
@@ -590,7 +590,7 @@ static const njs_object_prop_t  njs_hmac_prototype_properties[] =
     {
         .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,
     },
@@ -598,7 +598,7 @@ static const njs_object_prop_t  njs_hmac_prototype_properties[] =
     {
         .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,
@@ -607,7 +607,7 @@ static const njs_object_prop_t  njs_hmac_prototype_properties[] =
     {
         .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,
@@ -655,7 +655,7 @@ static const njs_object_prop_t  njs_crypto_object_properties[] =
     {
         .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,
@@ -664,7 +664,7 @@ static const njs_object_prop_t  njs_crypto_object_properties[] =
     {
         .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,
index d85660a051f187ea18c23e223183fa89ff1fe6c9..ea6cd1247dae4c744bfbae105412318e5635639e 100644 (file)
@@ -917,7 +917,7 @@ static const njs_object_prop_t  njs_date_constructor_properties[] =
     {
         .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,
     },
@@ -925,7 +925,7 @@ static const njs_object_prop_t  njs_date_constructor_properties[] =
     {
         .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,
     },
@@ -933,8 +933,8 @@ static const njs_object_prop_t  njs_date_constructor_properties[] =
     {
         .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,
     },
@@ -1909,8 +1909,8 @@ njs_date_prototype_to_json(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         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);
         }
     }
 
@@ -1941,8 +1941,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -1950,8 +1949,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -1959,8 +1958,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -1968,8 +1967,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -1977,8 +1976,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -1986,8 +1985,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -1995,8 +1994,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2004,8 +2003,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2013,8 +2012,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2022,8 +2021,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2031,8 +2029,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2040,8 +2038,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2049,8 +2047,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2058,8 +2056,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2067,8 +2065,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2076,8 +2074,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2085,8 +2083,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2094,8 +2091,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2103,8 +2100,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2112,8 +2109,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2121,8 +2118,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2130,8 +2127,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2139,8 +2136,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2148,8 +2145,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2157,8 +2154,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2166,8 +2163,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2175,8 +2172,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2184,8 +2181,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2193,8 +2190,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2202,8 +2199,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2211,8 +2208,8 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
@@ -2220,7 +2217,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2229,7 +2226,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2239,7 +2236,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2249,7 +2246,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2259,7 +2256,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2269,7 +2266,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2278,7 +2275,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2287,7 +2284,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2296,7 +2293,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2305,7 +2302,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2315,7 +2312,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
@@ -2325,8 +2322,7 @@ static const njs_object_prop_t  njs_date_prototype_properties[] =
     {
         .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,
     },
index 9af97026d3cf7eb14b132497f65034e0f0cce0de..245105cca8afe23e7da68ad448f3f74fb6701263 100644 (file)
@@ -711,7 +711,7 @@ static const njs_object_prop_t  njs_error_prototype_properties[] =
     {
         .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,
     },
@@ -719,7 +719,7 @@ static const njs_object_prop_t  njs_error_prototype_properties[] =
     {
         .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,
     },
@@ -793,8 +793,7 @@ static const njs_object_prop_t  njs_internal_error_prototype_properties[] =
     {
         .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,
     },
index cf88551c91943fdb0a14de02e444985cb45eb217..be570e21898246b1724a05f8b672a41520744cf7 100644 (file)
 #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;
@@ -44,8 +34,6 @@ static njs_ret_t njs_fs_write_file_internal(njs_vm_t *vm, njs_value_t *args,
     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);
@@ -93,7 +81,6 @@ njs_fs_read_file(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     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;
 
@@ -286,11 +273,16 @@ done:
 
     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:
 
@@ -538,7 +530,6 @@ static njs_ret_t njs_fs_write_file_internal(njs_vm_t *vm, njs_value_t *args,
     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;
 
@@ -706,11 +697,16 @@ done:
 
     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;
 }
 
 
@@ -880,15 +876,6 @@ done:
 }
 
 
-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)
 {
@@ -1036,8 +1023,7 @@ static const njs_object_prop_t  njs_fs_object_properties[] =
     {
         .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,
     },
@@ -1045,7 +1031,7 @@ static const njs_object_prop_t  njs_fs_object_properties[] =
     {
         .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,
     },
@@ -1053,8 +1039,7 @@ static const njs_object_prop_t  njs_fs_object_properties[] =
     {
         .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,
     },
@@ -1062,8 +1047,7 @@ static const njs_object_prop_t  njs_fs_object_properties[] =
     {
         .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,
     },
@@ -1071,8 +1055,7 @@ static const njs_object_prop_t  njs_fs_object_properties[] =
     {
         .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,
     },
@@ -1080,8 +1063,7 @@ static const njs_object_prop_t  njs_fs_object_properties[] =
     {
         .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,
     },
index 75045978e64fead524b7739c0712519db30e1a5d..67cb7aaea44b0d54face72b060db87eb90af142b 100644 (file)
@@ -288,17 +288,14 @@ const njs_object_init_t  njs_arguments_object_instance_init = {
 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);
@@ -310,13 +307,7 @@ njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
     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;
@@ -473,41 +464,21 @@ njs_function_frame_alloc(njs_vm_t *vm, size_t size)
 
 
 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;
@@ -515,8 +486,7 @@ njs_function_call(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
 
 
 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;
@@ -528,12 +498,10 @@ njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval,
     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;
 
@@ -605,72 +573,56 @@ njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval,
 
     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;
 }
 
 
@@ -811,27 +763,22 @@ type_error:
 
 
 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);
 }
 
 
@@ -1020,16 +967,20 @@ njs_function_prototype_call(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
     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;
 }
 
 
@@ -1084,7 +1035,7 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         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;
     }
@@ -1106,7 +1057,7 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     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;
         }
@@ -1114,53 +1065,20 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
 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;
 }
 
 
@@ -1240,7 +1158,7 @@ static const njs_object_prop_t  njs_function_prototype_properties[] =
     {
         .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,
     },
@@ -1248,7 +1166,7 @@ static const njs_object_prop_t  njs_function_prototype_properties[] =
     {
         .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,
     },
@@ -1256,7 +1174,7 @@ static const njs_object_prop_t  njs_function_prototype_properties[] =
     {
         .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,
     },
index 0b1c939a21f68fa74783a7c7451ce99dae671215..f5cd40307a5030f967f3b2806d71f9d49e9ff7fb 100644 (file)
@@ -57,23 +57,6 @@ struct njs_function_lambda_s {
 #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 {
@@ -92,8 +75,6 @@ struct njs_native_frame_s {
     njs_function_t                 *function;
     njs_native_frame_t             *previous;
 
-    njs_continuation_t             *continuation;
-
     njs_value_t                    *arguments;
     njs_object_t                   *arguments_object;
 
@@ -145,20 +126,15 @@ njs_ret_t njs_function_constructor(njs_vm_t *vm, njs_value_t *args,
     nxt_uint_t nargs, njs_index_t unused);
 njs_ret_t njs_function_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);
 
 
@@ -180,11 +156,10 @@ njs_function_lambda_alloc(njs_vm_t *vm, uint8_t ctor)
 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);
@@ -192,15 +167,6 @@ njs_function_frame(njs_vm_t *vm, njs_function_t *function,
 }
 
 
-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)
 {
@@ -216,6 +182,33 @@ 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;
index e9ddbf47bf18ac42045e7d48793352e917394245..e08536a6881bdb3be78478a9c8eca423cbca8f43 100644 (file)
@@ -43,14 +43,6 @@ typedef struct {
 
 
 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;
@@ -70,14 +62,6 @@ struct njs_chb_node_s {
 
 
 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;
 
@@ -107,9 +91,8 @@ nxt_inline uint32_t njs_json_unicode(const u_char *p);
 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);
@@ -117,8 +100,8 @@ static njs_json_state_t *njs_json_pop_parse_state(njs_json_parse_t *parse);
 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,
@@ -169,10 +152,12 @@ njs_json_parse(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     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);
@@ -221,8 +206,6 @@ njs_json_parse(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
             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),
@@ -236,7 +219,7 @@ njs_json_parse(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
             goto memory_error;
         }
 
-        return njs_json_parse_continuation(vm, args, nargs, unused);
+        return njs_json_parse_iterator(vm, parse);
     }
 
     vm->retval = *value;
@@ -271,12 +254,12 @@ njs_json_stringify(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     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;
 
@@ -339,7 +322,7 @@ njs_json_stringify(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         goto memory_error;
     }
 
-    return njs_json_stringify_continuation(vm, args, nargs, unused);
+    return njs_json_stringify_iterator(vm, stringify);
 
 memory_error:
 
@@ -932,22 +915,21 @@ njs_json_skip_space(const u_char *start, const u_char *end)
 
 #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 ( ;; ) {
@@ -992,7 +974,12 @@ njs_json_parse_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t unused,
                 }
             }
 
-            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];
@@ -1042,7 +1029,12 @@ njs_json_parse_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t unused,
                 (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];
@@ -1069,7 +1061,7 @@ memory_error:
 
 
 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;
@@ -1102,7 +1094,7 @@ njs_json_parse_continuation_apply(njs_vm_t *vm, njs_json_parse_t *parse)
     njs_set_invalid(&parse->retval);
 
     return njs_function_apply(vm, parse->function, arguments, 3,
-                              (njs_index_t) &parse->retval);
+                              &parse->retval);
 }
 
 
@@ -1215,23 +1207,22 @@ njs_json_parse_exception(njs_json_parse_ctx_t *ctx, const char *msg,
 
 
 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 ( ;; ) {
@@ -1279,15 +1270,25 @@ njs_json_stringify_continuation(njs_vm_t *vm, njs_value_t *args,
             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);
@@ -1313,9 +1314,14 @@ njs_json_stringify_continuation(njs_vm_t *vm, njs_value_t *args,
             }
 
             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. */
@@ -1373,14 +1379,23 @@ njs_json_stringify_continuation(njs_vm_t *vm, njs_value_t *args,
             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)) {
@@ -1400,8 +1415,13 @@ njs_json_stringify_continuation(njs_vm_t *vm, njs_value_t *args,
             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. */
@@ -1538,8 +1558,7 @@ njs_json_stringify_to_json(njs_vm_t *vm, njs_json_stringify_t* stringify,
         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);
 }
 
 
@@ -1583,7 +1602,7 @@ njs_json_stringify_replacer(njs_vm_t *vm, njs_json_stringify_t* stringify,
     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);
 }
 
 
@@ -2071,9 +2090,8 @@ static const njs_object_prop_t  njs_json_object_properties[] =
         .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,
     },
@@ -2083,9 +2101,8 @@ static const njs_object_prop_t  njs_json_object_properties[] =
         .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,
     },
index 5220067874d1ae91a98e1c7a4356324302f5ddf1..18fabad90e5a9e95858cb0ee6f2cae296dd93eb4 100644 (file)
@@ -833,8 +833,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -842,8 +842,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -852,8 +852,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -861,8 +861,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -871,8 +871,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -880,8 +880,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -889,7 +889,7 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
@@ -899,8 +899,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -909,8 +909,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -918,8 +918,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -928,8 +928,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -937,8 +937,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -947,8 +947,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -956,8 +956,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -966,8 +966,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -975,8 +975,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -985,8 +985,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -995,7 +995,7 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1004,7 +1004,7 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
@@ -1013,8 +1013,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1023,8 +1023,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1033,8 +1033,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1043,8 +1043,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1052,7 +1052,7 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1060,7 +1060,7 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1068,7 +1068,7 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
@@ -1077,7 +1077,7 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1085,8 +1085,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1095,8 +1095,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1104,8 +1104,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1114,8 +1114,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1123,8 +1123,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1132,8 +1132,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1142,8 +1142,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
@@ -1152,8 +1152,8 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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,
     },
index 2d298519bc386e7db6a4c4e64448691f26f284ec..d2b898787c7cd5eaac570059f66eb0ae25f65f24 100644 (file)
@@ -416,7 +416,7 @@ static const njs_object_prop_t  njs_number_constructor_properties[] =
     {
         .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,
     },
@@ -425,7 +425,7 @@ static const njs_object_prop_t  njs_number_constructor_properties[] =
     {
         .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,
     },
@@ -434,7 +434,7 @@ static const njs_object_prop_t  njs_number_constructor_properties[] =
     {
         .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,
     },
@@ -443,7 +443,7 @@ static const njs_object_prop_t  njs_number_constructor_properties[] =
     {
         .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,
     },
@@ -452,8 +452,8 @@ static const njs_object_prop_t  njs_number_constructor_properties[] =
     {
         .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,
     },
@@ -462,7 +462,7 @@ static const njs_object_prop_t  njs_number_constructor_properties[] =
     {
         .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,
@@ -630,7 +630,7 @@ static const njs_object_prop_t  njs_number_prototype_properties[] =
     {
         .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,
     },
@@ -638,8 +638,8 @@ static const njs_object_prop_t  njs_number_prototype_properties[] =
     {
         .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,
     },
index 719f5186eba5804fca853601a1900850999506ce..166ef0d90a9f9bc10471dce17ffb3e53907b1a81 100644 (file)
@@ -1675,7 +1675,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
     },
@@ -1684,7 +1684,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1694,7 +1694,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1704,7 +1704,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1714,7 +1714,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1725,7 +1725,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1736,7 +1736,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1747,7 +1747,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1757,7 +1757,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1767,7 +1767,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1777,7 +1777,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1787,7 +1787,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1797,7 +1797,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1807,7 +1807,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1817,7 +1817,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -1827,7 +1827,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
     {
         .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,
@@ -2244,7 +2244,7 @@ static const njs_object_prop_t  njs_object_prototype_properties[] =
     {
         .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,
     },
@@ -2252,7 +2252,7 @@ static const njs_object_prop_t  njs_object_prototype_properties[] =
     {
         .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,
     },
@@ -2260,7 +2260,7 @@ static const njs_object_prop_t  njs_object_prototype_properties[] =
     {
         .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,
@@ -2269,7 +2269,7 @@ static const njs_object_prop_t  njs_object_prototype_properties[] =
     {
         .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,
@@ -2278,7 +2278,7 @@ static const njs_object_prop_t  njs_object_prototype_properties[] =
     {
         .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,
index 701f8a06237254ea0d0305bbfd05c4d69abac9d2..74c3d3abdebf0e2c8b7da1026e1c675d438e21d2 100644 (file)
@@ -127,9 +127,9 @@ njs_ret_t njs_object_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
 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,
index 55223b87a85980e281f1eec80426c91e862cd7c0..a308699d56e0ed4655bb6df5bee54dfd6606543e 100644 (file)
@@ -478,13 +478,12 @@ njs_external_property_delete(njs_vm_t *vm, njs_value_t *value,
  *      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;
@@ -525,9 +524,8 @@ njs_value_property(njs_vm_t *vm, const njs_value_t *value,
                 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;
@@ -569,12 +567,11 @@ njs_value_property(njs_vm_t *vm, const njs_value_t *value,
 
 /*
  *   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;
@@ -630,11 +627,8 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
                 }
 
                 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;
index 57c3dff8435e94e3c66a4ced36ce7037f9a4e85d..7fdd5b9b442326ad459bec7b7704ed480e3d5867 100644 (file)
@@ -1207,7 +1207,7 @@ static const njs_object_prop_t  njs_regexp_prototype_properties[] =
     {
         .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,
     },
@@ -1215,8 +1215,8 @@ static const njs_object_prop_t  njs_regexp_prototype_properties[] =
     {
         .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,
     },
@@ -1224,8 +1224,8 @@ static const njs_object_prop_t  njs_regexp_prototype_properties[] =
     {
         .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,
     },
index f9a2500eb5f8874e553aa78e669669f7f52828b5..31ca7b221aeacf68463ac665e68ee81fb654fe68 100644 (file)
@@ -30,14 +30,6 @@ typedef struct {
 
 
 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;
@@ -84,16 +76,12 @@ static njs_ret_t njs_string_replace_regexp(njs_vm_t *vm, njs_value_t *args,
     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);
@@ -601,7 +589,7 @@ static const njs_object_prop_t  njs_string_constructor_properties[] =
     {
         .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,
@@ -611,7 +599,7 @@ static const njs_object_prop_t  njs_string_constructor_properties[] =
     {
         .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,
     },
@@ -620,7 +608,7 @@ static const njs_object_prop_t  njs_string_constructor_properties[] =
     {
         .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,
     },
@@ -2989,7 +2977,7 @@ njs_string_prototype_replace(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     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;
@@ -3001,7 +2989,7 @@ njs_string_prototype_replace(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         goto original;
     }
 
-    r = njs_vm_continuation(vm);
+    r = &string_replace;
 
     r->utf8 = NJS_STRING_BYTE;
     r->type = NJS_REGEXP_BYTE;
@@ -3234,7 +3222,6 @@ njs_string_replace_regexp_function(njs_vm_t *vm, njs_value_t *args,
     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));
@@ -3278,19 +3265,11 @@ njs_string_replace_regexp_function(njs_vm_t *vm, njs_value_t *args,
 
     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]);
 
@@ -3312,7 +3291,7 @@ njs_string_replace_regexp_continuation(njs_vm_t *vm, njs_value_t *args,
 
     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;
@@ -3388,10 +3367,10 @@ static njs_ret_t
 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] */
@@ -3405,20 +3384,11 @@ njs_string_replace_search_function(njs_vm_t *vm, njs_value_t *args,
     /* 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);
@@ -3988,7 +3958,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
     },
@@ -3996,7 +3966,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
     },
@@ -4004,7 +3974,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
     },
@@ -4012,7 +3982,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4021,7 +3991,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4030,7 +4000,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4039,7 +4009,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4048,7 +4018,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4057,7 +4027,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4066,7 +4036,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4075,7 +4045,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4084,7 +4054,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4094,7 +4064,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4103,7 +4073,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4112,7 +4082,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4122,7 +4092,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4132,7 +4102,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4142,7 +4112,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4151,8 +4121,8 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
     },
@@ -4160,8 +4130,8 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
     },
@@ -4169,8 +4139,8 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
     },
@@ -4179,8 +4149,8 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
     },
@@ -4189,7 +4159,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4199,7 +4169,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4208,8 +4178,8 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
     },
@@ -4217,8 +4187,8 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
     },
@@ -4226,7 +4196,7 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     {
         .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,
@@ -4236,7 +4206,6 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
         .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,
index 3c6469d705e6ea2c92d362d4e555095e9d267633..ac82314e65e88d1971b895604f540b97dcace720 100644 (file)
@@ -106,11 +106,10 @@ njs_value_to_primitive(njs_vm_t *vm, njs_value_t *dst, njs_value_t *value,
 {
     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,
@@ -146,8 +145,8 @@ njs_value_to_primitive(njs_vm_t *vm, njs_value_t *dst, njs_value_t *value,
                 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)) {
index ed73dd0be74dacd48bfcc29673f6ad3caa55ece1..e9ef44fa368c1dd39d7bb3f6b862626b5088840b 100644 (file)
@@ -342,13 +342,12 @@ typedef enum {
 }
 
 
-#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,                                            \
index 12bcbf1430292f84218013da60234e54433ce437..a60df1c7e3c2e4740071abf342578251406e07dc 100644 (file)
@@ -30,10 +30,6 @@ static njs_ret_t njs_primitive_values_compare(njs_vm_t *vm, njs_value_t *val1,
 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);
 
@@ -176,6 +172,8 @@ njs_vmcode_run(njs_vm_t *vm)
 {
     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;
@@ -353,14 +351,17 @@ njs_vmcode_template_literal(njs_vm_t *vm, njs_value_t *invld1,
     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);
@@ -414,14 +415,14 @@ njs_vmcode_property_get(njs_vm_t *vm, njs_value_t *object,
     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);
 }
 
 
@@ -546,13 +547,12 @@ njs_vmcode_property_set(njs_vm_t *vm, njs_value_t *object,
     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);
 }
 
 
@@ -816,11 +816,10 @@ njs_vmcode_instance_of(njs_vm_t *vm, njs_value_t *object,
 
     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)) {
@@ -1982,7 +1981,7 @@ njs_function_frame_create(njs_vm_t *vm, njs_value_t *value,
             }
         }
 
-        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));
@@ -2115,51 +2114,20 @@ njs_vmcode_method_frame(njs_vm_t *vm, njs_value_t *object, njs_value_t *name)
 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;
@@ -2177,6 +2145,8 @@ njs_vmcode_return(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
         }
     }
 
+    vm->current = frame->return_address;
+
     previous = njs_function_previous_frame(&frame->native);
 
     njs_vm_scopes_restore(vm, frame, previous);
@@ -2190,17 +2160,13 @@ njs_vmcode_return(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
     /* 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)
 {
@@ -2252,36 +2218,6 @@ njs_vm_scopes_restore(njs_vm_t *vm, njs_frame_t *frame,
 }
 
 
-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)
 {
index 67be5d417c00a6b40381bf040b3a49e2bc25eec5..cfca2524a377d534949c32978cee7d2ec78f6a77 100644 (file)
 #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.
@@ -635,6 +628,8 @@ struct njs_vm_shared_s {
 
 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);
@@ -796,7 +791,5 @@ extern const nxt_str_t    njs_entry_anonymous;
 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_ */
index 5d6c7ea536bddc96bbe6d3278f8d87c8fab395c9..1caac8b8b128af49847d47467634fdad2969a989 100644 (file)
@@ -8449,7 +8449,11 @@ static njs_unit_test_t  njs_test[] =
 
     { 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. */
 
@@ -9085,11 +9089,8 @@ static njs_unit_test_t  njs_test[] =
     { 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("β") },