[njs] Added default number of arguments expected by builtin functions.

Alexander Borisov alexander.borisov at nginx.com
Fri Oct 11 16:42:39 UTC 2019


details:   https://hg.nginx.org/njs/rev/30c1bde3f194
branches:  
changeset: 1184:30c1bde3f194
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Fri Oct 11 19:41:51 2019 +0300
description:
Added default number of arguments expected by builtin functions.

This closes #207 issue on GitHub.

diffstat:

 src/njs_array.c    |  52 ++++++++++++++--------------
 src/njs_boolean.c  |   4 +-
 src/njs_builtin.c  |   2 +-
 src/njs_crypto.c   |  16 ++++----
 src/njs_date.c     |  95 +++++++++++++++++++++++++++--------------------------
 src/njs_error.c    |   7 ++-
 src/njs_fs.c       |  14 +++---
 src/njs_function.c |  40 +++++++---------------
 src/njs_json.c     |   4 +-
 src/njs_math.c     |  70 +++++++++++++++++++-------------------
 src/njs_number.c   |  22 ++++++------
 src/njs_object.c   |  42 +++++++++++-----------
 src/njs_parser.c   |   7 +++-
 src/njs_regexp.c   |   6 +-
 src/njs_string.c   |  66 ++++++++++++++++++------------------
 src/njs_value.h    |   5 +-
 src/njs_vmcode.c   |   2 +
 17 files changed, 226 insertions(+), 228 deletions(-)

diffs (truncated from 1966 to 1000 lines):

