From 4db12c6f7ff2ceb328f34308544017da346952ff Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Wed, 23 Mar 2016 15:27:10 +0300 Subject: [PATCH] Style and small miscellaneous fixes. --- njs/njs_string.c | 6 ++++++ njs/njs_string.h | 2 +- njs/njs_vm.c | 1 - njs/njs_vm.h | 5 ++++- njs/test/njs_unit_test.c | 15 +++++++++++++++ nxt/test/lvlhsh_unit_test.c | 10 +++++----- nxt/test/rbtree_unit_test.c | 6 +++--- nxt/test/utf8_unit_test.c | 10 +++++----- 8 files changed, 39 insertions(+), 16 deletions(-) diff --git a/njs/njs_string.c b/njs/njs_string.c index 9ecc7ccf..42ab6444 100644 --- a/njs/njs_string.c +++ b/njs/njs_string.c @@ -547,6 +547,7 @@ njs_string_prototype_concat(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, /* * String.fromUTF8(start[, end]). + * The method converts an UTF-8 encoded byte string to an Unicode string. */ static njs_ret_t @@ -599,6 +600,7 @@ njs_string_prototype_from_utf8(njs_vm_t *vm, njs_value_t *args, /* * String.toUTF8(start[, end]). + * The method serializes Unicode string to an UTF-8 encoded byte string. */ static njs_ret_t @@ -621,6 +623,7 @@ njs_string_prototype_to_utf8(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, /* * String.fromBytes(start[, end]). + * The method converts a byte string to an Unicode string. */ static njs_ret_t @@ -676,6 +679,9 @@ njs_string_prototype_from_bytes(njs_vm_t *vm, njs_value_t *args, /* * String.toBytes(start[, end]). + * The method serializes an Unicode string to a byte string. + * The method returns null if a character larger than 255 is + * encountered in the Unicode string. */ static njs_ret_t diff --git a/njs/njs_string.h b/njs/njs_string.h index fb242cf2..5e9f188f 100644 --- a/njs/njs_string.h +++ b/njs/njs_string.h @@ -55,7 +55,7 @@ * 3) if the length is less than NJS_STRING_MAP_OFFSET. * * The current implementation does not support Unicode surrogate pairs. - * If offset in map points to surrogate pair, it the previous offset + * If offset in map points to surrogate pair then the previous offset * should be used and so on until start of the string. */ diff --git a/njs/njs_vm.c b/njs/njs_vm.c index dbfc0d3e..d9fc903a 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -133,7 +133,6 @@ const njs_value_t njs_string_nan = njs_string("NaN"); const njs_value_t njs_string_string = njs_string("string"); const njs_value_t njs_string_object = njs_string("object"); const njs_value_t njs_string_function = njs_string("function"); -const njs_value_t njs_string_native = njs_string("[native code]"); const njs_value_t njs_exception_syntax_error = njs_string("SyntaxError"); const njs_value_t njs_exception_reference_error = njs_string("ReferenceError"); diff --git a/njs/njs_vm.h b/njs/njs_vm.h index 3b219988..b754cfb1 100644 --- a/njs/njs_vm.h +++ b/njs/njs_vm.h @@ -41,7 +41,10 @@ #define NJS_APPLIED NXT_DONE -/* The order of the enum is used in njs_vmcode_typeof() */ +/* + * The order of the enum is used in njs_vmcode_typeof() + * and njs_object_prototype_to_string(). + */ typedef enum { NJS_NULL = 0x00, diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index e74bbd24..b83395fb 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -404,6 +404,15 @@ static njs_unit_test_t njs_test[] = { nxt_string("'3' -+-+-+ '1' + '1' / '3' * '6' + '2'"), nxt_string("42") }, + { nxt_string("((+!![])+(+!![])+(+!![])+(+!![])+[])+((+!![])+(+!![])+[])"), + nxt_string("42") }, + + { nxt_string("1+[[]+[]]-[]+[[]-[]]-1"), + nxt_string("9") }, + + { nxt_string("[[]+[]]-[]+[[]-[]]"), + nxt_string("00") }, + { nxt_string("'true' == true"), nxt_string("false") }, @@ -3796,6 +3805,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("Function.constructor === Function"), nxt_string("true") }, + { nxt_string("function f() {} f.__proto__ === Function.prototype"), + nxt_string("true") }, + { nxt_string("RegExp()"), nxt_string("/(?:)/") }, @@ -3823,6 +3835,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("RegExp.constructor === Function"), nxt_string("true") }, + { nxt_string("/./.__proto__ === RegExp.prototype"), + nxt_string("true") }, + { nxt_string("Object.prototype.toString.call()"), nxt_string("[object Undefined]") }, diff --git a/nxt/test/lvlhsh_unit_test.c b/nxt/test/lvlhsh_unit_test.c index cda0243d..46ece5bc 100644 --- a/nxt/test/lvlhsh_unit_test.c +++ b/nxt/test/lvlhsh_unit_test.c @@ -193,16 +193,16 @@ static const nxt_mem_proto_t mem_cache_pool_proto = { static nxt_int_t lvlhsh_unit_test(nxt_uint_t n) { - uintptr_t key; + uintptr_t key; nxt_uint_t i; nxt_lvlhsh_t lh; nxt_lvlhsh_each_t lhe; nxt_mem_cache_pool_t *pool; - const size_t min_chunk_size = 32; - const size_t page_size = 1024; - const size_t page_alignment = 128; - const size_t cluster_size = 4096; + const size_t min_chunk_size = 32; + const size_t page_size = 1024; + const size_t page_alignment = 128; + const size_t cluster_size = 4096; pool = nxt_mem_cache_pool_create(&mem_cache_pool_proto, NULL, NULL, cluster_size, page_alignment, diff --git a/nxt/test/rbtree_unit_test.c b/nxt/test/rbtree_unit_test.c index 1b7c544f..4817b55a 100644 --- a/nxt/test/rbtree_unit_test.c +++ b/nxt/test/rbtree_unit_test.c @@ -16,7 +16,7 @@ typedef struct { NXT_RBTREE_NODE (node); - uint32_t key; + uint32_t key; } nxt_rbtree_test_t; @@ -30,8 +30,8 @@ static int nxt_cdecl rbtree_unit_test_sort_cmp(const void *one, static nxt_int_t rbtree_unit_test(nxt_uint_t n) { - void *mark; - uint32_t key, *keys; + void *mark; + uint32_t key, *keys; nxt_uint_t i; nxt_rbtree_t tree; nxt_rbtree_node_t *node; diff --git a/nxt/test/utf8_unit_test.c b/nxt/test/utf8_unit_test.c index 702f5d56..3f1ed39f 100644 --- a/nxt/test/utf8_unit_test.c +++ b/nxt/test/utf8_unit_test.c @@ -49,7 +49,7 @@ utf8_overlong(u_char *overlong, size_t len) u_char *p, utf8[4]; size_t size; uint32_t u, d; - nxt_uint_t i; + nxt_uint_t i; const u_char *pp; pp = overlong; @@ -88,7 +88,7 @@ utf8_unit_test(void) size_t len; int32_t n; uint32_t u, d; - nxt_uint_t i, k, l, m; + nxt_uint_t i, k, l, m; const u_char *pp; printf("utf8 unit test started\n"); @@ -175,9 +175,9 @@ utf8_unit_test(void) } n = nxt_utf8_casecmp((u_char *) "ABC АБВ ΑΒΓ", - (u_char *) "abc абв αβγ", - sizeof("ABC АБВ ΑΒΓ") - 1, - sizeof("abc абв αβγ") - 1); + (u_char *) "abc абв αβγ", + sizeof("ABC АБВ ΑΒΓ") - 1, + sizeof("abc абв αβγ") - 1); if (n != 0) { printf("nxt_utf8_casecmp() failed\n"); -- 2.47.3