]> git.kaiwu.me - njs.git/commitdiff
Style.
authorhongzhidao <hongzhidao@gmail.com>
Sun, 4 Aug 2019 15:17:48 +0000 (11:17 -0400)
committerhongzhidao <hongzhidao@gmail.com>
Sun, 4 Aug 2019 15:17:48 +0000 (11:17 -0400)
Renaming arguments of the functions as follows:
1) "property" -> "key".
2) if function handles values of any type, its main argument
   is named "value".

src/njs_object.h
src/njs_object_prop.c
src/njs_value.c
src/njs_value.h
src/njs_vmcode.c

index e3ddbc097644a7415e0ef8a749e93a8336aaebd5..3cc4c74d210444f42efa8c05725baeb78e3040fa 100644 (file)
@@ -61,7 +61,7 @@ njs_object_prop_t *njs_object_property(njs_vm_t *vm, const njs_object_t *obj,
 njs_int_t njs_object_prop_define(njs_vm_t *vm, njs_value_t *object,
     njs_value_t *name, njs_value_t *value);
 njs_int_t njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
-    njs_value_t *value, njs_value_t *property);
+    njs_value_t *value, njs_value_t *setval);
 njs_int_t njs_prop_private_copy(njs_vm_t *vm, njs_property_query_t *pq);
 const char *njs_prop_type_string(njs_object_prop_type_t type);
 
index 81d4d39ca970786b21d75a1ef9f64b4aff768794..42c71009653a837a97de5fc0dd34af315fa2c230 100644 (file)
@@ -433,7 +433,7 @@ static const njs_value_t  njs_object_configurable_string =
 
 njs_int_t
 njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
-    njs_value_t *value, njs_value_t *property)
+    njs_value_t *value, njs_value_t *key)
 {
     njs_int_t             ret;
     njs_object_t          *desc;
@@ -444,7 +444,7 @@ njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
 
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1);
 
