[njs] Avoiding excessive (njs_value_t *) casts.

Dmitry Volyntsev xeioex at nginx.com
Thu Aug 1 18:01:31 UTC 2019


details:   https://hg.nginx.org/njs/rev/b0823626551d
branches:  
changeset: 1090:b0823626551d
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Aug 01 18:49:28 2019 +0300
description:
Avoiding excessive (njs_value_t *) casts.

Previously njs_arg() returned expression of type (const njs_value_t *).
This caused a lot of casts when calling functions and forced to declared
const njs_value_t * variables.

NO functional changes.

diffstat:

 nginx/ngx_http_js_module.c   |    9 +--
 nginx/ngx_stream_js_module.c |   10 ++--
 src/njs.h                    |    3 +-
 src/njs_array.c              |  102 ++++++++++++++++++++----------------------
 src/njs_builtin.c            |    6 +-
 src/njs_error.c              |    8 +-
 src/njs_function.c           |   31 ++++++------
 src/njs_function.h           |    6 +-
 src/njs_json.c               |    5 +-
 src/njs_object.c             |   71 +++++++++++++++--------------
 src/njs_object.h             |   12 ++--
 src/njs_object_property.c    |   29 +++++------
 src/njs_regexp.c             |    8 +--
 src/njs_string.c             |   10 ++--
 src/njs_vm.c                 |    7 +--
 src/njs_vmcode.c             |    4 +-
 16 files changed, 156 insertions(+), 165 deletions(-)

diffs (truncated from 1021 to 1000 lines):

