From 11952580dd887ffbcd46ed78564fca57e63c423f Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Thu, 18 Apr 2019 20:51:53 +0300 Subject: [PATCH] Style. --- njs/njs_generator.c | 4 +- njs/njs_object.c | 31 ++++++++------- njs/njs_vm.c | 86 ++++++++++++++++++++--------------------- njs/test/module/lib1.js | 4 +- nxt/nxt_clang.h | 1 - 5 files changed, 66 insertions(+), 60 deletions(-) diff --git a/njs/njs_generator.c b/njs/njs_generator.c index 78a8a142..470c66dd 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -1606,7 +1606,8 @@ njs_generate_stop_statement(njs_vm_t *vm, njs_generator_t *generator, } 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, njs_generator_t *generator, if (nxt_slow_path(ret != NXT_OK)) { return ret; } + name = node; } diff --git a/njs/njs_object.c b/njs/njs_object.c index 6c8331eb..3f3ccc8a 100644 --- a/njs/njs_object.c +++ b/njs/njs_object.c @@ -27,7 +27,7 @@ static njs_ret_t njs_object_query_prop_handler(njs_property_query_t *pq, 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_value_t *args, nxt_uint_t nargs, 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_object_t *begin, const njs_object_t *end, 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_object_t *begin, const njs_object_t *end, 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_object_t *begin, const njs_object_t *end, next: - begin = begin->__proto__; + object = object->__proto__; } return NULL; @@ -1111,7 +1111,7 @@ njs_object_own_enumerate_value(njs_vm_t *vm, const njs_object_t *object, 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__) { + proto = object->__proto__; - length += njs_object_own_enumerate_length(ptr, object, all); + 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, const njs_object_t *object, 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__) { + proto = object->__proto__; - ret = njs_object_own_enumerate_value(vm, ptr, object, items, kind, + 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 --git a/njs/njs_vm.c b/njs/njs_vm.c index 90e83f4a..b2606c20 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -840,7 +840,7 @@ njs_vmcode_property_next(njs_vm_t *vm, njs_value_t *object, njs_value_t *value) 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 njs_value_t *value, } +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, size_t size) { 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 --git a/njs/test/module/lib1.js b/njs/test/module/lib1.js index 8bf87cc2..5bfe2d0d 100644 --- a/njs/test/module/lib1.js +++ b/njs/test/module/lib1.js @@ -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 --git a/nxt/nxt_clang.h b/nxt/nxt_clang.h index f79108ff..fddba0ec 100644 --- a/nxt/nxt_clang.h +++ b/nxt/nxt_clang.h @@ -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) -- 2.47.3