[njs] Improved working with arguments in Regexp.prototype methods.

Dmitry Volyntsev xeioex at nginx.com
Thu Apr 18 15:15:04 UTC 2019


details:   https://hg.nginx.org/njs/rev/e4ba35c2844b
branches:  
changeset: 902:e4ba35c2844b
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Apr 18 15:44:37 2019 +0300
description:
Improved working with arguments in Regexp.prototype methods.

diffstat:

 njs/njs_regexp.c |  21 ++++++++-------------
 1 files changed, 8 insertions(+), 13 deletions(-)

diffs (54 lines):

diff -r 108ef0cd302d -r e4ba35c2844b njs/njs_regexp.c
--- a/njs/njs_regexp.c	Thu Apr 18 15:05:27 2019 +0300
+++ b/njs/njs_regexp.c	Thu Apr 18 15:44:37 2019 +0300
@@ -552,7 +552,7 @@ static njs_ret_t
 njs_regexp_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
     nxt_uint_t nargs, njs_index_t unused)
 {
-    if (njs_is_regexp(&args[0])) {
+    if (njs_is_regexp(njs_arg(args, nargs, 0))) {
         return njs_regexp_to_string(vm, &vm->retval, &args[0]);
     }
 
@@ -587,23 +587,20 @@ njs_regexp_prototype_test(njs_vm_t *vm, 
 {
     njs_ret_t             ret;
     nxt_uint_t            n;
-    njs_value_t           *value;
-    const njs_value_t     *retval;
+    const njs_value_t     *value, *retval;
     njs_string_prop_t     string;
     njs_regexp_pattern_t  *pattern;
 
-    if (!njs_is_regexp(&args[0])) {
+    if (!njs_is_regexp(njs_arg(args, nargs, 0))) {
         njs_type_error(vm, "\"this\" argument is not a regexp");
         return NXT_ERROR;
     }
 
     retval = &njs_value_false;
 
-    if (nargs > 1) {
-        value = &args[1];
-
-    } else {
-        value = (njs_value_t *) &njs_string_undefined;
+    value = njs_arg(args, nargs, 1);
+    if (njs_is_undefined(value)) {
+        value = &njs_string_undefined;
     }
 
     (void) njs_string_prop(&string, value);
@@ -647,10 +644,8 @@ njs_regexp_prototype_exec(njs_vm_t *vm, 
         return NXT_ERROR;
     }
 
-    if (nargs > 1) {
-        value = &args[1];
-
-    } else {
+    value = njs_arg(args, nargs, 1);
+    if (njs_is_undefined(value)) {
         value = &njs_string_undefined;
     }
 


More information about the nginx-devel mailing list