]> git.kaiwu.me - njs.git/commitdiff
Style and small miscellaneous fixes.
authorIgor Sysoev <igor@sysoev.ru>
Wed, 23 Mar 2016 12:27:10 +0000 (15:27 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Wed, 23 Mar 2016 12:27:10 +0000 (15:27 +0300)
njs/njs_string.c
njs/njs_string.h
njs/njs_vm.c
njs/njs_vm.h
njs/test/njs_unit_test.c
nxt/test/lvlhsh_unit_test.c
nxt/test/rbtree_unit_test.c
nxt/test/utf8_unit_test.c

index 9ecc7ccfa1268a8f57e63911e2008f3dbbde1379..42ab6444a7ec63b99d60cf6e0aeb32df52aac482 100644 (file)
@@ -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
index fb242cf2758ab14968485144188e683f9a4ca5ba..5e9f188f29fd84be87c5facaad66d59b103e35ef 100644 (file)
@@ -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.
  */
 
index dbfc0d3e21aa8628de943f9d6535e1e79ecabb7e..d9fc903ae85e63fd1a2892a53c02b58166d68bca 100644 (file)
@@ -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");
index 3b219988397da191f7bf87d641f672be88505bdc..b754cfb1324dcc0587f386cebe02af160259d0db 100644 (file)
 #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,
index e74bbd24e4705283dfa2cac4b0b841868ea19532..b83395fb09eaee56f79fffd6275f868198610418 100644 (file)
@@ -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]") },
 
index cda0243d890c117d2a883926b6a70225877a50a5..46ece5bc0daa023c6e5848bb47846f700ee11c39 100644 (file)
@@ -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,
index 1b7c544f3dee590bcb4d8d55ebb9f9c382ecd452..4817b55ab5fef54e13a3d542b5c9c628e1d820d5 100644 (file)
@@ -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;
index 702f5d5699adff6f678b81943bade6b085558604..3f1ed39fcda93c69699f0b0662fbac8ba21b819c 100644 (file)
@@ -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");