[njs] Style.

Dmitry Volyntsev xeioex at nginx.com
Thu Apr 18 17:53:59 UTC 2019


details:   https://hg.nginx.org/njs/rev/6d7a4fb82b25
branches:  
changeset: 910:6d7a4fb82b25
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Apr 18 20:51:53 2019 +0300
description:
Style.

diffstat:

 njs/njs_generator.c     |   4 +-
 njs/njs_object.c        |  35 +++++++++++--------
 njs/njs_vm.c            |  86 ++++++++++++++++++++++++------------------------
 njs/test/module/lib1.js |   4 +-
 nxt/nxt_clang.h         |   1 -
 5 files changed, 68 insertions(+), 62 deletions(-)

diffs (263 lines):

diff -r ec44a042cf15 -r 6d7a4fb82b25 njs/njs_generator.c
--- a/njs/njs_generator.c	Fri Apr 19 00:28:31 2019 +0800
+++ b/njs/njs_generator.c	Thu Apr 18 20:51:53 2019 +0300
@@ -1606,7 +1606,8 @@ njs_generate_stop_statement(njs_vm_t *vm
         }
 
         if (index == NJS_INDEX_NONE) {
-            index = njs_value_index(vm, &njs_value_undefined, generator->runtime);
+            index = njs_value_index(vm, &njs_value_undefined,
+                                    generator->runtime);
         }
 
         stop->retval = index;
@@ -2548,6 +2549,7 @@ njs_generate_function_call(njs_vm_t *vm,
         if (nxt_slow_path(ret != NXT_OK)) {
             return ret;
         }
+
         name = node;
     }
 
diff -r ec44a042cf15 -r 6d7a4fb82b25 njs/njs_object.c
--- a/njs/njs_object.c	Fri Apr 19 00:28:31 2019 +0800
+++ b/njs/njs_object.c	Thu Apr 18 20:51:53 2019 +0300
@@ -27,7 +27,7 @@ static njs_ret_t njs_object_query_prop_h
 static njs_ret_t njs_define_property(njs_vm_t *vm, njs_value_t *object,
     const njs_value_t *name, const njs_object_t *descriptor);
 