-    ret = njs_property_query(vm, &pq, value, property);
+    ret = njs_property_query(vm, &pq, value, key);
 
     switch (ret) {
     case NJS_OK:
index 82b960a7344864353d7b03862429978851f25d68..0fb42e22892ba54b3b4210bf10a899cdfed4b288 100644 (file)
@@ -10,7 +10,7 @@
 
 static njs_int_t njs_object_property_query(njs_vm_t *vm,
     njs_property_query_t *pq, njs_object_t *object,
-    const njs_value_t *property);
+    const njs_value_t *key);
 static njs_int_t njs_array_property_query(njs_vm_t *vm,
     njs_property_query_t *pq, njs_array_t *array, uint32_t index);
 static njs_int_t njs_string_property_query(njs_vm_t *vm,
@@ -487,8 +487,8 @@ njs_value_is_function(const njs_value_t *value)
  */
 
 njs_int_t
-njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
-    njs_value_t *property)
+njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *value,
+    njs_value_t *key)
 {
     uint32_t        index;
     njs_int_t       ret;
@@ -496,29 +496,29 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
     njs_value_t     prop;
     njs_function_t  *function;
 
-    if (njs_slow_path(!njs_is_primitive(property))) {
-        ret = njs_value_to_string(vm, &prop, property);
+    if (njs_slow_path(!njs_is_primitive(key))) {
+        ret = njs_value_to_string(vm, &prop, key);
         if (ret != NJS_OK) {
             return ret;
         }
 
-        property = &prop;
+        key = &prop;
     }
 
-    switch (object->type) {
+    switch (value->type) {
 
     case NJS_BOOLEAN:
     case NJS_NUMBER:
-        index = njs_primitive_prototype_index(object->type);
+        index = njs_primitive_prototype_index(value->type);
         obj = &vm->prototypes[index].object;
         break;
 
     case NJS_STRING:
-        if (njs_fast_path(!njs_is_null_or_undefined_or_boolean(property))) {
-            index = njs_value_to_index(property);
+        if (njs_fast_path(!njs_is_null_or_undefined_or_boolean(key))) {
+            index = njs_value_to_index(key);
 
             if (njs_fast_path(index < NJS_STRING_MAX_LENGTH)) {
-                return njs_string_property_query(vm, pq, object, index);
+                return njs_string_property_query(vm, pq, value, index);
             }
         }
 
@@ -541,11 +541,11 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
     case NJS_OBJECT_TYPE_ERROR:
     case NJS_OBJECT_URI_ERROR:
     case NJS_OBJECT_VALUE:
-        obj = njs_object(object);
+        obj = njs_object(value);
         break;
 
     case NJS_FUNCTION:
-        function = njs_function_value_copy(vm, object);
+        function = njs_function_value_copy(vm, value);
         if (njs_slow_path(function == NULL)) {
             return NJS_ERROR;
         }
@@ -560,7 +560,7 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
     case NJS_UNDEFINED:
     case NJS_NULL:
     default:
-        ret = njs_primitive_value_to_string(vm, &pq->value, property);
+        ret = njs_primitive_value_to_string(vm, &pq->value, key);
 
         if (njs_fast_path(ret == NJS_OK)) {
             njs_string_get(&pq->value, &pq->lhq.key);
@@ -574,7 +574,7 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
         return NJS_ERROR;
     }
 
-    ret = njs_primitive_value_to_string(vm, &pq->value, property);
+    ret = njs_primitive_value_to_string(vm, &pq->value, key);
 
     if (njs_fast_path(ret == NJS_OK)) {
 
@@ -583,10 +583,10 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
 
         if (obj == NULL) {
             pq->own = 1;
-            return njs_external_property_query(vm, pq, object);
+            return njs_external_property_query(vm, pq, value);
         }
 
-        return njs_object_property_query(vm, pq, obj, property);
+        return njs_object_property_query(vm, pq, obj, key);
     }
 
     return ret;
@@ -595,7 +595,7 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
 
 static njs_int_t
 njs_object_property_query(njs_vm_t *vm, njs_property_query_t *pq,
-    njs_object_t *object, const njs_value_t *property)
+    njs_object_t *object, const njs_value_t *key)
 {
     uint32_t            index;
     njs_int_t           ret;
@@ -615,10 +615,10 @@ njs_object_property_query(njs_vm_t *vm, njs_property_query_t *pq,
     do {
         pq->prototype = proto;
 
-        if (!njs_is_null_or_undefined_or_boolean(property)) {
+        if (!njs_is_null_or_undefined_or_boolean(key)) {
             switch (proto->type) {
             case NJS_ARRAY:
-                index = njs_value_to_index(property);
+                index = njs_value_to_index(key);
                 if (njs_fast_path(index < NJS_ARRAY_MAX_INDEX)) {
                     array = (njs_array_t *) proto;
                     return njs_array_property_query(vm, pq, array, index);
@@ -627,7 +627,7 @@ njs_object_property_query(njs_vm_t *vm, njs_property_query_t *pq,
                 break;
 
             case NJS_OBJECT_STRING:
-                index = njs_value_to_index(property);
+                index = njs_value_to_index(key);
                 if (njs_fast_path(index < NJS_STRING_MAX_LENGTH)) {
                     ov = (njs_object_value_t *) proto;
                     ret = njs_string_property_query(vm, pq, &ov->value, index);
@@ -921,7 +921,7 @@ njs_external_property_delete(njs_vm_t *vm, njs_value_t *value,
  *      retval will contain undefined
  */
 njs_int_t
-njs_value_property(njs_vm_t *vm, njs_value_t *value, njs_value_t *property,
+njs_value_property(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
     njs_value_t *retval)
 {
     njs_int_t             ret;
@@ -930,7 +930,7 @@ njs_value_property(njs_vm_t *vm, njs_value_t *value, njs_value_t *property,
 
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0);
 
-    ret = njs_property_query(vm, &pq, value, property);
+    ret = njs_property_query(vm, &pq, value, key);
 
     switch (ret) {
 
@@ -1009,16 +1009,16 @@ njs_value_property(njs_vm_t *vm, njs_value_t *value, njs_value_t *property,
  *   NJS_ERROR            exception has been thrown.
  */
 njs_int_t
-njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
-    njs_value_t *property, njs_value_t *value)
+njs_value_property_set(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
+    njs_value_t *setval)
 {
     njs_int_t             ret;
     njs_object_prop_t     *prop, *shared;
     njs_property_query_t  pq;
 
-    if (njs_is_primitive(object)) {
+    if (njs_is_primitive(value)) {
         njs_type_error(vm, "property set on primitive %s type",
-                       njs_type_string(object->type));
+                       njs_type_string(value->type));
         return NJS_ERROR;
     }
 
@@ -1026,7 +1026,7 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
 
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_SET, 0);
 
-    ret = njs_property_query(vm, &pq, object, property);
+    ret = njs_property_query(vm, &pq, value, key);
 
     switch (ret) {
 
@@ -1037,24 +1037,24 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
             if (!prop->writable) {
                 njs_type_error(vm,
                              "Cannot assign to read-only property \"%V\" of %s",
-                               &pq.lhq.key, njs_type_string(object->type));
+                               &pq.lhq.key, njs_type_string(value->type));
                 return NJS_ERROR;
             }
 
         } else {
             if (njs_is_function(&prop->setter)) {
                 return njs_function_call(vm, njs_function(&prop->setter),
-                                         object, value, 1, &vm->retval);
+                                         value, setval, 1, &vm->retval);
             }
 
             njs_type_error(vm,
                      "Cannot set property \"%V\" of %s which has only a getter",
-                           &pq.lhq.key, njs_type_string(object->type));
+                           &pq.lhq.key, njs_type_string(value->type));
             return NJS_ERROR;
         }
 
         if (prop->type == NJS_PROPERTY_HANDLER) {
-            ret = prop->value.data.u.prop_handler(vm, object, value,
+            ret = prop->value.data.u.prop_handler(vm, value, setval,
                                                   &vm->retval);
             if (ret != NJS_DECLINED) {
                 return ret;
@@ -1073,7 +1073,7 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
                 goto found;
 
             case NJS_PROPERTY_REF:
-                *prop->value.data.u.value = *value;
+                *prop->value.data.u.value = *setval;
                 return NJS_OK;
 
             default:
@@ -1110,7 +1110,7 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
         return ret;
     }
 
-    if (njs_slow_path(!njs_object(object)->extensible)) {
+    if (njs_slow_path(!njs_object(value)->extensible)) {
         njs_type_error(vm, "Cannot add property \"%V\", "
                        "object is not extensible", &pq.lhq.key);
         return NJS_ERROR;
@@ -1130,7 +1130,7 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
     pq.lhq.value = prop;
     pq.lhq.pool = vm->mem_pool;
 
-    ret = njs_lvlhsh_insert(njs_object_hash(object), &pq.lhq);
+    ret = njs_lvlhsh_insert(njs_object_hash(value), &pq.lhq);
     if (njs_slow_path(ret != NJS_OK)) {
         njs_internal_error(vm, "lvlhsh insert failed");
         return NJS_ERROR;
@@ -1138,7 +1138,7 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
 
 found:
 
-    prop->value = *value;
+    prop->value = *setval;
 
     return NJS_OK;
 }
index fac48342439e31d9a7bbff73c9ec4dc6ab7d9d29..6682dbd492f724b49e1f625fd78c0800014d1ef3 100644 (file)
@@ -822,11 +822,11 @@ double njs_string_to_number(const njs_value_t *value, njs_bool_t parse_float);
 njs_bool_t njs_string_eq(const njs_value_t *v1, const njs_value_t *v2);
 
 njs_int_t njs_property_query(njs_vm_t *vm, njs_property_query_t *pq,
-    njs_value_t *object, njs_value_t *property);
+    njs_value_t *value, njs_value_t *key);
 njs_int_t njs_value_property(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *property, njs_value_t *retval);
-njs_int_t njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
-    njs_value_t *property, njs_value_t *value);
+    njs_value_t *key, njs_value_t *retval);
+njs_int_t njs_value_property_set(njs_vm_t *vm, njs_value_t *value,
+    njs_value_t *key, njs_value_t *setval);
 
 
 njs_inline njs_int_t
index 148b6de4e23d26a4bb262e07959c0696929bcc99..51951451ac7c8c0225f5a05446687954d6664bf0 100644 (file)
@@ -24,11 +24,11 @@ static njs_jump_off_t njs_vmcode_object_copy(njs_vm_t *vm, njs_value_t *value,
     njs_value_t *invld);
 
 static njs_jump_off_t njs_vmcode_property_init(njs_vm_t *vm,
-    njs_value_t *object, njs_value_t *property, njs_value_t *retval);
+    njs_value_t *value, njs_value_t *key, njs_value_t *retval);
 static njs_jump_off_t njs_vmcode_property_in(njs_vm_t *vm,
-    njs_value_t *property, njs_value_t *object);
+    njs_value_t *value, njs_value_t *key);
 static njs_jump_off_t njs_vmcode_property_delete(njs_vm_t *vm,
-    njs_value_t *object, njs_value_t *property);
+    njs_value_t *value, njs_value_t *key);
 static njs_jump_off_t njs_vmcode_property_foreach(njs_vm_t *vm,
     njs_value_t *object, njs_value_t *invld, u_char *pc);
 static njs_jump_off_t njs_vmcode_property_next(njs_vm_t *vm,
@@ -1077,27 +1077,27 @@ njs_vmcode_object_copy(njs_vm_t *vm, njs_value_t *value, njs_value_t *invld)
 
 
 static njs_jump_off_t
-njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *object,
-    njs_value_t *property, njs_value_t *init)
+njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
+    njs_value_t *init)
 {
     uint32_t            index, size;
     njs_array_t         *array;
-    njs_value_t         *value, name;
+    njs_value_t         *val, name;
     njs_object_t        *obj;
     njs_jump_off_t      ret;
     njs_object_prop_t   *prop;
     njs_lvlhsh_query_t  lhq;
 
-    switch (object->type) {
+    switch (value->type) {
     case NJS_ARRAY:
-        index = njs_value_to_index(property);
+        index = njs_value_to_index(key);
         if (njs_slow_path(index == NJS_ARRAY_INVALID_INDEX)) {
             njs_internal_error(vm,
                                "invalid index while property initialization");
             return NJS_ERROR;
         }
 
-        array = object->data.u.array;
+        array = value->data.u.array;
 
         if (index >= array->length) {
             size = index - array->length;
@@ -1107,11 +1107,11 @@ njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *object,
                 return ret;
             }
 
-            value = &array->start[array->length];
+            val = &array->start[array->length];
 
             while (size != 0) {
-                njs_set_invalid(value);
-                value++;
+                njs_set_invalid(val);
+                val++;
                 size--;
             }
 
@@ -1124,7 +1124,7 @@ njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *object,
         break;
 
     case NJS_OBJECT:
-        ret = njs_value_to_string(vm, &name, property);
+        ret = njs_value_to_string(vm, &name, key);
         if (njs_slow_path(ret != NJS_OK)) {
             return NJS_ERROR;
         }
@@ -1134,14 +1134,14 @@ njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *object,
         lhq.proto = &njs_object_hash_proto;
         lhq.pool = vm->mem_pool;
 
-        obj = njs_object(object);
+        obj = njs_object(value);
 
         ret = njs_lvlhsh_find(&obj->__proto__->shared_hash, &lhq);
         if (ret == NJS_OK) {
             prop = lhq.value;
 
             if (prop->type == NJS_PROPERTY_HANDLER) {
-                ret = prop->value.data.u.prop_handler(vm, object, init,
+                ret = prop->value.data.u.prop_handler(vm, value, init,
                                                       &vm->retval);
                 if (njs_slow_path(ret != NJS_OK)) {
                     return ret;
@@ -1170,7 +1170,7 @@ njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *object,
     default:
         njs_internal_error(vm, "unexpected object type \"%s\" "
                            "while property initialization",
-                           njs_type_string(object->type));
+                           njs_type_string(value->type));
 
         return NJS_ERROR;
     }
@@ -1180,7 +1180,7 @@ njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *object,
 
 
 static njs_jump_off_t
-njs_vmcode_property_in(njs_vm_t *vm, njs_value_t *object, njs_value_t *property)
+njs_vmcode_property_in(njs_vm_t *vm, njs_value_t *value, njs_value_t *key)
 {
     njs_jump_off_t        ret;
     njs_object_prop_t     *prop;
@@ -1191,7 +1191,7 @@ njs_vmcode_property_in(njs_vm_t *vm, njs_value_t *object, njs_value_t *property)
 
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0);
 
-    ret = njs_property_query(vm, &pq, object, property);
+    ret = njs_property_query(vm, &pq, value, key);
 
     switch (ret) {
 
@@ -1206,7 +1206,7 @@ njs_vmcode_property_in(njs_vm_t *vm, njs_value_t *object, njs_value_t *property)
         break;
 
     case NJS_DECLINED:
-        if (!njs_is_object(object) && !njs_is_external(object)) {
+        if (!njs_is_object(value) && !njs_is_external(value)) {
             njs_type_error(vm, "property in on a primitive value");
 
             return NJS_ERROR;
@@ -1227,8 +1227,7 @@ njs_vmcode_property_in(njs_vm_t *vm, njs_value_t *object, njs_value_t *property)
 
 
 static njs_jump_off_t
-njs_vmcode_property_delete(njs_vm_t *vm, njs_value_t *object,
-    njs_value_t *property)
+njs_vmcode_property_delete(njs_vm_t *vm, njs_value_t *value, njs_value_t *key)
 {
     njs_jump_off_t        ret;
     njs_object_prop_t     *prop, *whipeout;
@@ -1236,7 +1235,7 @@ njs_vmcode_property_delete(njs_vm_t *vm, njs_value_t *object,
 
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_DELETE, 1);
 
-    ret = njs_property_query(vm, &pq, object, property);
+    ret = njs_property_query(vm, &pq, value, key);
 
     switch (ret) {
 
@@ -1245,7 +1244,7 @@ njs_vmcode_property_delete(njs_vm_t *vm, njs_value_t *object,
 
         if (njs_slow_path(!prop->configurable)) {
             njs_type_error(vm, "Cannot delete property \"%V\" of %s",
-                           &pq.lhq.key, njs_type_string(object->type));
+                           &pq.lhq.key, njs_type_string(value->type));
             return NJS_ERROR;
         }
 
@@ -1284,7 +1283,7 @@ njs_vmcode_property_delete(njs_vm_t *vm, njs_value_t *object,
             goto done;
 
         case NJS_PROPERTY_HANDLER:
-            ret = prop->value.data.u.prop_handler(vm, object, NULL, NULL);
+            ret = prop->value.data.u.prop_handler(vm, value, NULL, NULL);
             if (njs_slow_path(ret != NJS_OK)) {
                 return ret;
             }