[njs] Improved access to this argument.

Dmitry Volyntsev xeioex at nginx.com
Wed Jan 19 13:12:52 UTC 2022


details:   https://hg.nginx.org/njs/rev/79b109076c13
branches:  
changeset: 1811:79b109076c13
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Jan 18 15:37:11 2022 +0000
description:
Improved access to this argument.

'this' argument is always present, so it may be accessed
without checking the number provided arguments.

diffstat:

 external/njs_query_string_module.c |   4 ++--
 src/njs_array_buffer.c             |   4 ++--
 src/njs_function.c                 |   2 +-
 src/njs_object.c                   |   6 +++---
 src/njs_promise.c                  |  12 ++++++------
 src/njs_string.c                   |  32 ++++++++++++++++----------------
 6 files changed, 30 insertions(+), 30 deletions(-)

diffs (288 lines):

diff -r 30865ae17149 -r 79b109076c13 external/njs_query_string_module.c
--- a/external/njs_query_string_module.c	Tue Jan 18 08:37:09 2022 +0100
+++ b/external/njs_query_string_module.c	Tue Jan 18 15:37:11 2022 +0000
@@ -391,7 +391,7 @@ njs_query_string_parse(njs_vm_t *vm, njs
 
     njs_set_object(&obj, object);
 
-    this = njs_arg(args, nargs, 0);
+    this = njs_argument(args, 0);
     string = njs_arg(args, nargs, 1);
 
     if (njs_slow_path(!njs_is_string(string)
@@ -703,7 +703,7 @@ njs_query_string_stringify(njs_vm_t *vm,
     (void) njs_string_prop(&eq, &val_eq);
 
     encode = NULL;
-    this = njs_arg(args, nargs, 0);
+    this = njs_argument(args, 0);
     object = njs_arg(args, nargs, 1);
 
     if (njs_slow_path(!njs_is_object(object))) {
diff -r 30865ae17149 -r 79b109076c13 src/njs_array_buffer.c
--- a/src/njs_array_buffer.c	Tue Jan 18 08:37:09 2022 +0100
+++ b/src/njs_array_buffer.c	Tue Jan 18 15:37:11 2022 +0000
@@ -195,7 +195,7 @@ njs_array_buffer_prototype_byte_length(n
     njs_value_t         *value;
     njs_array_buffer_t  *array;
 
-    value = njs_arg(args, nargs, 0);
+    value = njs_argument(args, 0);
 
     if (!njs_is_array_buffer(value)) {
         njs_type_error(vm, "Method ArrayBuffer.prototype.byteLength called "
@@ -224,7 +224,7 @@ njs_array_buffer_prototype_slice(njs_vm_
     njs_value_t         *value;
     njs_array_buffer_t  *this, *buffer;
 
-    value = njs_arg(args, nargs, 0);
+    value = njs_argument(args, 0);
 
     if (!njs_is_array_buffer(value)) {
         njs_type_error(vm, "Method ArrayBuffer.prototype.slice called "
diff -r 30865ae17149 -r 79b109076c13 src/njs_function.c
--- a/src/njs_function.c	Tue Jan 18 08:37:09 2022 +0100
+++ b/src/njs_function.c	Tue Jan 18 15:37:11 2022 +0000
@@ -1374,7 +1374,7 @@ njs_function_prototype_apply(njs_vm_t *v
     njs_array_t     *arr;
     njs_function_t  *func;
 
-    if (!njs_is_function(njs_arg(args, nargs, 0))) {
+    if (!njs_is_function(njs_argument(args, 0))) {
         njs_type_error(vm, "\"this\" argument is not a function");
         return NJS_ERROR;
     }
diff -r 30865ae17149 -r 79b109076c13 src/njs_object.c
--- a/src/njs_object.c	Tue Jan 18 08:37:09 2022 +0100
+++ b/src/njs_object.c	Tue Jan 18 15:37:11 2022 +0000
@@ -2437,7 +2437,7 @@ njs_object_prototype_has_own_property(nj
     njs_value_t           *value, *property;
     njs_property_query_t  pq;
 
-    value = njs_arg(args, nargs, 0);
+    value = njs_argument(args, 0);
 
     if (njs_is_null_or_undefined(value)) {
         njs_type_error(vm, "cannot convert %s argument to object",
@@ -2477,7 +2477,7 @@ njs_object_prototype_prop_is_enumerable(
     njs_object_prop_t     *prop;
     njs_property_query_t  pq;
 
-    value = njs_arg(args, nargs, 0);
+    value = njs_argument(args, 0);
 
     if (njs_is_null_or_undefined(value)) {
         njs_type_error(vm, "cannot convert %s argument to object",
@@ -2520,7 +2520,7 @@ njs_object_prototype_is_prototype_of(njs
     njs_object_t       *object, *proto;
     const njs_value_t  *retval;
 
-    if (njs_slow_path(njs_is_null_or_undefined(njs_arg(args, nargs, 0)))) {
+    if (njs_slow_path(njs_is_null_or_undefined(njs_argument(args, 0)))) {
         njs_type_error(vm, "cannot convert undefined to object");
         return NJS_ERROR;
     }
diff -r 30865ae17149 -r 79b109076c13 src/njs_promise.c
--- a/src/njs_promise.c	Tue Jan 18 08:37:09 2022 +0100
+++ b/src/njs_promise.c	Tue Jan 18 15:37:11 2022 +0000
@@ -749,7 +749,7 @@ njs_promise_object_resolve(njs_vm_t *vm,
 {
     njs_promise_t  *promise;
 
-    if (njs_slow_path(!njs_is_object(njs_arg(args, nargs, 0)))) {
+    if (njs_slow_path(!njs_is_object(njs_argument(args, 0)))) {
         njs_type_error(vm, "this value is not an object");
         return NJS_ERROR;
     }
@@ -846,7 +846,7 @@ njs_promise_object_reject(njs_vm_t *vm, 
     njs_value_t               value;
     njs_promise_capability_t  *capability;
 
-    if (njs_slow_path(!njs_is_object(njs_arg(args, nargs, 0)))) {
+    if (njs_slow_path(!njs_is_object(njs_argument(args, 0)))) {
         njs_type_error(vm, "this value is not an object");
         return NJS_ERROR;
     }
@@ -879,7 +879,7 @@ njs_promise_prototype_then(njs_vm_t *vm,
     njs_function_t            *function;
     njs_promise_capability_t  *capability;
 
-    promise = njs_arg(args, nargs, 0);
+    promise = njs_argument(args, 0);
 
     if (njs_slow_path(!njs_is_object(promise))) {
         goto failed;
@@ -1018,7 +1018,7 @@ njs_promise_prototype_catch(njs_vm_t *vm
     arguments[0] = njs_value_undefined;
     arguments[1] = *njs_arg(args, nargs, 1);
 
-    return njs_promise_invoke_then(vm, njs_arg(args, nargs, 0), arguments, 2);
+    return njs_promise_invoke_then(vm, njs_argument(args,  0), arguments, 2);
 }
 
 
@@ -1031,7 +1031,7 @@ njs_promise_prototype_finally(njs_vm_t *
     njs_function_t         *function;
     njs_promise_context_t  *context;
 
-    promise = njs_arg(args, nargs, 0);
+    promise = njs_argument(args, 0);
 
     if (njs_slow_path(!njs_is_object(promise))) {
         njs_type_error(vm, "required a object");
@@ -1779,7 +1779,7 @@ static njs_int_t
 njs_promise_species(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
-    njs_vm_retval_set(vm, njs_arg(args, nargs, 0));
+    njs_vm_retval_set(vm, njs_argument(args, 0));
 
     return NJS_OK;
 }
diff -r 30865ae17149 -r 79b109076c13 src/njs_string.c
--- a/src/njs_string.c	Tue Jan 18 08:37:09 2022 +0100
+++ b/src/njs_string.c	Tue Jan 18 15:37:11 2022 +0000
@@ -986,7 +986,7 @@ njs_string_prototype_from_utf8(njs_vm_t 
     njs_slice_prop_t   slice;
     njs_string_prop_t  string;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -1029,7 +1029,7 @@ njs_string_prototype_to_utf8(njs_vm_t *v
     njs_slice_prop_t   slice;
     njs_string_prop_t  string;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -1063,7 +1063,7 @@ njs_string_prototype_from_bytes(njs_vm_t
     njs_slice_prop_t   slice;
     njs_string_prop_t  string;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -1129,7 +1129,7 @@ njs_string_prototype_to_bytes(njs_vm_t *
     njs_string_prop_t     string;
     njs_unicode_decode_t  ctx;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -1192,7 +1192,7 @@ njs_string_prototype_slice(njs_vm_t *vm,
     njs_slice_prop_t   slice;
     njs_string_prop_t  string;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -1216,7 +1216,7 @@ njs_string_prototype_substring(njs_vm_t 
     njs_slice_prop_t   slice;
     njs_string_prop_t  string;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -1294,7 +1294,7 @@ njs_string_prototype_substr(njs_vm_t *vm
     njs_slice_prop_t   slice;
     njs_string_prop_t  string;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -1372,7 +1372,7 @@ njs_string_prototype_char_at(njs_vm_t *v
     njs_slice_prop_t   slice;
     njs_string_prop_t  string;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -1566,7 +1566,7 @@ njs_string_prototype_char_code_at(njs_vm
     njs_string_prop_t     string;
     njs_unicode_decode_t  ctx;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -2332,7 +2332,7 @@ njs_string_prototype_includes(njs_vm_t *
     const njs_value_t  *retval;
     njs_string_prop_t  string, search;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -2425,7 +2425,7 @@ njs_string_prototype_starts_or_ends_with
 
     retval = &njs_value_true;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -2635,7 +2635,7 @@ njs_string_prototype_to_lower_case(njs_v
     const u_char       *s, *end;
     njs_string_prop_t  string;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -2707,7 +2707,7 @@ njs_string_prototype_to_upper_case(njs_v
     const u_char       *s, *end;
     njs_string_prop_t  string;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -2973,7 +2973,7 @@ njs_string_prototype_pad(njs_vm_t *vm, n
 
     static const njs_value_t  string_space = njs_string(" ");
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -3093,7 +3093,7 @@ njs_string_prototype_search(njs_vm_t *vm
     njs_string_prop_t     string;
     njs_regexp_pattern_t  *pattern;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }
@@ -3171,7 +3171,7 @@ njs_string_prototype_match(njs_vm_t *vm,
     njs_value_t           arguments[2];
     njs_regexp_pattern_t  *pattern;
 
-    ret = njs_string_object_validate(vm, njs_arg(args, nargs, 0));
+    ret = njs_string_object_validate(vm, njs_argument(args, 0));
     if (njs_slow_path(ret != NJS_OK)) {
         return ret;
     }



More information about the nginx-devel mailing list