Welcome! Log In Create A New Profile

Advanced

[njs] Style.

Dmitry Volyntsev
August 05, 2019 12:04PM
details: https://hg.nginx.org/njs/rev/1acb3acb1059
branches:
changeset: 1106:1acb3acb1059
user: hongzhidao <hongzhidao@gmail.com>
date: Sun Aug 04 11:17:48 2019 -0400
description:
Style.

Renaming arguments of the functions as follows:
1) "property" -> "key".
2) if function handles values of any type, its main argument
is named "value".

diffstat:

src/njs_object.h | 2 +-
src/njs_object_prop.c | 4 +-
src/njs_value.c | 72 +++++++++++++++++++++++++-------------------------
src/njs_value.h | 8 ++--
src/njs_vmcode.c | 47 ++++++++++++++++-----------------
5 files changed, 66 insertions(+), 67 deletions(-)

diffs (468 lines):

diff -r bfdf58ec9116 -r 1acb3acb1059 src/njs_object.h
--- a/src/njs_object.h Mon Aug 05 17:10:59 2019 +0300
+++ b/src/njs_object.h Sun Aug 04 11:17:48 2019 -0400
@@ -61,7 +61,7 @@ njs_object_prop_t *njs_object_property(n
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);

diff -r bfdf58ec9116 -r 1acb3acb1059 src/njs_object_prop.c
--- a/src/njs_object_prop.c Mon Aug 05 17:10:59 2019 +0300
+++ b/src/njs_object_prop.c Sun Aug 04 11:17:48 2019 -0400
@@ -433,7 +433,7 @@ static const njs_value_t njs_object_con

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_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:
diff -r bfdf58ec9116 -r 1acb3acb1059 src/njs_value.c
--- a/src/njs_value.c Mon Aug 05 17:10:59 2019 +0300
+++ b/src/njs_value.c Sun Aug 04 11:17:48 2019 -0400
@@ -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
*/

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_pro
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_pro
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_pro
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_pro
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_pro

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_pro

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,
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,
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 *v
* 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_val

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_val
* 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

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
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
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
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
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

found:

- prop->value = *value;
+ prop->value = *setval;

return NJS_OK;
}
diff -r bfdf58ec9116 -r 1acb3acb1059 src/njs_value.h
--- a/src/njs_value.h Mon Aug 05 17:10:59 2019 +0300
+++ b/src/njs_value.h Sun Aug 04 11:17:48 2019 -0400
@@ -822,11 +822,11 @@ double njs_string_to_number(const njs_va
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
diff -r bfdf58ec9116 -r 1acb3acb1059 src/njs_vmcode.c
--- a/src/njs_vmcode.c Mon Aug 05 17:10:59 2019 +0300
+++ b/src/njs_vmcode.c Sun Aug 04 11:17:48 2019 -0400
@@ -24,11 +24,11 @@ static njs_jump_off_t njs_vmcode_object_
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


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, n
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, n
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, n
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, n
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, n


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

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
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


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_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,

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,
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;
}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Style.

Dmitry Volyntsev 235 August 05, 2019 12:04PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 251
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready