]> git.kaiwu.me - njs.git/commitdiff
Style and small miscellaneous fixes.
authorIgor Sysoev <igor@sysoev.ru>
Wed, 3 Feb 2016 12:03:30 +0000 (15:03 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Wed, 3 Feb 2016 12:03:30 +0000 (15:03 +0300)
14 files changed:
njs/njs_array.c
njs/njs_boolean.c
njs/njs_builtin.c
njs/njs_extern.c
njs/njs_function.c
njs/njs_function.h
njs/njs_generator.c
njs/njs_number.c
njs/njs_object.c
njs/njs_regexp.c
njs/njs_string.c
njs/njs_vm.c
njs/njs_vm.h
njs/test/njs_unit_test.c

index 8425c3e3ba7362771b2cdfb5a45f27fb585b95b3..a13cd9c0f58738ce7a4401c4ba7d9bdab09da29d 100644 (file)
@@ -244,8 +244,8 @@ static const njs_object_prop_t  njs_array_constructor_properties[] =
 
 
 const njs_object_init_t  njs_array_constructor_init = {
-     njs_array_constructor_properties,
-     nxt_nitems(njs_array_constructor_properties),
+    njs_array_constructor_properties,
+    nxt_nitems(njs_array_constructor_properties),
 };
 
 
@@ -973,6 +973,6 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
 
 
 const njs_object_init_t  njs_array_prototype_init = {
-     njs_array_prototype_properties,
-     nxt_nitems(njs_array_prototype_properties),
+    njs_array_prototype_properties,
+    nxt_nitems(njs_array_prototype_properties),
 };
index a0bdb335b8b3a6103e311a33a0cd462bcc7183c2..3affde6573daf4181972fe2f8b64f7622d274c50 100644 (file)
@@ -75,8 +75,8 @@ static const njs_object_prop_t  njs_boolean_constructor_properties[] =
 
 
 const njs_object_init_t  njs_boolean_constructor_init = {
-     njs_boolean_constructor_properties,
-     nxt_nitems(njs_boolean_constructor_properties),
+    njs_boolean_constructor_properties,
+    nxt_nitems(njs_boolean_constructor_properties),
 };
 
 
@@ -151,6 +151,6 @@ static const njs_object_prop_t  njs_boolean_prototype_properties[] =
 
 
 const njs_object_init_t  njs_boolean_prototype_init = {
-     njs_boolean_prototype_properties,
-     nxt_nitems(njs_boolean_prototype_properties),
+    njs_boolean_prototype_properties,
+    nxt_nitems(njs_boolean_prototype_properties),
 };
index ac660be5a9683c8b1bcce0762c90a9e8c37ab637..b37c717023ae9175114c0534c83aee57c1937726 100644 (file)
@@ -152,6 +152,10 @@ njs_builtin_objects_clone(njs_vm_t *vm)
     njs_value_t   *values;
     njs_object_t  *function_prototype;
 
+    /*
+     * Copy both prototypes and functions arrays by one memcpy()
+     * because they are stored together.
+     */
     size = NJS_PROTOTYPE_MAX * sizeof(njs_object_t)
            + NJS_FUNCTION_MAX * sizeof(njs_function_t);
 
index a52b0a76583e583f89e4cfccadba18c0b1f0a2c2..42420100c9c654f6350c31edb8a2cb4795218172 100644 (file)
@@ -50,8 +50,8 @@ const nxt_lvlhsh_proto_t  njs_extern_hash_proto
 
 
 nxt_int_t
-njs_add_external(nxt_lvlhsh_t *hash, nxt_mem_cache_pool_t *mcp, uintptr_t object,
-    njs_external_t *external, nxt_uint_t n)
+njs_add_external(nxt_lvlhsh_t *hash, nxt_mem_cache_pool_t *mcp,
+    uintptr_t object, njs_external_t *external, nxt_uint_t n)
 {
     nxt_int_t           ret;
     njs_extern_t        *ext;
index e680d2c57158030f09238fa8172a0f0a0ce805c3..f91538761ed819dcddce9ec1fc3c3290f932c434 100644 (file)
@@ -260,8 +260,8 @@ static const njs_object_prop_t  njs_function_constructor_properties[] =
 
 
 const njs_object_init_t  njs_function_constructor_init = {
-     njs_function_constructor_properties,
-     nxt_nitems(njs_function_constructor_properties),
+    njs_function_constructor_properties,
+    nxt_nitems(njs_function_constructor_properties),
 };
 
 
@@ -442,8 +442,8 @@ static const njs_object_prop_t  njs_function_prototype_properties[] =
 
 
 const njs_object_init_t  njs_function_prototype_init = {
-     njs_function_prototype_properties,
-     nxt_nitems(njs_function_prototype_properties),
+    njs_function_prototype_properties,
+    nxt_nitems(njs_function_prototype_properties),
 };
 
 
@@ -473,6 +473,6 @@ static const njs_object_prop_t  njs_eval_function_properties[] =
 
 
 const njs_object_init_t  njs_eval_function_init = {
-     njs_eval_function_properties,
-     nxt_nitems(njs_eval_function_properties),
+    njs_eval_function_properties,
+    nxt_nitems(njs_eval_function_properties),
 };
index 7f17fbc016d1b076fdc261d6443fcf85e061017d..796ae79cd8605b3d12c771225129037713424ebc 100644 (file)
@@ -64,7 +64,7 @@ struct njs_native_frame_s {
 
     /*
      * The return_address is required in njs_frame_t only, however, it
-     * can be stored here just after function adddress has been fetched.
+     * can be stored here just after function address has been fetched.
      */
     union {
         njs_function_t             *function;
index 25992f8f1cede2adff9594e97165b8e73b16deb2..305521c019275c3cd0a618ed25447e8b0e31631e 100644 (file)
@@ -110,7 +110,7 @@ static nxt_noinline nxt_int_t njs_generator_index_release(njs_vm_t *vm,
 nxt_inline nxt_bool_t njs_generator_is_constant(njs_parser_node_t *node);
 
 
-static const nxt_str_t no_label = { 0, NULL };
+static const nxt_str_t  no_label = { 0, NULL };
 
 
 static nxt_int_t
index 53ee76715ed402735532914c412aa0db8550ecea..2468ce5e294957a86df9fcf4665a39074faf8bd5 100644 (file)
@@ -270,8 +270,8 @@ static const njs_object_prop_t  njs_number_constructor_properties[] =
 
 
 const njs_object_init_t  njs_number_constructor_init = {
-     njs_number_constructor_properties,
-     nxt_nitems(njs_number_constructor_properties),
+    njs_number_constructor_properties,
+    nxt_nitems(njs_number_constructor_properties),
 };
 
 
@@ -344,6 +344,6 @@ static const njs_object_prop_t  njs_number_prototype_properties[] =
 
 
 const njs_object_init_t  njs_number_prototype_init = {
-     njs_number_prototype_properties,
-     nxt_nitems(njs_number_prototype_properties),
+    njs_number_prototype_properties,
+    nxt_nitems(njs_number_prototype_properties),
 };
index a412ec8a0de06516050193363edad978b6f3dbe6..14f183d71a610bdce891e45a1673a6cc0c11d53f 100644 (file)
@@ -419,8 +419,8 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
 
 
 const njs_object_init_t  njs_object_constructor_init = {
-     njs_object_constructor_properties,
-     nxt_nitems(njs_object_constructor_properties),
+    njs_object_constructor_properties,
+    nxt_nitems(njs_object_constructor_properties),
 };
 
 
@@ -634,6 +634,6 @@ static const njs_object_prop_t  njs_object_prototype_properties[] =
 
 
 const njs_object_init_t  njs_object_prototype_init = {
-     njs_object_prototype_properties,
-     nxt_nitems(njs_object_prototype_properties),
+    njs_object_prototype_properties,
+    nxt_nitems(njs_object_prototype_properties),
 };
index 91945332fd9f4c073c062a81483db34361872bd9..7d2383434f43122d9630ed6835eff0fc0d9fc329 100644 (file)
@@ -689,8 +689,8 @@ static const njs_object_prop_t  njs_regexp_constructor_properties[] =
 
 
 const njs_object_init_t  njs_regexp_constructor_init = {
-     njs_regexp_constructor_properties,
-     nxt_nitems(njs_regexp_constructor_properties),
+    njs_regexp_constructor_properties,
+    nxt_nitems(njs_regexp_constructor_properties),
 };
 
 
@@ -747,8 +747,8 @@ static const njs_object_prop_t  njs_regexp_prototype_properties[] =
 
 
 const njs_object_init_t  njs_regexp_prototype_init = {
-     njs_regexp_prototype_properties,
-     nxt_nitems(njs_regexp_prototype_properties),
+    njs_regexp_prototype_properties,
+    nxt_nitems(njs_regexp_prototype_properties),
 };
 
 
index 13fe0661d757131fb0fb076054d7eee2e043665a..2144744267a5eece4d3e134bdbcf68433a3b7ba8 100644 (file)
@@ -308,8 +308,8 @@ static const njs_object_prop_t  njs_string_constructor_properties[] =
 
 
 const njs_object_init_t  njs_string_constructor_init = {
-     njs_string_constructor_properties,
-     nxt_nitems(njs_string_constructor_properties),
+    njs_string_constructor_properties,
+    nxt_nitems(njs_string_constructor_properties),
 };
 
 
@@ -1684,7 +1684,6 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
     },
 
     /* ECMAScript 6, codePointAt(). */
-
     {
         .type = NJS_METHOD,
         .name = njs_string("codePointAt"),
@@ -1718,8 +1717,8 @@ static const njs_object_prop_t  njs_string_prototype_properties[] =
 
 
 const njs_object_init_t  njs_string_prototype_init = {
-     njs_string_prototype_properties,
-     nxt_nitems(njs_string_prototype_properties),
+    njs_string_prototype_properties,
+    nxt_nitems(njs_string_prototype_properties),
 };
 
 
index 80dbf791fdd101707e9b29e9826edee9a16ccb7f..da9793afd05707a4a758878159c502fe46275a10 100644 (file)
@@ -2806,7 +2806,6 @@ fail:
     dst->data = NULL;
 
     return NXT_ERROR;
-
 }
 
 
index b7b59f3355cb21a47dc062412f55b510cf1fc2db..bfe8392615778d15c0dd0afaaaa7c354c517b0b5 100644 (file)
@@ -710,6 +710,11 @@ struct njs_vm_s {
     nxt_lvlhsh_t             variables_hash;
     nxt_lvlhsh_t             values_hash;
 
+    /*
+     * The prototypes and functions arrays must be togther because
+     * they are copied from njs_vm_shared_t by single memcpy()
+     * in njs_builtin_objects_clone().
+     */
     njs_object_t             prototypes[NJS_PROTOTYPE_MAX];
     njs_function_t           functions[NJS_FUNCTION_MAX];
 
@@ -737,6 +742,10 @@ struct njs_vm_shared_s {
     nxt_lvlhsh_t             values_hash;
     nxt_lvlhsh_t             null_proto_hash;
 
+    /*
+     * The prototypes and functions arrays must be togther because they are
+     * copied to njs_vm_t by single memcpy() in njs_builtin_objects_clone().
+     */
     njs_object_t             prototypes[NJS_PROTOTYPE_MAX];
     njs_function_t           functions[NJS_FUNCTION_MAX];
 };
index bde2ed3d4c6f175781228d16a6df3bc16b4cde25..1232ee44e8d7b663b6347a026b54502091b6df45 100644 (file)
@@ -1980,10 +1980,10 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("a = []; a[5] = 5; a.join()"),
       nxt_string(",,,,,5") },
 
-    { nxt_string("a = []; a[5] = 5; a +''"),
+    { nxt_string("a = []; a[5] = 5; a"),
       nxt_string(",,,,,5") },
 
-    { nxt_string("a = []; a.concat([]) +''"),
+    { nxt_string("a = []; a.concat([])"),
       nxt_string("") },
 
     /* Array.toString(). */
@@ -2059,7 +2059,7 @@ static njs_unit_test_t  njs_test[] =
 
     /**/
 
-    { nxt_string("a = [1,2,3]; a.concat(4, [5, 6, 7], 8) +''"),
+    { nxt_string("a = [1,2,3]; a.concat(4, [5, 6, 7], 8)"),
       nxt_string("1,2,3,4,5,6,7,8") },
 
     { nxt_string("a = []; a[100] = a.length; a[100] +' '+ a.length"),
@@ -2106,8 +2106,7 @@ static njs_unit_test_t  njs_test[] =
       nxt_string("6") },
 
     { nxt_string("var a = [1,2,3];"
-                 "a.forEach(function(v, i, a) { a[i+3] = a.length });"
-                 "a +''"),
+                 "a.forEach(function(v, i, a) { a[i+3] = a.length }); a"),
       nxt_string("1,2,3,3,4,5") },
 
     { nxt_string("var a = [];"
@@ -2449,10 +2448,10 @@ static njs_unit_test_t  njs_test[] =
                  "a"),
       nxt_string("01:01|АБВ,02:02|АБВ,03:03|АБВ,") },
 
-    { nxt_string("$r.external('YES')"),
+    { nxt_string("$r.some_method('YES')"),
       nxt_string("АБВ") },
 
-    { nxt_string("for (p in $r.external);"),
+    { nxt_string("for (p in $r.some_method);"),
       nxt_string("undefined") },
 
     { nxt_string("'uri' in $r"),
@@ -2468,10 +2467,10 @@ static njs_unit_test_t  njs_test[] =
       nxt_string("false") },
 
 #if 0
-    { nxt_string("$r.external.call($r, 'YES')"),
+    { nxt_string("$r.some_method.call($r, 'YES')"),
       nxt_string("АБВ") },
 
-    { nxt_string("$r.external.apply($r, ['YES'])"),
+    { nxt_string("$r.some_method.apply($r, ['YES'])"),
       nxt_string("АБВ") },
 #endif
 
@@ -2571,16 +2570,16 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("'abcdefgh'.search('def')"),
       nxt_string("3") },
 
-    { nxt_string("''.match(/^$/) +''"),
+    { nxt_string("''.match(/^$/)"),
       nxt_string("") },
 
-    { nxt_string("''.match(/^$/g) +''"),
+    { nxt_string("''.match(/^$/g)"),
       nxt_string("") },
 
-    { nxt_string("'abcdefgh'.match(/def/) +''"),
+    { nxt_string("'abcdefgh'.match(/def/)"),
       nxt_string("def") },
 
-    { nxt_string("'abc ABC aBc'.match(/abc/ig) +''"),
+    { nxt_string("'abc ABC aBc'.match(/abc/ig)"),
       nxt_string("abc,ABC,aBc") },
 
     /* Functions. */
@@ -2806,6 +2805,12 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("a = (0, function(a) { return a + 1 }(2)); a"),
       nxt_string("3") },
 
+    { nxt_string("var a = 0, function(a) { return a + 1 }(2); a"),
+      nxt_string("SyntaxError") },
+
+    { nxt_string("var a = (0, function(a) { return a + 1 }(2)); a"),
+      nxt_string("3") },
+
     { nxt_string("var a = +function f(a) { return a + 1 }(2)"
                  "var b = f(5); a"),
       nxt_string("ReferenceError") },
@@ -3150,7 +3155,7 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("var o = new Object(); o"),
       nxt_string("[object Object]") },
 
-    { nxt_string("var o = new Object(1); o +''"),
+    { nxt_string("var o = new Object(1); o"),
       nxt_string("1") },
 
     { nxt_string("var o = {}; o === Object(o)"),
@@ -3186,7 +3191,7 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("({}).constructor === Object"),
       nxt_string("true") },
 
-    { nxt_string("var a = Array(3); a +''"),
+    { nxt_string("var a = Array(3); a"),
       nxt_string(",,") },
 
     { nxt_string("var a = Array(); a.length"),
@@ -3195,10 +3200,10 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("var a = Array(0); a.length"),
       nxt_string("0") },
 
-    { nxt_string("var a = Array(true); a +''"),
+    { nxt_string("var a = Array(true); a"),
       nxt_string("true") },
 
-    { nxt_string("var a = Array(1,'two',3); a +''"),
+    { nxt_string("var a = Array(1,'two',3); a"),
       nxt_string("1,two,3") },
 
     { nxt_string("var a = Array(-1)"),
@@ -3213,7 +3218,7 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("var a = Array(Infinity)"),
       nxt_string("RangeError") },
 
-    { nxt_string("var a = new Array(3); a +''"),
+    { nxt_string("var a = new Array(3); a"),
       nxt_string(",,") },
 
     { nxt_string("Array.name"),
@@ -3234,7 +3239,7 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("Array.constructor === Function"),
       nxt_string("true") },
 
-    { nxt_string("var a = []; a.join = 'OK'; a +''"),
+    { nxt_string("var a = []; a.join = 'OK'; a"),
       nxt_string("[object Array]") },
 
     { nxt_string("[].__proto__ === Array.prototype"),
@@ -3405,12 +3410,6 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("RegExp.constructor === Function"),
       nxt_string("true") },
 
-    { nxt_string("var a = 0, function(a) { return a + 1 }(2); a"),
-      nxt_string("SyntaxError") },
-
-    { nxt_string("var a = (0, function(a) { return a + 1 }(2)); a"),
-      nxt_string("3") },
-
 #if 0
     { nxt_string("Object.prototype.toString.call()"),
       nxt_string("[object Undefined]") },
@@ -3686,7 +3685,7 @@ static njs_external_t  njs_unit_test_r_external[] = {
       NULL,
       0 },
 
-    { nxt_string("external"),
+    { nxt_string("some_method"),
       NJS_EXTERN_METHOD,
       NULL,
       0,