diff -r 26802fc27c76 -r b0823626551d nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/nginx/ngx_http_js_module.c	Thu Aug 01 18:49:28 2019 +0300
@@ -139,7 +139,7 @@ static void ngx_http_js_clear_timer(njs_
 static void ngx_http_js_timer_handler(ngx_event_t *ev);
 static void ngx_http_js_handle_event(ngx_http_request_t *r,
     njs_vm_event_t vm_event, njs_value_t *args, njs_uint_t nargs);
-static njs_int_t ngx_http_js_string(njs_vm_t *vm, const njs_value_t *value,
+static njs_int_t ngx_http_js_string(njs_vm_t *vm, njs_value_t *value,
     njs_str_t *str);
 
 static char *ngx_http_js_include(ngx_conf_t *cf, ngx_command_t *cmd,
@@ -1246,9 +1246,9 @@ ngx_http_js_ext_return(njs_vm_t *vm, njs
 {
     njs_str_t                  text;
     ngx_int_t                  status;
+    njs_value_t               *value;
     ngx_http_js_ctx_t         *ctx;
     ngx_http_request_t        *r;
-    const njs_value_t         *value;
     ngx_http_complex_value_t   cv;
 
     r = njs_vm_external(vm, njs_arg(args, nargs, 0));
@@ -1729,10 +1729,9 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm,
     ngx_int_t                 rc;
     njs_str_t                 uri_arg, args_arg, method_name, body_arg;
     ngx_uint_t                method, methods_max, has_body;
-    njs_value_t              *value;
+    njs_value_t              *value, *arg, *options;
     njs_function_t           *callback;
     ngx_http_js_ctx_t        *ctx;
-    const njs_value_t        *arg, *options;
     ngx_http_request_t       *r, *sr;
     ngx_http_request_body_t  *rb;
 
@@ -2187,7 +2186,7 @@ ngx_http_js_handle_event(ngx_http_reques
 
 
 static njs_int_t
-ngx_http_js_string(njs_vm_t *vm, const njs_value_t *value, njs_str_t *str)
+ngx_http_js_string(njs_vm_t *vm, njs_value_t *value, njs_str_t *str)
 {
     if (!njs_value_is_null_or_undefined(value)) {
         if (njs_vm_value_to_string(vm, str, value) == NJS_ERROR) {
diff -r 26802fc27c76 -r b0823626551d nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/nginx/ngx_stream_js_module.c	Thu Aug 01 18:49:28 2019 +0300
@@ -110,7 +110,7 @@ static void ngx_stream_js_clear_timer(nj
 static void ngx_stream_js_timer_handler(ngx_event_t *ev);
 static void ngx_stream_js_handle_event(ngx_stream_session_t *s,
     njs_vm_event_t vm_event, njs_value_t *args, njs_uint_t nargs);
-static njs_int_t ngx_stream_js_string(njs_vm_t *vm, const njs_value_t *value,
+static njs_int_t ngx_stream_js_string(njs_vm_t *vm, njs_value_t *value,
     njs_str_t *str);
 
 static char *ngx_stream_js_include(ngx_conf_t *cf, ngx_command_t *cmd,
@@ -931,7 +931,7 @@ static njs_int_t
 ngx_stream_js_ext_set_status(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     ngx_int_t status)
 {
-    const njs_value_t     *code;
+    njs_value_t           *code;
     ngx_stream_js_ctx_t   *ctx;
     ngx_stream_session_t  *s;
 
@@ -1038,8 +1038,8 @@ ngx_stream_js_ext_on(njs_vm_t *vm, njs_v
     njs_index_t unused)
 {
     njs_str_t              name;
+    njs_value_t           *callback;
     njs_vm_event_t        *event;
-    const njs_value_t     *callback;
     ngx_stream_session_t  *s;
 
     s = njs_vm_external(vm, njs_arg(args, nargs, 0));
@@ -1120,9 +1120,9 @@ ngx_stream_js_ext_send(njs_vm_t *vm, njs
     unsigned               last_buf, flush;
     njs_str_t              buffer;
     ngx_buf_t             *b;
+    njs_value_t           *flags, *value;
     ngx_chain_t           *cl;
     ngx_connection_t      *c;
-    const njs_value_t     *flags, *value;
     ngx_stream_js_ctx_t   *ctx;
     ngx_stream_session_t  *s;
 
@@ -1377,7 +1377,7 @@ ngx_stream_js_handle_event(ngx_stream_se
 
 
 static njs_int_t
-ngx_stream_js_string(njs_vm_t *vm, const njs_value_t *value, njs_str_t *str)
+ngx_stream_js_string(njs_vm_t *vm, njs_value_t *value, njs_str_t *str)
 {
     if (!njs_value_is_null_or_undefined(value)) {
         if (njs_vm_value_to_string(vm, str, value) == NJS_ERROR) {
diff -r 26802fc27c76 -r b0823626551d src/njs.h
--- a/src/njs.h	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs.h	Thu Aug 01 18:49:28 2019 +0300
@@ -47,7 +47,8 @@ typedef struct {
 extern const njs_value_t            njs_value_undefined;
 
 #define njs_arg(args, nargs, n)                                               \
-    ((n < nargs) ? njs_argument(args, n) : &njs_value_undefined)
+    ((n < nargs) ? njs_argument(args, n)                                      \
+                 : (njs_value_t *) &njs_value_undefined)
 
 #define njs_value_assign(dst, src)                                            \
     *((njs_opaque_value_t *) dst) = *((njs_opaque_value_t *) src);
diff -r 26802fc27c76 -r b0823626551d src/njs_array.c
--- a/src/njs_array.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_array.c	Thu Aug 01 18:49:28 2019 +0300
@@ -406,7 +406,8 @@ njs_array_prototype_slice(njs_vm_t *vm, 
 
     static const njs_value_t  string_length = njs_string("length");
 
-    ret = njs_value_property(vm, &args[0], &string_length, &prop_length);
+    ret = njs_value_property(vm, &args[0], njs_value_arg(&string_length),
+                             &prop_length);
     if (njs_slow_path(ret == NJS_ERROR)) {
         return ret;
     }
@@ -942,7 +943,7 @@ njs_array_prototype_join(njs_vm_t *vm, n
         value = &args[1];
 
     } else {
-        value = (njs_value_t *) &njs_string_comma;
+        value = njs_value_arg(&njs_string_comma);
     }
 
     (void) njs_string_prop(&separator, value);
@@ -1112,10 +1113,10 @@ static njs_int_t
 njs_array_prototype_last_index_of(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
-    njs_int_t          k, n, index, length;
-    njs_value_t        *start;
-    njs_array_t        *array;
-    const njs_value_t  *this, *value;
+    njs_int_t    k, n, index, length;
+    njs_value_t  *start;
+    njs_array_t  *array;
+    njs_value_t  *this, *value;
 
     index = -1;
 
@@ -1252,16 +1253,15 @@ static njs_int_t
 njs_array_prototype_fill(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    njs_int_t          ret;
-    njs_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;
+    njs_int_t     ret;
+    njs_int_t     i, start, end, length;
+    njs_array_t   *array;
+    njs_value_t   name, prop_length, *this, *value;
+    njs_object_t  *object;
 
     static const njs_value_t  string_length = njs_string("length");
 
-    this = (njs_value_t *) njs_arg(args, nargs, 0);
+    this = njs_arg(args, nargs, 0);
 
     if (njs_is_primitive(this)) {
         if (njs_is_null_or_undefined(this)) {
@@ -1287,7 +1287,8 @@ njs_array_prototype_fill(njs_vm_t *vm, n
         length = array->length;
 
     } else {
-        ret = njs_value_property(vm, this, &string_length, &prop_length);
+        ret = njs_value_property(vm, this, njs_value_arg(&string_length),
+                                 &prop_length);
         if (njs_slow_path(ret == NJS_ERROR)) {
             return ret;
         }
@@ -1331,8 +1332,7 @@ njs_array_prototype_fill(njs_vm_t *vm, n
     while (start < end) {
         njs_uint32_to_string(&name, start++);
 
-        ret = njs_value_property_set(vm, (njs_value_t *) this, &name,
-                                     (njs_value_t *) value);
+        ret = njs_value_property_set(vm, this, &name, value);
         if (njs_slow_path(ret == NJS_ERROR)) {
             return ret;
         }
@@ -1346,8 +1346,8 @@ njs_array_prototype_fill(njs_vm_t *vm, n
 
 njs_inline njs_int_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)
+    const njs_value_t *this_arg, const njs_value_t *value, uint32_t n,
+    const njs_value_t *array)
 {
     njs_value_t  arguments[3];
 
@@ -1357,8 +1357,8 @@ njs_array_iterator_call(njs_vm_t *vm, nj
     njs_set_number(&arguments[1], n);
     arguments[2] = *array;
 
-    return njs_function_call(vm, function, (njs_value_t *) this_arg,
-                             arguments, 3, &vm->retval);
+    return njs_function_call(vm, function, this_arg, arguments, 3,
+                             &vm->retval);
 }
 
 
@@ -1368,9 +1368,8 @@ njs_array_prototype_for_each(njs_vm_t *v
 {
     uint32_t           i, length;
     njs_int_t          ret;
-    njs_value_t        *array, *value;
+    njs_value_t        *array, *value, *this_arg;
     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");
@@ -1379,7 +1378,7 @@ njs_array_prototype_for_each(njs_vm_t *v
 
     array = &args[0];
     length = njs_array_len(array);
-    function =  njs_function(&args[1]);
+    function = njs_function(&args[1]);
     this_arg = njs_arg(args, nargs, 2);
 
     for (i = 0; i < length; i++) {
@@ -1408,9 +1407,9 @@ njs_array_prototype_some(njs_vm_t *vm, n
 {
     uint32_t           i, length;
     njs_int_t          ret;
-    njs_value_t        *array, *value;
+    njs_value_t        *array, *value, *this_arg;
     njs_function_t     *function;
-    const njs_value_t  *this_arg, *retval;
+    const njs_value_t  *retval;
 
     if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
         njs_type_error(vm, "unexpected iterator arguments");
@@ -1419,7 +1418,7 @@ njs_array_prototype_some(njs_vm_t *vm, n
 
     array = &args[0];
     length = njs_array_len(array);
-    function =  njs_function(&args[1]);
+    function = njs_function(&args[1]);
     this_arg = njs_arg(args, nargs, 2);
 
     retval = &njs_value_false;
@@ -1455,9 +1454,9 @@ njs_array_prototype_every(njs_vm_t *vm, 
 {
     uint32_t           i, length;
     njs_int_t          ret;
-    njs_value_t        *array, *value;
+    njs_value_t        *array, *value, *this_arg;
     njs_function_t     *function;
-    const njs_value_t  *this_arg, *retval;
+    const njs_value_t  *retval;
 
     if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
         njs_type_error(vm, "unexpected iterator arguments");
@@ -1466,7 +1465,7 @@ njs_array_prototype_every(njs_vm_t *vm, 
 
     array = &args[0];
     length = njs_array_len(array);
-    function =  njs_function(&args[1]);
+    function = njs_function(&args[1]);
     this_arg = njs_arg(args, nargs, 2);
 
     retval = &njs_value_true;
@@ -1500,12 +1499,11 @@ static njs_int_t
 njs_array_prototype_filter(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    uint32_t           i, length;
-    njs_int_t          ret;
-    njs_array_t        *retval;
-    njs_value_t        *array, value;
-    njs_function_t     *function;
-    const njs_value_t  *this_arg;
+    uint32_t        i, length;
+    njs_int_t       ret;
+    njs_array_t     *retval;
+    njs_value_t     *array, value, *this_arg;
+    njs_function_t  *function;
 
     if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
         njs_type_error(vm, "unexpected iterator arguments");
@@ -1514,7 +1512,7 @@ njs_array_prototype_filter(njs_vm_t *vm,
 
     array = &args[0];
     length = njs_array_len(array);
-    function =  njs_function(&args[1]);
+    function = njs_function(&args[1]);
     this_arg = njs_arg(args, nargs, 2);
 
     retval = njs_array_alloc(vm, 0, NJS_ARRAY_SPARE);
@@ -1555,9 +1553,9 @@ njs_array_prototype_find(njs_vm_t *vm, n
 {
     uint32_t           i, length;
     njs_int_t          ret;
-    njs_value_t        *array, value;
+    njs_value_t        *array, value, *this_arg;
     njs_function_t     *function;
-    const njs_value_t  *this_arg, *retval;
+    const njs_value_t  *retval;
 
     if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
         njs_type_error(vm, "unexpected iterator arguments");
@@ -1566,7 +1564,7 @@ njs_array_prototype_find(njs_vm_t *vm, n
 
     array = &args[0];
     length = njs_array_len(array);
-    function =  njs_function(&args[1]);
+    function = njs_function(&args[1]);
     this_arg = njs_arg(args, nargs, 2);
 
     retval = &njs_value_undefined;
@@ -1601,12 +1599,11 @@ static njs_int_t
 njs_array_prototype_find_index(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
-    double             index;
-    uint32_t           i, length;
-    njs_int_t          ret;
-    njs_value_t        *array, value;
-    njs_function_t     *function;
-    const njs_value_t  *this_arg;
+    double          index;
+    uint32_t        i, length;
+    njs_int_t       ret;
+    njs_value_t     *array, value, *this_arg;
+    njs_function_t  *function;
 
     if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
         njs_type_error(vm, "unexpected iterator arguments");
@@ -1615,7 +1612,7 @@ njs_array_prototype_find_index(njs_vm_t 
 
     array = &args[0];
     length = njs_array_len(array);
-    function =  njs_function(&args[1]);
+    function = njs_function(&args[1]);
     this_arg = njs_arg(args, nargs, 2);
 
     index = -1;
@@ -1650,12 +1647,11 @@ static njs_int_t
 njs_array_prototype_map(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    uint32_t           i, length, size;
-    njs_int_t          ret;
-    njs_array_t        *retval;
-    njs_value_t        *array, *value;
-    njs_function_t     *function;
-    const njs_value_t  *this_arg;
+    uint32_t        i, length, size;
+    njs_int_t       ret;
+    njs_array_t     *retval;
+    njs_value_t     *array, *value, *this_arg;
+    njs_function_t  *function;
 
     if (nargs < 2 || !njs_is_array(&args[0]) || !njs_is_function(&args[1])) {
         njs_type_error(vm, "unexpected iterator arguments");
@@ -1664,7 +1660,7 @@ njs_array_prototype_map(njs_vm_t *vm, nj
 
     array = &args[0];
     length = njs_array_len(array);
-    function =  njs_function(&args[1]);
+    function = njs_function(&args[1]);
     this_arg = njs_arg(args, nargs, 2);
 
     size = length;
diff -r 26802fc27c76 -r b0823626551d src/njs_builtin.c
--- a/src/njs_builtin.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_builtin.c	Thu Aug 01 18:49:28 2019 +0300
@@ -1067,9 +1067,9 @@ static njs_int_t
 njs_dump_value(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    njs_str_t          str;
-    njs_uint_t         n;
-    const njs_value_t  *value, *indent;
+    njs_str_t    str;
+    njs_uint_t   n;
+    njs_value_t  *value, *indent;
 
     value = njs_arg(args, nargs, 1);
     indent = njs_arg(args, nargs, 2);
diff -r 26802fc27c76 -r b0823626551d src/njs_error.c
--- a/src/njs_error.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_error.c	Thu Aug 01 18:49:28 2019 +0300
@@ -534,9 +534,9 @@ static njs_int_t
 njs_memory_error_prototype_create(njs_vm_t *vm, njs_value_t *value,
     njs_value_t *setval, njs_value_t *retval)
 {
-    int32_t         index;
-    njs_value_t     *proto;
-    njs_function_t  *function;
+    int32_t            index;
+    njs_function_t     *function;
+    const njs_value_t  *proto;
 
     /* MemoryError has no its own prototype. */
 
@@ -546,7 +546,7 @@ njs_memory_error_prototype_create(njs_vm
     proto = njs_property_prototype_create(vm, &function->object.hash,
                                           &vm->prototypes[index].object);
     if (proto == NULL) {
-        proto = (njs_value_t *) &njs_value_undefined;
+        proto = &njs_value_undefined;
     }
 
     *retval = *proto;
diff -r 26802fc27c76 -r b0823626551d src/njs_function.c
--- a/src/njs_function.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_function.c	Thu Aug 01 18:49:28 2019 +0300
@@ -464,8 +464,9 @@ njs_function_frame_alloc(njs_vm_t *vm, s
 
 
 njs_int_t
-njs_function_call(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
-    njs_value_t *args, njs_uint_t nargs, njs_value_t *retval)
+njs_function_call(njs_vm_t *vm, njs_function_t *function,
+    const njs_value_t *this, const njs_value_t *args,
+    njs_uint_t nargs, njs_value_t *retval)
 {
     njs_int_t    ret;
     njs_value_t  dst njs_aligned(16);
@@ -944,9 +945,9 @@ static njs_int_t
 njs_function_prototype_call(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t retval)
 {
-    njs_int_t       ret;
-    njs_value_t     *this;
-    njs_function_t  *function;
+    njs_int_t          ret;
+    njs_function_t     *function;
+    const njs_value_t  *this;
 
     if (!njs_is_function(&args[0])) {
         njs_type_error(vm, "\"this\" argument is not a function");
@@ -996,14 +997,13 @@ static njs_int_t
 njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t retval)
 {
-    uint32_t           i;
-    njs_int_t          ret;
-    njs_value_t        length, name;
-    njs_array_t        *arr;
-    njs_function_t     *func;
-    const njs_value_t  *this, *arr_like;
+    uint32_t        i;
+    njs_int_t       ret;
+    njs_value_t     length, name, *this, *arr_like;
+    njs_array_t     *arr;
+    njs_function_t  *func;
 
-    static const njs_value_t  njs_string_length = njs_string("length");
+    static const njs_value_t  string_length = njs_string("length");
 
     if (!njs_is_function(njs_arg(args, nargs, 0))) {
         njs_type_error(vm, "\"this\" argument is not a function");
@@ -1032,7 +1032,8 @@ njs_function_prototype_apply(njs_vm_t *v
         return NJS_ERROR;
     }
 
-    ret = njs_value_property(vm, arr_like, &njs_string_length, &length);
+    ret = njs_value_property(vm, arr_like, njs_value_arg(&string_length),
+                             &length);
     if (njs_slow_path(ret == NJS_ERROR)) {
         return ret;
     }
@@ -1065,7 +1066,7 @@ activate:
     /* Skip the "apply" method frame. */
     vm->top_frame->skip = 1;
 
-    ret = njs_function_frame(vm, func, (njs_value_t *) this, args, nargs, 0);
+    ret = njs_function_frame(vm, func, this, args, nargs, 0);
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -1099,7 +1100,7 @@ njs_function_prototype_bind(njs_vm_t *vm
     }
 
     if (nargs == 1) {
-        args = (njs_value_t *) &njs_value_undefined;
+        args = njs_value_arg(&njs_value_undefined);
 
     } else {
         nargs--;
diff -r 26802fc27c76 -r b0823626551d src/njs_function.h
--- a/src/njs_function.h	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_function.h	Thu Aug 01 18:49:28 2019 +0300
@@ -129,7 +129,7 @@ njs_int_t njs_function_lambda_frame(njs_
     const njs_value_t *this, const njs_value_t *args, njs_uint_t nargs,
     njs_bool_t ctor);
 njs_int_t njs_function_call(njs_vm_t *vm, njs_function_t *function,
-    njs_value_t *this, njs_value_t *args, njs_uint_t nargs,
+    const njs_value_t *this, const njs_value_t *args, njs_uint_t nargs,
     njs_value_t *retval);
 njs_int_t njs_function_lambda_call(njs_vm_t *vm);
 njs_int_t njs_function_native_call(njs_vm_t *vm);
@@ -199,8 +199,8 @@ njs_function_frame_invoke(njs_vm_t *vm, 
 
 
 njs_inline njs_int_t
-njs_function_apply(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
-    njs_uint_t nargs, njs_value_t *retval)
+njs_function_apply(njs_vm_t *vm, njs_function_t *function,
+    const njs_value_t *args, njs_uint_t nargs, njs_value_t *retval)
 {
     return njs_function_call(vm, function, &args[0], &args[1], nargs - 1,
                              retval);
diff -r 26802fc27c76 -r b0823626551d src/njs_json.c
--- a/src/njs_json.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_json.c	Thu Aug 01 18:49:28 2019 +0300
@@ -252,8 +252,7 @@ njs_json_stringify(njs_vm_t *vm, njs_val
     double                num;
     njs_int_t             i;
     njs_int_t             ret;
-    njs_value_t           *wrapper;
-    const njs_value_t     *replacer, *space;
+    njs_value_t           *wrapper, *replacer, *space;
     njs_json_stringify_t  *stringify, json_stringify;
 
     stringify = &json_stringify;
@@ -1802,7 +1801,7 @@ njs_json_append_string(njs_json_stringif
     static char   hex2char[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
                                    '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
 
-    (void) njs_string_prop(&str, (njs_value_t *) value);
+    (void) njs_string_prop(&str, value);
 
     p = str.start;
     end = p + str.size;
diff -r 26802fc27c76 -r b0823626551d src/njs_object.c
--- a/src/njs_object.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_object.c	Thu Aug 01 18:49:28 2019 +0300
@@ -193,9 +193,9 @@ njs_int_t
 njs_object_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    njs_uint_t         type;
-    njs_object_t       *object;
-    const njs_value_t  *value;
+    njs_uint_t    type;
+    njs_value_t   *value;
+    njs_object_t  *object;
 
     value = njs_arg(args, nargs, 1);
     type = value->type;
@@ -244,8 +244,8 @@ static njs_int_t
 njs_object_create(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    njs_object_t       *object;
-    const njs_value_t  *value;
+    njs_value_t   *value;
+    njs_object_t  *object;
 
     value = njs_arg(args, nargs, 1);
 
@@ -280,8 +280,8 @@ static njs_int_t
 njs_object_keys(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    njs_array_t        *keys;
-    const njs_value_t  *value;
+    njs_value_t  *value;
+    njs_array_t  *keys;
 
     value = njs_arg(args, nargs, 1);
 
@@ -307,8 +307,8 @@ static njs_int_t
 njs_object_values(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    njs_array_t        *array;
-    const njs_value_t  *value;
+    njs_array_t  *array;
+    njs_value_t  *value;
 
     value = njs_arg(args, nargs, 1);
 
@@ -334,8 +334,8 @@ static njs_int_t
 njs_object_entries(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    njs_array_t        *array;
-    const njs_value_t  *value;
+    njs_array_t  *array;
+    njs_value_t  *value;
 
     value = njs_arg(args, nargs, 1);
 
@@ -1087,9 +1087,8 @@ static njs_int_t
 njs_object_define_property(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    njs_int_t          ret;
-    njs_value_t        *value;
-    const njs_value_t  *name, *desc;
+    njs_int_t    ret;
+    njs_value_t  *value, *name, *desc;
 
     if (!njs_is_object(njs_arg(args, nargs, 1))) {
         njs_type_error(vm, "cannot convert %s argument to object",
@@ -1129,11 +1128,10 @@ njs_object_define_properties(njs_vm_t *v
     njs_index_t unused)
 {
     njs_int_t          ret;
-    njs_value_t        *value;
+    njs_value_t        *value, *desc;
     njs_lvlhsh_t       *hash;
     njs_lvlhsh_each_t  lhe;
     njs_object_prop_t  *prop;
-    const njs_value_t  *desc;
 
     if (!njs_is_object(njs_arg(args, nargs, 1))) {
         njs_type_error(vm, "cannot convert %s argument to object",
@@ -1185,7 +1183,7 @@ static njs_int_t
 njs_object_get_own_property_descriptor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
-    const njs_value_t  *value, *property;
+    njs_value_t  *value, *property;
 
     value = njs_arg(args, nargs, 1);
 
@@ -1208,9 +1206,8 @@ njs_object_get_own_property_descriptors(
     njs_int_t           ret;
     uint32_t            i, length;
     njs_array_t         *names;
-    njs_value_t         descriptor;
+    njs_value_t         descriptor, *value, *key;
     njs_object_t        *descriptors;
-    const njs_value_t   *value, *key;
     njs_object_prop_t   *pr;
     njs_lvlhsh_query_t  lhq;
 
@@ -1272,8 +1269,8 @@ static njs_int_t
 njs_object_get_own_property_names(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
-    njs_array_t        *names;
-    const njs_value_t  *value;
+    njs_array_t  *names;
+    njs_value_t  *value;
 
     value = njs_arg(args, nargs, 1);
 
@@ -1299,13 +1296,12 @@ static njs_int_t
 njs_object_get_prototype_of(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    const njs_value_t  *value;
+    njs_value_t  *value;
 
     value = njs_arg(args, nargs, 1);
 
     if (njs_is_object(value)) {
-        njs_object_prototype_proto(vm, (njs_value_t *) value, NULL,
-                                   &vm->retval);
+        njs_object_prototype_proto(vm, value, NULL, &vm->retval);
         return NJS_OK;
     }
 
@@ -1320,11 +1316,11 @@ static njs_int_t
 njs_object_freeze(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
+    njs_value_t        *value;
     njs_lvlhsh_t       *hash;
     njs_object_t       *object;
     njs_object_prop_t  *prop;
     njs_lvlhsh_each_t  lhe;
-    const njs_value_t  *value;
 
     value = njs_arg(args, nargs, 1);
 
@@ -1361,11 +1357,12 @@ static njs_int_t
 njs_object_is_frozen(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
+    njs_value_t        *value;
     njs_lvlhsh_t       *hash;
     njs_object_t       *object;
     njs_object_prop_t  *prop;
     njs_lvlhsh_each_t  lhe;
-    const njs_value_t  *value, *retval;
+    const njs_value_t  *retval;
 
     value = njs_arg(args, nargs, 1);
 
@@ -1415,9 +1412,9 @@ static njs_int_t
 njs_object_seal(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
+    njs_value_t        *value;
     njs_lvlhsh_t       *hash;
     njs_object_t       *object;
-    const njs_value_t  *value;
     njs_object_prop_t  *prop;
     njs_lvlhsh_each_t  lhe;
 
@@ -1455,11 +1452,12 @@ static njs_int_t
 njs_object_is_sealed(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
+    njs_value_t        *value;
     njs_lvlhsh_t       *hash;
     njs_object_t       *object;
     njs_object_prop_t  *prop;
     njs_lvlhsh_each_t  lhe;
-    const njs_value_t  *value, *retval;
+    const njs_value_t  *retval;
 
     value = njs_arg(args, nargs, 1);
 
@@ -1505,7 +1503,7 @@ static njs_int_t
 njs_object_prevent_extensions(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    const njs_value_t  *value;
+    njs_value_t  *value;
 
     value = njs_arg(args, nargs, 1);
 
@@ -1526,7 +1524,8 @@ static njs_int_t
 njs_object_is_extensible(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    const njs_value_t  *value, *retval;
+    njs_value_t        *value;
+    const njs_value_t  *retval;
 
     value = njs_arg(args, nargs, 1);
 
@@ -2114,7 +2113,7 @@ njs_object_prototype_has_own_property(nj
     njs_uint_t nargs, njs_index_t unused)
 {
     njs_int_t             ret;
-    const njs_value_t     *value, *property;
+    njs_value_t           *value, *property;
     njs_property_query_t  pq;
 
     value = njs_arg(args, nargs, 0);
@@ -2129,7 +2128,7 @@ njs_object_prototype_has_own_property(nj
 
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1);
 
-    ret = njs_property_query(vm, &pq, (njs_value_t *) value, property);
+    ret = njs_property_query(vm, &pq, value, property);
 
     switch (ret) {
     case NJS_OK:
@@ -2152,7 +2151,8 @@ njs_object_prototype_prop_is_enumerable(
     njs_uint_t nargs, njs_index_t unused)
 {
     njs_int_t             ret;
-    const njs_value_t     *value, *property, *retval;
+    njs_value_t           *value, *property;
+    const njs_value_t     *retval;
     njs_object_prop_t     *prop;
     njs_property_query_t  pq;
 
@@ -2168,7 +2168,7 @@ njs_object_prototype_prop_is_enumerable(
 
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1);
 
-    ret = njs_property_query(vm, &pq, (njs_value_t *) value, property);
+    ret = njs_property_query(vm, &pq, value, property);
 
     switch (ret) {
     case NJS_OK:
@@ -2195,8 +2195,9 @@ static njs_int_t
 njs_object_prototype_is_prototype_of(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
+    njs_value_t        *prototype, *value;
     njs_object_t       *object, *proto;
-    const njs_value_t  *prototype, *value, *retval;
+    const njs_value_t  *retval;
 
     retval = &njs_value_false;
     prototype = &args[0];
diff -r 26802fc27c76 -r b0823626551d src/njs_object.h
--- a/src/njs_object.h	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_object.h	Thu Aug 01 18:49:28 2019 +0300
@@ -125,19 +125,19 @@ njs_int_t njs_object_prototype_to_string
     njs_uint_t nargs, njs_index_t unused);
 
 njs_int_t njs_property_query(njs_vm_t *vm, njs_property_query_t *pq,
-    njs_value_t *object, const njs_value_t *property);
-njs_int_t njs_value_property(njs_vm_t *vm, const njs_value_t *value,
-    const njs_value_t *property, njs_value_t *retval);
+    njs_value_t *object, njs_value_t *property);
+njs_int_t njs_value_property(njs_vm_t *vm, njs_value_t *value,
+    njs_value_t *property, njs_value_t *retval);
 njs_int_t njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
-    const njs_value_t *property, njs_value_t *value);
+    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,
     njs_lvlhsh_query_t *lhq);
 njs_int_t njs_object_prop_define(njs_vm_t *vm, njs_value_t *object,
-    const njs_value_t *name, const njs_value_t *value);
+    njs_value_t *name, njs_value_t *value);
 njs_int_t njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
-    const njs_value_t *value, const njs_value_t *property);
+    njs_value_t *value, njs_value_t *property);
 njs_int_t njs_prop_private_copy(njs_vm_t *vm, njs_property_query_t *pq);
 const char *njs_prop_type_string(njs_object_prop_type_t type);
 
diff -r 26802fc27c76 -r b0823626551d src/njs_object_property.c
--- a/src/njs_object_property.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_object_property.c	Thu Aug 01 18:49:28 2019 +0300
@@ -46,7 +46,7 @@ static njs_object_prop_t *njs_descriptor
 
 njs_int_t
 njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
-    const njs_value_t *property)
+    njs_value_t *property)
 {
     uint32_t        index;
     njs_int_t       ret;
@@ -55,7 +55,7 @@ njs_property_query(njs_vm_t *vm, njs_pro
     njs_function_t  *function;
 
     if (njs_slow_path(!njs_is_primitive(property))) {
-        ret = njs_value_to_string(vm, &prop, (njs_value_t *) property);
+        ret = njs_value_to_string(vm, &prop, property);
         if (ret != NJS_OK) {
             return ret;
         }
@@ -479,8 +479,8 @@ njs_external_property_delete(njs_vm_t *v
  *      retval will contain undefined
  */
 njs_int_t
-njs_value_property(njs_vm_t *vm, const njs_value_t *value,
-    const njs_value_t *property, njs_value_t *retval)
+njs_value_property(njs_vm_t *vm, njs_value_t *value, njs_value_t *property,
+    njs_value_t *retval)
 {
     njs_int_t             ret;
     njs_object_prop_t     *prop;
@@ -488,7 +488,7 @@ njs_value_property(njs_vm_t *vm, const n
 
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0);
 
-    ret = njs_property_query(vm, &pq, (njs_value_t *) value, property);
+    ret = njs_property_query(vm, &pq, value, property);
 
     switch (ret) {
 
@@ -521,14 +521,14 @@ njs_value_property(njs_vm_t *vm, const n
                 break;
             }
 
-            return njs_function_apply(vm, njs_function(&prop->getter),
-                                      (njs_value_t *) value, 1, retval);
+            return njs_function_apply(vm, njs_function(&prop->getter), value,
+                                      1, retval);
 
         case NJS_PROPERTY_HANDLER:
             pq.scratch = *prop;
             prop = &pq.scratch;
-            ret = prop->value.data.u.prop_handler(vm, (njs_value_t *) value,
-                                                  NULL, &prop->value);
+            ret = prop->value.data.u.prop_handler(vm, value, NULL,
+                                                  &prop->value);
 
             if (njs_slow_path(ret != NJS_OK)) {
                 return ret;
@@ -568,7 +568,7 @@ njs_value_property(njs_vm_t *vm, const n
  */
 njs_int_t
 njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
-    const njs_value_t *property, njs_value_t *value)
+    njs_value_t *property, njs_value_t *value)
 {
     njs_int_t             ret;
     njs_object_prop_t     *prop, *shared;
@@ -771,7 +771,7 @@ njs_object_property(njs_vm_t *vm, const 
  */
 njs_int_t
 njs_object_prop_define(njs_vm_t *vm, njs_value_t *object,
-    const njs_value_t *name, const njs_value_t *value)
+    njs_value_t *name, njs_value_t *value)
 {
     njs_int_t             ret;
     njs_object_prop_t     *prop, *prev;
@@ -1123,7 +1123,7 @@ static const njs_value_t  njs_object_con
 
 njs_int_t
 njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
-    const njs_value_t *value, const njs_value_t *property)
+    njs_value_t *value, njs_value_t *property)
 {
     njs_int_t             ret;
     njs_object_t          *desc;
@@ -1134,7 +1134,7 @@ njs_object_prop_descriptor(njs_vm_t *vm,
 
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1);
 
-    ret = njs_property_query(vm, &pq, (njs_value_t *) value, property);
+    ret = njs_property_query(vm, &pq, value, property);
 
     switch (ret) {
     case NJS_OK:
@@ -1158,8 +1158,7 @@ njs_object_prop_descriptor(njs_vm_t *vm,
     case NJS_PROPERTY_HANDLER:
         pq.scratch = *prop;
         prop = &pq.scratch;
-        ret = prop->value.data.u.prop_handler(vm, (njs_value_t *) value,
-                                              NULL, &prop->value);
+        ret = prop->value.data.u.prop_handler(vm, value, NULL, &prop->value);
         if (njs_slow_path(ret != NJS_OK)) {
             return ret;
         }
diff -r 26802fc27c76 -r b0823626551d src/njs_regexp.c
--- a/src/njs_regexp.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_regexp.c	Thu Aug 01 18:49:28 2019 +0300
@@ -105,8 +105,7 @@ njs_regexp_constructor(njs_vm_t *vm, njs
     u_char              *start;
     njs_int_t           ret;
     njs_str_t           string;
-    njs_value_t         source, flags_string;
-    const njs_value_t   *pattern, *flags;
+    njs_value_t         source, flags_string, *pattern, *flags;
     njs_regexp_flags_t  re_flags;
 
     pattern = njs_arg(args, nargs, 1);
@@ -130,8 +129,7 @@ njs_regexp_constructor(njs_vm_t *vm, njs
     re_flags = 0;
 
     if (njs_is_regexp(pattern)) {
-        ret = njs_regexp_prototype_source(vm, (njs_value_t *) pattern, NULL,
-                                          &source);
+        ret = njs_regexp_prototype_source(vm, pattern, NULL, &source);
         if (njs_slow_path(ret != NJS_OK)) {
             return ret;
         }
@@ -142,7 +140,7 @@ njs_regexp_constructor(njs_vm_t *vm, njs
 
     } else {
         if (njs_is_undefined(pattern)) {
-            pattern = &njs_string_empty;
+            pattern = njs_value_arg(&njs_string_empty);
         }
 
         ret = njs_primitive_value_to_string(vm, &source, pattern);
diff -r 26802fc27c76 -r b0823626551d src/njs_string.c
--- a/src/njs_string.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_string.c	Thu Aug 01 18:49:28 2019 +0300
@@ -1271,8 +1271,8 @@ static void
 njs_string_slice_args(njs_slice_prop_t *slice, njs_value_t *args,
     njs_uint_t nargs)
 {
-    ssize_t            start, end, length;
-    const njs_value_t  *value;
+    ssize_t      start, end, length;
+    njs_value_t  *value;
 
     length = slice->string_length;
 
@@ -1444,7 +1444,7 @@ static njs_int_t
 njs_string_bytes_from(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    const njs_value_t  *value;
+    njs_value_t  *value;
 
     value = njs_arg(args, nargs, 1);
 
@@ -1504,8 +1504,8 @@ static njs_int_t
 njs_string_bytes_from_string(njs_vm_t *vm, const njs_value_t *args,
     njs_uint_t nargs)
 {
-    njs_str_t          enc, str;
-    const njs_value_t  *enc_val;
+    njs_str_t    enc, str;
+    njs_value_t  *enc_val;
 
     enc_val = njs_arg(args, nargs, 2);
 
diff -r 26802fc27c76 -r b0823626551d src/njs_vm.c
--- a/src/njs_vm.c	Thu Aug 01 18:48:39 2019 +0300
+++ b/src/njs_vm.c	Thu Aug 01 18:49:28 2019 +0300
@@ -471,12 +471,9 @@ njs_int_t
 njs_vm_invoke(njs_vm_t *vm, njs_function_t *function, const njs_value_t *args,
     njs_uint_t nargs, njs_index_t retval)
 {
-    njs_int_t    ret;
-    njs_value_t  *this;
+    njs_int_t  ret;
 


More information about the nginx-devel mailing list