[njs] Fixed return value type for boolean functions.

Dmitry Volyntsev xeioex at nginx.com
Thu Apr 26 16:11:38 UTC 2018


details:   http://hg.nginx.org/njs/rev/e7878051e75d
branches:  
changeset: 505:e7878051e75d
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Apr 26 19:11:29 2018 +0300
description:
Fixed return value type for boolean functions.

Previously, the functions returned "true" and "false" strings.

diffstat:

 njs/njs_array.c          |   4 ++--
 njs/njs_object.c         |  34 +++++++++++++++++-----------------
 njs/test/njs_unit_test.c |   6 ++++++
 3 files changed, 25 insertions(+), 19 deletions(-)

diffs (172 lines):

diff -r 7e4b13d45b30 -r e7878051e75d njs/njs_array.c
--- a/njs/njs_array.c	Thu Apr 26 19:11:28 2018 +0300
+++ b/njs/njs_array.c	Thu Apr 26 19:11:29 2018 +0300
@@ -295,10 +295,10 @@ njs_array_is_array(njs_vm_t *vm, njs_val
     const njs_value_t  *value;
 
     if (nargs > 1 && njs_is_array(&args[1])) {
-        value = &njs_string_true;
+        value = &njs_value_true;
 
     } else {
-        value = &njs_string_false;
+        value = &njs_value_false;
     }
 
     vm->retval = *value;
diff -r 7e4b13d45b30 -r e7878051e75d njs/njs_object.c
--- a/njs/njs_object.c	Thu Apr 26 19:11:28 2018 +0300
+++ b/njs/njs_object.c	Thu Apr 26 19:11:29 2018 +0300
@@ -695,7 +695,7 @@ njs_object_get_own_property_descriptor(n
     lhq.key = nxt_string_value("configurable");
     lhq.key_hash = NJS_CONFIGURABLE_HASH;
 
-    setval = (prop->configurable == 1) ? &njs_string_true : &njs_string_false;
+    setval = (prop->configurable == 1) ? &njs_value_true : &njs_value_false;
 
     pr = njs_object_prop_alloc(vm, &njs_object_configurable_string, setval, 1);
     if (nxt_slow_path(pr == NULL)) {
@@ -712,7 +712,7 @@ njs_object_get_own_property_descriptor(n
     lhq.key = nxt_string_value("enumerable");
     lhq.key_hash = NJS_ENUMERABLE_HASH;
 
-    setval = (prop->enumerable == 1) ? &njs_string_true : &njs_string_false;
+    setval = (prop->enumerable == 1) ? &njs_value_true : &njs_value_false;
 
     pr = njs_object_prop_alloc(vm, &njs_object_enumerable_string, setval, 1);
     if (nxt_slow_path(pr == NULL)) {
@@ -729,7 +729,7 @@ njs_object_get_own_property_descriptor(n
     lhq.key = nxt_string_value("writable");
     lhq.key_hash = NJS_WRITABABLE_HASH;
 
-    setval = (prop->writable == 1) ? &njs_string_true : &njs_string_false;
+    setval = (prop->writable == 1) ? &njs_value_true : &njs_value_false;
 
     pr = njs_object_prop_alloc(vm, &njs_object_writable_string, setval, 1);
     if (nxt_slow_path(pr == NULL)) {
@@ -826,11 +826,11 @@ njs_object_is_frozen(njs_vm_t *vm, njs_v
     value = njs_arg(args, nargs, 1);
 
     if (!njs_is_object(value)) {
-        vm->retval = njs_string_true;
+        vm->retval = njs_value_true;
         return NXT_OK;
     }
 
-    retval = &njs_string_false;
+    retval = &njs_value_false;
 
     object = value->data.u.object;
     nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto);
@@ -853,7 +853,7 @@ njs_object_is_frozen(njs_vm_t *vm, njs_v
         }
     }
 
-    retval = &njs_string_true;
+    retval = &njs_value_true;
 
 done:
 
@@ -916,11 +916,11 @@ njs_object_is_sealed(njs_vm_t *vm, njs_v
     value = njs_arg(args, nargs, 1);
 
     if (!njs_is_object(value)) {
-        vm->retval = njs_string_true;
+        vm->retval = njs_value_true;
         return NXT_OK;
     }
 
-    retval = &njs_string_false;
+    retval = &njs_value_false;
 
     object = value->data.u.object;
     nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto);
@@ -943,7 +943,7 @@ njs_object_is_sealed(njs_vm_t *vm, njs_v
         }
     }
 
-    retval = &njs_string_true;
+    retval = &njs_value_true;
 
 done:
 
@@ -983,12 +983,12 @@ njs_object_is_extensible(njs_vm_t *vm, n
     value = njs_arg(args, nargs, 1);
 
     if (!njs_is_object(value)) {
-        vm->retval = njs_string_false;
+        vm->retval = njs_value_false;
         return NXT_OK;
     }
 
-    retval = value->data.u.object->extensible ? &njs_string_true
-                                              : &njs_string_false;
+    retval = value->data.u.object->extensible ? &njs_value_true
+                                              : &njs_value_false;
 
     vm->retval = *retval;
 
@@ -1490,7 +1490,7 @@ njs_object_prototype_has_own_property(nj
     const njs_value_t   *value, *prop, *retval;
     nxt_lvlhsh_query_t  lhq;
 
-    retval = &njs_string_false;
+    retval = &njs_value_false;
     value = &args[0];
 
     if (njs_is_object(value)) {
@@ -1502,7 +1502,7 @@ njs_object_prototype_has_own_property(nj
             index = njs_string_to_index(prop);
 
             if (index < array->length && njs_is_valid(&array->start[index])) {
-                retval = &njs_string_true;
+                retval = &njs_value_true;
                 goto done;
             }
         }
@@ -1514,7 +1514,7 @@ njs_object_prototype_has_own_property(nj
         ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq);
 
         if (ret == NXT_OK) {
-            retval = &njs_string_true;
+            retval = &njs_value_true;
         }
     }
 
@@ -1533,7 +1533,7 @@ njs_object_prototype_is_prototype_of(njs
     njs_object_t       *object, *proto;
     const njs_value_t  *value, *obj, *retval;
 
-    retval = &njs_string_false;
+    retval = &njs_value_false;
     value = &args[0];
     obj = njs_arg(args, nargs, 1);
 
@@ -1545,7 +1545,7 @@ njs_object_prototype_is_prototype_of(njs
             object = object->__proto__;
 
             if (object == proto) {
-                retval = &njs_string_true;
+                retval = &njs_value_true;
                 break;
             }
 
diff -r 7e4b13d45b30 -r e7878051e75d njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Thu Apr 26 19:11:28 2018 +0300
+++ b/njs/test/njs_unit_test.c	Thu Apr 26 19:11:29 2018 +0300
@@ -2852,9 +2852,15 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("Array.isArray(1)"),
       nxt_string("false") },
 
+    { nxt_string("Array.isArray(1) ? 'true' : 'false'"),
+      nxt_string("false") },
+
     { nxt_string("Array.isArray([])"),
       nxt_string("true") },
 
+    { nxt_string("Array.isArray([]) ? 'true' : 'false'"),
+      nxt_string("true") },
+
     { nxt_string("Array.of()"),
       nxt_string("") },
 


More information about the nginx-devel mailing list