-static njs_object_prop_t * njs_object_exist_in_proto(const njs_object_t *begin,
+static njs_object_prop_t *njs_object_exist_in_proto(const njs_object_t *begin,
     const njs_object_t *end, nxt_lvlhsh_query_t *lhq);
 static uint32_t njs_object_enumerate_array_length(const njs_object_t *object);
 static uint32_t njs_object_enumerate_string_length(const njs_object_t *object);
@@ -977,7 +977,7 @@ njs_object_entries(njs_vm_t *vm, njs_val
 
 
 static njs_object_prop_t *
-njs_object_exist_in_proto(const njs_object_t *begin, const njs_object_t *end,
+njs_object_exist_in_proto(const njs_object_t *object, const njs_object_t *end,
     nxt_lvlhsh_query_t *lhq)
 {
     nxt_int_t          ret;
@@ -985,8 +985,8 @@ njs_object_exist_in_proto(const njs_obje
 
     lhq->proto = &njs_object_hash_proto;
 
-    while (begin != end) {
-        ret = nxt_lvlhsh_find(&begin->hash, lhq);
+    while (object != end) {
+        ret = nxt_lvlhsh_find(&object->hash, lhq);
 
         if (nxt_fast_path(ret == NXT_OK)) {
             prop = lhq->value;
@@ -998,7 +998,7 @@ njs_object_exist_in_proto(const njs_obje
             return lhq->value;
         }
 
-        ret = nxt_lvlhsh_find(&begin->shared_hash, lhq);
+        ret = nxt_lvlhsh_find(&object->shared_hash, lhq);
 
         if (nxt_fast_path(ret == NXT_OK)) {
             return lhq->value;
@@ -1006,7 +1006,7 @@ njs_object_exist_in_proto(const njs_obje
 
 next:
 
-        begin = begin->__proto__;
+        object = object->__proto__;
     }
 
     return NULL;
@@ -1111,7 +1111,7 @@ njs_object_own_enumerate_value(njs_vm_t 
     switch (object->type) {
     case NJS_ARRAY:
         ret = njs_object_enumerate_array(vm, (njs_array_t *) object, items,
-                                            kind);
+                                         kind);
         break;
 
     case NJS_OBJECT_STRING:
@@ -1225,13 +1225,15 @@ static uint32_t
 njs_object_enumerate_object_length(const njs_object_t *object, nxt_bool_t all)
 {
     uint32_t            length;
-    const njs_object_t  *ptr;
+    const njs_object_t  *proto;
 
     length = njs_object_own_enumerate_object_length(object, object, all);
 
-    for (ptr = object->__proto__; ptr != NULL; ptr = ptr->__proto__) {
-
-        length += njs_object_own_enumerate_length(ptr, object, all);
+    proto = object->__proto__;
+
+    while (proto != NULL) {
+        length += njs_object_own_enumerate_length(proto, object, all);
+        proto = proto->__proto__;
     }
 
     return length;
@@ -1493,20 +1495,23 @@ njs_object_enumerate_object(njs_vm_t *vm
     njs_array_t *items, njs_object_enum_t kind, nxt_bool_t all)
 {
     njs_ret_t           ret;
-    const njs_object_t  *ptr;
+    const njs_object_t  *proto;
 
     ret = njs_object_own_enumerate_object(vm, object, object, items, kind, all);
     if (nxt_slow_path(ret != NXT_OK)) {
         return NXT_ERROR;
     }
 
-    for (ptr = object->__proto__; ptr != NULL; ptr = ptr->__proto__) {
-
-        ret = njs_object_own_enumerate_value(vm, ptr, object, items, kind,
+    proto = object->__proto__;
+
+    while (proto != NULL) {
+        ret = njs_object_own_enumerate_value(vm, proto, object, items, kind,
                                              all);
         if (nxt_slow_path(ret != NXT_OK)) {
             return NXT_ERROR;
         }
+
+        proto = proto->__proto__;
     }
 
     return NJS_OK;
diff -r ec44a042cf15 -r 6d7a4fb82b25 njs/njs_vm.c
--- a/njs/njs_vm.c	Fri Apr 19 00:28:31 2019 +0800
+++ b/njs/njs_vm.c	Thu Apr 18 20:51:53 2019 +0300
@@ -840,7 +840,7 @@ njs_vmcode_property_next(njs_vm_t *vm, n
     next = value->data.u.next;
 
     if (next->index < next->array->length) {
-        *retval = next->array->data[ next->index++ ];
+        *retval = next->array->data[next->index++];
 
         return code->offset;
     }
@@ -3023,6 +3023,48 @@ njs_value_property(njs_vm_t *vm, const n
 }
 
 
+njs_array_t *
+njs_value_enumerate(njs_vm_t *vm, const njs_value_t *value,
+    njs_object_enum_t kind, nxt_bool_t all)
+{
+    njs_object_value_t  obj_val;
+
+    if (njs_is_object(value)) {
+        return njs_object_enumerate(vm, value->data.u.object, kind, all);
+    }
+
+    if (value->type != NJS_STRING) {
+        return njs_array_alloc(vm, 0, NJS_ARRAY_SPARE);
+    }
+
+    obj_val.object = vm->string_object;
+    obj_val.value = *value;
+
+    return njs_object_enumerate(vm, (njs_object_t *) &obj_val, kind, all);
+}
+
+
+njs_array_t *
+njs_value_own_enumerate(njs_vm_t *vm, const njs_value_t *value,
+    njs_object_enum_t kind, nxt_bool_t all)
+{
+    njs_object_value_t  obj_val;
+
+    if (njs_is_object(value)) {
+        return njs_object_own_enumerate(vm, value->data.u.object, kind, all);
+    }
+
+    if (value->type != NJS_STRING) {
+        return njs_array_alloc(vm, 0, NJS_ARRAY_SPARE);
+    }
+
+    obj_val.object = vm->string_object;
+    obj_val.value = *value;
+
+    return njs_object_own_enumerate(vm, (njs_object_t *) &obj_val, kind, all);
+}
+
+
 njs_ret_t
 njs_vm_value_to_ext_string(njs_vm_t *vm, nxt_str_t *dst, const njs_value_t *src,
     nxt_uint_t handle_exception)
@@ -3613,45 +3655,3 @@ njs_lvlhsh_free(void *data, void *p, siz
 {
     nxt_mp_free(data, p);
 }
-
-
-njs_array_t *
-njs_value_enumerate(njs_vm_t *vm, const njs_value_t *value,
-    njs_object_enum_t kind, nxt_bool_t all)
-{
-    njs_object_value_t  obj_val;
-
-    if (njs_is_object(value)) {
-        return njs_object_enumerate(vm, value->data.u.object, kind, all);
-    }
-
-    if (value->type != NJS_STRING) {
-        return njs_array_alloc(vm, 0, NJS_ARRAY_SPARE);
-    }
-
-    obj_val.object = vm->string_object;
-    obj_val.value = *value;
-
-    return njs_object_enumerate(vm, (njs_object_t *) &obj_val, kind, all);
-}
-
-
-njs_array_t *
-njs_value_own_enumerate(njs_vm_t *vm, const njs_value_t *value,
-    njs_object_enum_t kind, nxt_bool_t all)
-{
-    njs_object_value_t  obj_val;
-
-    if (njs_is_object(value)) {
-        return njs_object_own_enumerate(vm, value->data.u.object, kind, all);
-    }
-
-    if (value->type != NJS_STRING) {
-        return njs_array_alloc(vm, 0, NJS_ARRAY_SPARE);
-    }
-
-    obj_val.object = vm->string_object;
-    obj_val.value = *value;
-
-    return njs_object_own_enumerate(vm, (njs_object_t *) &obj_val, kind, all);
-}
diff -r ec44a042cf15 -r 6d7a4fb82b25 njs/test/module/lib1.js
--- a/njs/test/module/lib1.js	Fri Apr 19 00:28:31 2019 +0800
+++ b/njs/test/module/lib1.js	Thu Apr 18 20:51:53 2019 +0300
@@ -9,11 +9,11 @@ import crypto from 'crypto';
 var state = {count:0}
 
 function inc() {
-	state.count++;
+    state.count++;
 }
 
 function get() {
-	return state.count;
+    return state.count;
 }
 
 export default {hash, inc, get};
diff -r ec44a042cf15 -r 6d7a4fb82b25 nxt/nxt_clang.h
--- a/nxt/nxt_clang.h	Fri Apr 19 00:28:31 2019 +0800
+++ b/nxt/nxt_clang.h	Thu Apr 18 20:51:53 2019 +0300
@@ -25,7 +25,6 @@
     (sizeof(x) / sizeof((x)[0]))
 
 
-
 #if (NXT_HAVE_BUILTIN_EXPECT)
 #define nxt_expect(c, x)   __builtin_expect((long) (x), (c))
 #define nxt_fast_path(x)   nxt_expect(1, x)


More information about the nginx-devel mailing list