diff -r b4cd260f7b69 -r 30c1bde3f194 src/njs_array.c
--- a/src/njs_array.c	Fri Oct 11 17:08:28 2019 +0300
+++ b/src/njs_array.c	Fri Oct 11 19:41:51 2019 +0300
@@ -304,7 +304,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("isArray"),
-        .value = njs_native_function(njs_array_is_array, 0),
+        .value = njs_native_function(njs_array_is_array, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -314,7 +314,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("of"),
-        .value = njs_native_function(njs_array_of, 0),
+        .value = njs_native_function(njs_array_of, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2736,7 +2736,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("slice"),
-        .value = njs_native_function(njs_array_prototype_slice,
+        .value = njs_native_function(njs_array_prototype_slice, 2,
                      NJS_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2745,7 +2745,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("push"),
-        .value = njs_native_function(njs_array_prototype_push, 0),
+        .value = njs_native_function(njs_array_prototype_push, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2753,7 +2753,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("pop"),
-        .value = njs_native_function(njs_array_prototype_pop, 0),
+        .value = njs_native_function(njs_array_prototype_pop, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2761,7 +2761,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("unshift"),
-        .value = njs_native_function(njs_array_prototype_unshift, 0),
+        .value = njs_native_function(njs_array_prototype_unshift, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2769,7 +2769,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("shift"),
-        .value = njs_native_function(njs_array_prototype_shift, 0),
+        .value = njs_native_function(njs_array_prototype_shift, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2777,7 +2777,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("splice"),
-        .value = njs_native_function(njs_array_prototype_splice,
+        .value = njs_native_function(njs_array_prototype_splice, 2,
                     NJS_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2786,7 +2786,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("reverse"),
-        .value = njs_native_function(njs_array_prototype_reverse,
+        .value = njs_native_function(njs_array_prototype_reverse, 0,
                                      NJS_OBJECT_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2795,7 +2795,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toString"),
-        .value = njs_native_function(njs_array_prototype_to_string, 0),
+        .value = njs_native_function(njs_array_prototype_to_string, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2803,7 +2803,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("join"),
-        .value = njs_native_function(njs_array_prototype_join,
+        .value = njs_native_function(njs_array_prototype_join, 1,
                      NJS_OBJECT_ARG, NJS_STRING_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2812,7 +2812,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("concat"),
-        .value = njs_native_function(njs_array_prototype_concat, 0),
+        .value = njs_native_function(njs_array_prototype_concat, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2820,7 +2820,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("indexOf"),
-        .value = njs_native_function(njs_array_prototype_index_of,
+        .value = njs_native_function(njs_array_prototype_index_of, 1,
                      NJS_OBJECT_ARG, NJS_SKIP_ARG, NJS_INTEGER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2829,7 +2829,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("lastIndexOf"),
-        .value = njs_native_function(njs_array_prototype_last_index_of,
+        .value = njs_native_function(njs_array_prototype_last_index_of, 1,
                      NJS_OBJECT_ARG, NJS_SKIP_ARG, NJS_INTEGER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2839,7 +2839,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("includes"),
-        .value = njs_native_function(njs_array_prototype_includes,
+        .value = njs_native_function(njs_array_prototype_includes, 1,
                      NJS_OBJECT_ARG, NJS_SKIP_ARG, NJS_INTEGER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2848,7 +2848,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("forEach"),
-        .value = njs_native_function(njs_array_prototype_for_each, 0),
+        .value = njs_native_function(njs_array_prototype_for_each, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2856,7 +2856,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("some"),
-        .value = njs_native_function(njs_array_prototype_some, 0),
+        .value = njs_native_function(njs_array_prototype_some, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2864,7 +2864,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("every"),
-        .value = njs_native_function(njs_array_prototype_every, 0),
+        .value = njs_native_function(njs_array_prototype_every, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2873,7 +2873,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("fill"),
-        .value = njs_native_function(njs_array_prototype_fill,
+        .value = njs_native_function(njs_array_prototype_fill, 1,
                      NJS_OBJECT_ARG, NJS_SKIP_ARG, NJS_NUMBER_ARG,
                      NJS_NUMBER_ARG),
         .writable = 1,
@@ -2883,7 +2883,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("filter"),
-        .value = njs_native_function(njs_array_prototype_filter, 0),
+        .value = njs_native_function(njs_array_prototype_filter, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2892,7 +2892,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("find"),
-        .value = njs_native_function(njs_array_prototype_find, 0),
+        .value = njs_native_function(njs_array_prototype_find, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2901,7 +2901,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("findIndex"),
-        .value = njs_native_function(njs_array_prototype_find_index, 0),
+        .value = njs_native_function(njs_array_prototype_find_index, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2909,7 +2909,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("map"),
-        .value = njs_native_function(njs_array_prototype_map, 0),
+        .value = njs_native_function(njs_array_prototype_map, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2917,7 +2917,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("reduce"),
-        .value = njs_native_function(njs_array_prototype_reduce, 0),
+        .value = njs_native_function(njs_array_prototype_reduce, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2925,7 +2925,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("reduceRight"),
-        .value = njs_native_function(njs_array_prototype_reduce_right, 0),
+        .value = njs_native_function(njs_array_prototype_reduce_right, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -2933,7 +2933,7 @@ static const njs_object_prop_t  njs_arra
     {
         .type = NJS_PROPERTY,
         .name = njs_string("sort"),
-        .value = njs_native_function(njs_array_prototype_sort, 0),
+        .value = njs_native_function(njs_array_prototype_sort, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
diff -r b4cd260f7b69 -r 30c1bde3f194 src/njs_boolean.c
--- a/src/njs_boolean.c	Fri Oct 11 17:08:28 2019 +0300
+++ b/src/njs_boolean.c	Fri Oct 11 19:41:51 2019 +0300
@@ -145,7 +145,7 @@ static const njs_object_prop_t  njs_bool
     {
         .type = NJS_PROPERTY,
         .name = njs_string("valueOf"),
-        .value = njs_native_function(njs_boolean_prototype_value_of, 0),
+        .value = njs_native_function(njs_boolean_prototype_value_of, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -153,7 +153,7 @@ static const njs_object_prop_t  njs_bool
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toString"),
-        .value = njs_native_function(njs_boolean_prototype_to_string, 0),
+        .value = njs_native_function(njs_boolean_prototype_to_string, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
diff -r b4cd260f7b69 -r 30c1bde3f194 src/njs_builtin.c
--- a/src/njs_builtin.c	Fri Oct 11 17:08:28 2019 +0300
+++ b/src/njs_builtin.c	Fri Oct 11 19:41:51 2019 +0300
@@ -1117,7 +1117,7 @@ static const njs_object_prop_t  njs_njs_
     {
         .type = NJS_PROPERTY,
         .name = njs_string("dump"),
-        .value = njs_native_function(njs_dump_value,
+        .value = njs_native_function(njs_dump_value, 0,
                                     NJS_SKIP_ARG, NJS_SKIP_ARG, NJS_NUMBER_ARG),
         .configurable = 1,
     },
diff -r b4cd260f7b69 -r 30c1bde3f194 src/njs_crypto.c
--- a/src/njs_crypto.c	Fri Oct 11 17:08:28 2019 +0300
+++ b/src/njs_crypto.c	Fri Oct 11 19:41:51 2019 +0300
@@ -323,7 +323,7 @@ static const njs_object_prop_t  njs_hash
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toString"),
-        .value = njs_native_function(njs_hash_prototype_to_string, 0),
+        .value = njs_native_function(njs_hash_prototype_to_string, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -331,7 +331,7 @@ static const njs_object_prop_t  njs_hash
     {
         .type = NJS_PROPERTY,
         .name = njs_string("update"),
-        .value = njs_native_function(njs_hash_prototype_update,
+        .value = njs_native_function(njs_hash_prototype_update, 0,
                                      NJS_OBJECT_ARG, NJS_SKIP_ARG),
         .writable = 1,
         .configurable = 1,
@@ -340,7 +340,7 @@ static const njs_object_prop_t  njs_hash
     {
         .type = NJS_PROPERTY,
         .name = njs_string("digest"),
-        .value = njs_native_function(njs_hash_prototype_digest,
+        .value = njs_native_function(njs_hash_prototype_digest, 0,
                                      NJS_OBJECT_ARG, NJS_SKIP_ARG),
         .writable = 1,
         .configurable = 1,
@@ -585,7 +585,7 @@ static const njs_object_prop_t  njs_hmac
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toString"),
-        .value = njs_native_function(njs_hmac_prototype_to_string, 0),
+        .value = njs_native_function(njs_hmac_prototype_to_string, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -593,7 +593,7 @@ static const njs_object_prop_t  njs_hmac
     {
         .type = NJS_PROPERTY,
         .name = njs_string("update"),
-        .value = njs_native_function(njs_hmac_prototype_update,
+        .value = njs_native_function(njs_hmac_prototype_update, 0,
                                      NJS_OBJECT_ARG, NJS_SKIP_ARG),
         .writable = 1,
         .configurable = 1,
@@ -602,7 +602,7 @@ static const njs_object_prop_t  njs_hmac
     {
         .type = NJS_PROPERTY,
         .name = njs_string("digest"),
-        .value = njs_native_function(njs_hmac_prototype_digest,
+        .value = njs_native_function(njs_hmac_prototype_digest, 0,
                                      NJS_OBJECT_ARG, NJS_SKIP_ARG),
         .writable = 1,
         .configurable = 1,
@@ -650,7 +650,7 @@ static const njs_object_prop_t  njs_cryp
     {
         .type = NJS_PROPERTY,
         .name = njs_string("createHash"),
-        .value = njs_native_function(njs_crypto_create_hash,
+        .value = njs_native_function(njs_crypto_create_hash, 0,
                                      NJS_SKIP_ARG),
         .writable = 1,
         .configurable = 1,
@@ -659,7 +659,7 @@ static const njs_object_prop_t  njs_cryp
     {
         .type = NJS_PROPERTY,
         .name = njs_string("createHmac"),
-        .value = njs_native_function(njs_crypto_create_hmac,
+        .value = njs_native_function(njs_crypto_create_hmac, 0,
                                      NJS_SKIP_ARG),
         .writable = 1,
         .configurable = 1,
diff -r b4cd260f7b69 -r 30c1bde3f194 src/njs_date.c
--- a/src/njs_date.c	Fri Oct 11 17:08:28 2019 +0300
+++ b/src/njs_date.c	Fri Oct 11 19:41:51 2019 +0300
@@ -1016,7 +1016,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("UTC"),
-        .value = njs_native_function(njs_date_utc, 0),
+        .value = njs_native_function(njs_date_utc, 7, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -1024,7 +1024,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("now"),
-        .value = njs_native_function(njs_date_now, 0),
+        .value = njs_native_function(njs_date_now, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -1032,7 +1032,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("parse"),
-        .value = njs_native_function(njs_date_parse,
+        .value = njs_native_function(njs_date_parse, 1,
                                      NJS_SKIP_ARG, NJS_STRING_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2034,7 +2034,8 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("valueOf"),
-        .value = njs_native_function(njs_date_prototype_value_of, NJS_DATE_ARG),
+        .value = njs_native_function(njs_date_prototype_value_of, 0,
+                                     NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
     },
@@ -2042,7 +2043,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toString"),
-        .value = njs_native_function(njs_date_prototype_to_string,
+        .value = njs_native_function(njs_date_prototype_to_string, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2051,7 +2052,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toDateString"),
-        .value = njs_native_function(njs_date_prototype_to_date_string,
+        .value = njs_native_function(njs_date_prototype_to_date_string, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2060,7 +2061,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toTimeString"),
-        .value = njs_native_function(njs_date_prototype_to_time_string,
+        .value = njs_native_function(njs_date_prototype_to_time_string, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2069,7 +2070,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toLocaleString"),
-        .value = njs_native_function(njs_date_prototype_to_string,
+        .value = njs_native_function(njs_date_prototype_to_string, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2078,7 +2079,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_long_string("toLocaleDateString"),
-        .value = njs_native_function(njs_date_prototype_to_date_string,
+        .value = njs_native_function(njs_date_prototype_to_date_string, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2087,7 +2088,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_long_string("toLocaleTimeString"),
-        .value = njs_native_function(njs_date_prototype_to_time_string,
+        .value = njs_native_function(njs_date_prototype_to_time_string, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2096,7 +2097,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toUTCString"),
-        .value = njs_native_function(njs_date_prototype_to_utc_string,
+        .value = njs_native_function(njs_date_prototype_to_utc_string, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2105,7 +2106,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toISOString"),
-        .value = njs_native_function(njs_date_prototype_to_iso_string,
+        .value = njs_native_function(njs_date_prototype_to_iso_string, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2114,7 +2115,8 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getTime"),
-        .value = njs_native_function(njs_date_prototype_value_of, NJS_DATE_ARG),
+        .value = njs_native_function(njs_date_prototype_value_of, 0,
+                                     NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
     },
@@ -2122,7 +2124,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getFullYear"),
-        .value = njs_native_function(njs_date_prototype_get_full_year,
+        .value = njs_native_function(njs_date_prototype_get_full_year, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2131,7 +2133,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getUTCFullYear"),
-        .value = njs_native_function(njs_date_prototype_get_utc_full_year,
+        .value = njs_native_function(njs_date_prototype_get_utc_full_year, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2140,7 +2142,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getMonth"),
-        .value = njs_native_function(njs_date_prototype_get_month,
+        .value = njs_native_function(njs_date_prototype_get_month, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2149,7 +2151,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getUTCMonth"),
-        .value = njs_native_function(njs_date_prototype_get_utc_month,
+        .value = njs_native_function(njs_date_prototype_get_utc_month, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2158,7 +2160,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getDate"),
-        .value = njs_native_function(njs_date_prototype_get_date,
+        .value = njs_native_function(njs_date_prototype_get_date, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2167,7 +2169,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getUTCDate"),
-        .value = njs_native_function(njs_date_prototype_get_utc_date,
+        .value = njs_native_function(njs_date_prototype_get_utc_date, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2176,7 +2178,8 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getDay"),
-        .value = njs_native_function(njs_date_prototype_get_day, NJS_DATE_ARG),
+        .value = njs_native_function(njs_date_prototype_get_day, 0,
+                                     NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
     },
@@ -2184,7 +2187,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getUTCDay"),
-        .value = njs_native_function(njs_date_prototype_get_utc_day,
+        .value = njs_native_function(njs_date_prototype_get_utc_day, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2193,7 +2196,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getHours"),
-        .value = njs_native_function(njs_date_prototype_get_hours,
+        .value = njs_native_function(njs_date_prototype_get_hours, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2202,7 +2205,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getUTCHours"),
-        .value = njs_native_function(njs_date_prototype_get_utc_hours,
+        .value = njs_native_function(njs_date_prototype_get_utc_hours, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2211,7 +2214,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getMinutes"),
-        .value = njs_native_function(njs_date_prototype_get_minutes,
+        .value = njs_native_function(njs_date_prototype_get_minutes, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2220,7 +2223,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getUTCMinutes"),
-        .value = njs_native_function(njs_date_prototype_get_utc_minutes,
+        .value = njs_native_function(njs_date_prototype_get_utc_minutes, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2229,7 +2232,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getSeconds"),
-        .value = njs_native_function(njs_date_prototype_get_seconds,
+        .value = njs_native_function(njs_date_prototype_get_seconds, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2238,7 +2241,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("getUTCSeconds"),
-        .value = njs_native_function(njs_date_prototype_get_seconds,
+        .value = njs_native_function(njs_date_prototype_get_seconds, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2247,7 +2250,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_long_string("getMilliseconds"),
-        .value = njs_native_function(njs_date_prototype_get_milliseconds,
+        .value = njs_native_function(njs_date_prototype_get_milliseconds, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2256,7 +2259,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_long_string("getUTCMilliseconds"),
-        .value = njs_native_function(njs_date_prototype_get_milliseconds,
+        .value = njs_native_function(njs_date_prototype_get_milliseconds, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2265,7 +2268,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_long_string("getTimezoneOffset"),
-        .value = njs_native_function(njs_date_prototype_get_timezone_offset,
+        .value = njs_native_function(njs_date_prototype_get_timezone_offset, 0,
                                      NJS_DATE_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2274,7 +2277,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setTime"),
-        .value = njs_native_function(njs_date_prototype_set_time,
+        .value = njs_native_function(njs_date_prototype_set_time, 1,
                                      NJS_DATE_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2283,7 +2286,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_long_string("setMilliseconds"),
-        .value = njs_native_function(njs_date_prototype_set_milliseconds,
+        .value = njs_native_function(njs_date_prototype_set_milliseconds, 1,
                                      NJS_DATE_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2292,7 +2295,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_long_string("setUTCMilliseconds"),
-        .value = njs_native_function(njs_date_prototype_set_milliseconds,
+        .value = njs_native_function(njs_date_prototype_set_milliseconds, 1,
                                      NJS_DATE_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2301,7 +2304,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setSeconds"),
-        .value = njs_native_function(njs_date_prototype_set_seconds,
+        .value = njs_native_function(njs_date_prototype_set_seconds, 2,
                                      NJS_DATE_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2310,7 +2313,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setUTCSeconds"),
-        .value = njs_native_function(njs_date_prototype_set_seconds,
+        .value = njs_native_function(njs_date_prototype_set_seconds, 2,
                      NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2319,7 +2322,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setMinutes"),
-        .value = njs_native_function(njs_date_prototype_set_minutes,
+        .value = njs_native_function(njs_date_prototype_set_minutes, 3,
                      NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
                      NJS_NUMBER_ARG),
         .writable = 1,
@@ -2329,7 +2332,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setUTCMinutes"),
-        .value = njs_native_function(njs_date_prototype_set_utc_minutes,
+        .value = njs_native_function(njs_date_prototype_set_utc_minutes, 3,
                      NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
                      NJS_NUMBER_ARG),
         .writable = 1,
@@ -2339,7 +2342,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setHours"),
-        .value = njs_native_function(njs_date_prototype_set_hours,
+        .value = njs_native_function(njs_date_prototype_set_hours, 4,
                      NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
                      NJS_NUMBER_ARG, NJS_NUMBER_ARG),
         .writable = 1,
@@ -2349,7 +2352,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setUTCHours"),
-        .value = njs_native_function(njs_date_prototype_set_utc_hours,
+        .value = njs_native_function(njs_date_prototype_set_utc_hours, 4,
                      NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
                      NJS_NUMBER_ARG, NJS_NUMBER_ARG),
         .writable = 1,
@@ -2359,7 +2362,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setDate"),
-        .value = njs_native_function(njs_date_prototype_set_date,
+        .value = njs_native_function(njs_date_prototype_set_date, 1,
                      NJS_DATE_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2368,7 +2371,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setUTCDate"),
-        .value = njs_native_function(njs_date_prototype_set_utc_date,
+        .value = njs_native_function(njs_date_prototype_set_utc_date, 1,
                      NJS_DATE_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2377,7 +2380,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setMonth"),
-        .value = njs_native_function(njs_date_prototype_set_month,
+        .value = njs_native_function(njs_date_prototype_set_month, 2,
                      NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2386,7 +2389,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setUTCMonth"),
-        .value = njs_native_function(njs_date_prototype_set_utc_month,
+        .value = njs_native_function(njs_date_prototype_set_utc_month, 2,
                      NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -2395,7 +2398,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setFullYear"),
-        .value = njs_native_function(njs_date_prototype_set_full_year,
+        .value = njs_native_function(njs_date_prototype_set_full_year, 3,
                      NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
                      NJS_NUMBER_ARG),
         .writable = 1,
@@ -2405,7 +2408,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("setUTCFullYear"),
-        .value = njs_native_function(njs_date_prototype_set_utc_full_year,
+        .value = njs_native_function(njs_date_prototype_set_utc_full_year, 3,
                      NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
                      NJS_NUMBER_ARG),
         .writable = 1,
@@ -2415,7 +2418,7 @@ static const njs_object_prop_t  njs_date
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toJSON"),
-        .value = njs_native_function(njs_date_prototype_to_json, 0),
+        .value = njs_native_function(njs_date_prototype_to_json, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
diff -r b4cd260f7b69 -r 30c1bde3f194 src/njs_error.c
--- a/src/njs_error.c	Fri Oct 11 17:08:28 2019 +0300
+++ b/src/njs_error.c	Fri Oct 11 19:41:51 2019 +0300
@@ -734,7 +734,7 @@ static const njs_object_prop_t  njs_erro
     {
         .type = NJS_PROPERTY,
         .name = njs_string("valueOf"),
-        .value = njs_native_function(njs_error_prototype_value_of, 0),
+        .value = njs_native_function(njs_error_prototype_value_of, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -742,7 +742,7 @@ static const njs_object_prop_t  njs_erro
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toString"),
-        .value = njs_native_function(njs_error_prototype_to_string, 0),
+        .value = njs_native_function(njs_error_prototype_to_string, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -816,7 +816,8 @@ static const njs_object_prop_t  njs_inte
     {
         .type = NJS_PROPERTY,
         .name = njs_string("toString"),
-        .value = njs_native_function(njs_internal_error_prototype_to_string, 0),
+        .value = njs_native_function(njs_internal_error_prototype_to_string,
+                                     0, 0),
         .writable = 1,
         .configurable = 1,
     },
diff -r b4cd260f7b69 -r 30c1bde3f194 src/njs_fs.c
--- a/src/njs_fs.c	Fri Oct 11 17:08:28 2019 +0300
+++ b/src/njs_fs.c	Fri Oct 11 19:41:51 2019 +0300
@@ -1140,7 +1140,7 @@ static const njs_object_prop_t  njs_fs_o
     {
         .type = NJS_PROPERTY,
         .name = njs_string("readFile"),
-        .value = njs_native_function(njs_fs_read_file, 0),
+        .value = njs_native_function(njs_fs_read_file, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -1148,7 +1148,7 @@ static const njs_object_prop_t  njs_fs_o
     {
         .type = NJS_PROPERTY,
         .name = njs_string("readFileSync"),
-        .value = njs_native_function(njs_fs_read_file_sync, 0),
+        .value = njs_native_function(njs_fs_read_file_sync, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -1156,7 +1156,7 @@ static const njs_object_prop_t  njs_fs_o
     {
         .type = NJS_PROPERTY,
         .name = njs_string("appendFile"),
-        .value = njs_native_function(njs_fs_append_file, 0),
+        .value = njs_native_function(njs_fs_append_file, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -1164,7 +1164,7 @@ static const njs_object_prop_t  njs_fs_o
     {
         .type = NJS_PROPERTY,
         .name = njs_string("appendFileSync"),
-        .value = njs_native_function(njs_fs_append_file_sync, 0),
+        .value = njs_native_function(njs_fs_append_file_sync, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -1172,7 +1172,7 @@ static const njs_object_prop_t  njs_fs_o
     {
         .type = NJS_PROPERTY,
         .name = njs_string("writeFile"),
-        .value = njs_native_function(njs_fs_write_file, 0),
+        .value = njs_native_function(njs_fs_write_file, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -1180,7 +1180,7 @@ static const njs_object_prop_t  njs_fs_o
     {
         .type = NJS_PROPERTY,
         .name = njs_string("writeFileSync"),
-        .value = njs_native_function(njs_fs_write_file_sync, 0),
+        .value = njs_native_function(njs_fs_write_file_sync, 0, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -1188,7 +1188,7 @@ static const njs_object_prop_t  njs_fs_o
     {
         .type = NJS_PROPERTY,
         .name = njs_string("renameSync"),
-        .value = njs_native_function(njs_fs_rename_sync, NJS_STRING_ARG,
+        .value = njs_native_function(njs_fs_rename_sync, 0, NJS_STRING_ARG,
                                      NJS_STRING_ARG, 0),
         .writable = 1,
         .configurable = 1,
diff -r b4cd260f7b69 -r 30c1bde3f194 src/njs_function.c
--- a/src/njs_function.c	Fri Oct 11 17:08:28 2019 +0300
+++ b/src/njs_function.c	Fri Oct 11 19:41:51 2019 +0300
@@ -1032,10 +1032,8 @@ static njs_int_t
 njs_function_instance_length(njs_vm_t *vm, njs_value_t *value,
     njs_value_t *setval, njs_value_t *retval)
 {
-    njs_uint_t             n;
-    njs_object_t           *proto;
-    njs_function_t         *function;
-    njs_function_lambda_t  *lambda;
+    njs_object_t    *proto;
+    njs_function_t  *function;
 
     proto = njs_object(value);
 
@@ -1054,26 +1052,7 @@ njs_function_instance_length(njs_vm_t *v
 
     function = (njs_function_t *) proto;
 
-    if (function->native) {
-        for (n = function->args_offset; n < NJS_ARGS_TYPES_MAX; n++) {
-            if (function->args_types[n] == 0) {
-                break;
-            }
-        }
-
-    } else {
-        lambda = function->u.lambda;
-        n = lambda->nargs + 1 - lambda->rest_parameters;
-    }
-
-    if (n >= function->args_offset) {
-        n -= function->args_offset;
-
-    } else {
-        n = 0;
-    }
-
-    njs_set_number(retval, n);
+    njs_set_number(retval, function->args_count);
 
     return NJS_OK;
 }
@@ -1224,6 +1203,13 @@ njs_function_prototype_bind(njs_vm_t *vm
         args++;
     }
 
+    if (nargs > function->args_count) {
+        function->args_count = 0;
+
+    } else {
+        function->args_count -= nargs - 1;
+    }
+
     function->args_offset = nargs;
     size = nargs * sizeof(njs_value_t);
 
@@ -1273,7 +1259,7 @@ static const njs_object_prop_t  njs_func
     {
         .type = NJS_PROPERTY,
         .name = njs_string("call"),
-        .value = njs_native_function(njs_function_prototype_call, 0),
+        .value = njs_native_function(njs_function_prototype_call, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -1281,7 +1267,7 @@ static const njs_object_prop_t  njs_func
     {
         .type = NJS_PROPERTY,
         .name = njs_string("apply"),
-        .value = njs_native_function(njs_function_prototype_apply, 0),
+        .value = njs_native_function(njs_function_prototype_apply, 2, 0),
         .writable = 1,
         .configurable = 1,
     },
@@ -1289,7 +1275,7 @@ static const njs_object_prop_t  njs_func
     {
         .type = NJS_PROPERTY,
         .name = njs_string("bind"),
-        .value = njs_native_function(njs_function_prototype_bind, 0),
+        .value = njs_native_function(njs_function_prototype_bind, 1, 0),
         .writable = 1,
         .configurable = 1,
     },
diff -r b4cd260f7b69 -r 30c1bde3f194 src/njs_json.c
--- a/src/njs_json.c	Fri Oct 11 17:08:28 2019 +0300
+++ b/src/njs_json.c	Fri Oct 11 19:41:51 2019 +0300
@@ -2101,7 +2101,7 @@ static const njs_object_prop_t  njs_json
     {
         .type = NJS_PROPERTY,
         .name = njs_string("parse"),
-        .value = njs_native_function(njs_json_parse,
+        .value = njs_native_function(njs_json_parse, 2,
                                      NJS_SKIP_ARG, NJS_STRING_ARG,
                                      NJS_OBJECT_ARG),
         .writable = 1,
@@ -2112,7 +2112,7 @@ static const njs_object_prop_t  njs_json
     {
         .type = NJS_PROPERTY,
         .name = njs_string("stringify"),
-        .value = njs_native_function(njs_json_stringify,
+        .value = njs_native_function(njs_json_stringify, 3,
                                      NJS_SKIP_ARG, NJS_SKIP_ARG, NJS_SKIP_ARG,
                                      NJS_SKIP_ARG),
         .writable = 1,
diff -r b4cd260f7b69 -r 30c1bde3f194 src/njs_math.c
--- a/src/njs_math.c	Fri Oct 11 17:08:28 2019 +0300
+++ b/src/njs_math.c	Fri Oct 11 19:41:51 2019 +0300
@@ -833,7 +833,7 @@ static const njs_object_prop_t  njs_math
     {
         .type = NJS_PROPERTY,
         .name = njs_string("abs"),
-        .value = njs_native_function(njs_object_math_abs,
+        .value = njs_native_function(njs_object_math_abs, 1,
                                      NJS_SKIP_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -842,7 +842,7 @@ static const njs_object_prop_t  njs_math
     {
         .type = NJS_PROPERTY,
         .name = njs_string("acos"),
-        .value = njs_native_function(njs_object_math_acos,
+        .value = njs_native_function(njs_object_math_acos, 1,
                                      NJS_SKIP_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -852,7 +852,7 @@ static const njs_object_prop_t  njs_math
     {
         .type = NJS_PROPERTY,
         .name = njs_string("acosh"),
-        .value = njs_native_function(njs_object_math_acosh,
+        .value = njs_native_function(njs_object_math_acosh, 1,
                                      NJS_SKIP_ARG, NJS_NUMBER_ARG),
         .writable = 1,
         .configurable = 1,
@@ -861,7 +861,7 @@ static const njs_object_prop_t  njs_math
     {


More information about the nginx-devel mailing list