[njs] Cleanup of njs_property_query() usage.

Dmitry Volyntsev xeioex at nginx.com
Tue Aug 6 14:59:10 UTC 2019


details:   https://hg.nginx.org/njs/rev/9dab7c4514e3
branches:  
changeset: 1109:9dab7c4514e3
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Aug 06 17:58:37 2019 +0300
description:
Cleanup of njs_property_query() usage.

diffstat:

 src/njs_object_prop.c |   6 +-----
 src/njs_value.c       |  14 +++++++-------
 src/njs_value.h       |   2 +-
 3 files changed, 9 insertions(+), 13 deletions(-)

diffs (82 lines):

diff -r dda649936723 -r 9dab7c4514e3 src/njs_object_prop.c
--- a/src/njs_object_prop.c	Mon Aug 05 21:17:27 2019 +0300
+++ b/src/njs_object_prop.c	Tue Aug 06 17:58:37 2019 +0300
@@ -87,15 +87,11 @@ njs_object_prop_define(njs_vm_t *vm, njs
     njs_object_prop_t     *prop, *prev;
     njs_property_query_t  pq;
 
-    njs_string_get(name, &pq.lhq.key);
-    pq.lhq.key_hash = njs_djb_hash(pq.lhq.key.start, pq.lhq.key.length);
-    pq.lhq.proto = &njs_object_hash_proto;
-
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_SET, 1);
 
     ret = njs_property_query(vm, &pq, object, name);
 
-    if (ret != NJS_OK && ret != NJS_DECLINED) {
+    if (njs_slow_path(ret == NJS_ERROR)) {
         return ret;
     }
 
diff -r dda649936723 -r 9dab7c4514e3 src/njs_value.c
--- a/src/njs_value.c	Mon Aug 05 21:17:27 2019 +0300
+++ b/src/njs_value.c	Tue Aug 06 17:58:37 2019 +0300
@@ -560,10 +560,10 @@ njs_property_query(njs_vm_t *vm, njs_pro
     case NJS_UNDEFINED:
     case NJS_NULL:
     default:
-        ret = njs_primitive_value_to_string(vm, &pq->value, key);
+        ret = njs_primitive_value_to_string(vm, &pq->key, key);
 
         if (njs_fast_path(ret == NJS_OK)) {
-            njs_string_get(&pq->value, &pq->lhq.key);
+            njs_string_get(&pq->key, &pq->lhq.key);
             njs_type_error(vm, "cannot get property \"%V\" of undefined",
                            &pq->lhq.key);
             return NJS_ERROR;
@@ -574,11 +574,11 @@ njs_property_query(njs_vm_t *vm, njs_pro
         return NJS_ERROR;
     }
 
-    ret = njs_primitive_value_to_string(vm, &pq->value, key);
+    ret = njs_primitive_value_to_string(vm, &pq->key, key);
 
     if (njs_fast_path(ret == NJS_OK)) {
 
-        njs_string_get(&pq->value, &pq->lhq.key);
+        njs_string_get(&pq->key, &pq->lhq.key);
         pq->lhq.key_hash = njs_djb_hash(pq->lhq.key.start, pq->lhq.key.length);
 
         if (obj == NULL) {
@@ -765,8 +765,8 @@ njs_string_property_query(njs_vm_t *vm, 
 
         if (pq->query != NJS_PROPERTY_QUERY_GET) {
             /* pq->lhq.key is used by NJS_VMCODE_PROPERTY_SET for TypeError */
-            njs_uint32_to_string(&pq->value, index);
-            njs_string_get(&pq->value, &pq->lhq.key);
+            njs_uint32_to_string(&pq->key, index);
+            njs_string_get(&pq->key, &pq->lhq.key);
         }
 
         return NJS_OK;
@@ -1103,7 +1103,7 @@ njs_value_property_set(njs_vm_t *vm, njs
         return NJS_ERROR;
     }
 
-    prop = njs_object_prop_alloc(vm, &pq.value, &njs_value_undefined, 1);
+    prop = njs_object_prop_alloc(vm, &pq.key, &njs_value_undefined, 1);
     if (njs_slow_path(prop == NULL)) {
         return NJS_ERROR;
     }
diff -r dda649936723 -r 9dab7c4514e3 src/njs_value.h
--- a/src/njs_value.h	Mon Aug 05 21:17:27 2019 +0300
+++ b/src/njs_value.h	Tue Aug 06 17:58:37 2019 +0300
@@ -348,7 +348,7 @@ typedef struct {
     const njs_extern_t          *ext_proto;
     uint32_t                    ext_index;
 
-    njs_value_t                 value;
+    njs_value_t                 key;
     njs_object_t                *prototype;
     njs_object_prop_t           *own_whiteout;
     uint8_t                     query;


More information about the nginx-devel mailing list