From: Igor Sysoev Date: Wed, 3 Feb 2016 12:03:30 +0000 (+0300) Subject: Style and small miscellaneous fixes. X-Git-Tag: 0.1.0~77 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=08f6b5fddab6c1b01c99f4c2500937a31de3e2a4;p=njs.git Style and small miscellaneous fixes. --- diff --git a/njs/njs_array.c b/njs/njs_array.c index 8425c3e3..a13cd9c0 100644 --- a/njs/njs_array.c +++ b/njs/njs_array.c @@ -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), }; diff --git a/njs/njs_boolean.c b/njs/njs_boolean.c index a0bdb335..3affde65 100644 --- a/njs/njs_boolean.c +++ b/njs/njs_boolean.c @@ -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), }; diff --git a/njs/njs_builtin.c b/njs/njs_builtin.c index ac660be5..b37c7170 100644 --- a/njs/njs_builtin.c +++ b/njs/njs_builtin.c @@ -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); diff --git a/njs/njs_extern.c b/njs/njs_extern.c index a52b0a76..42420100 100644 --- a/njs/njs_extern.c +++ b/njs/njs_extern.c @@ -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; diff --git a/njs/njs_function.c b/njs/njs_function.c index e680d2c5..f9153876 100644 --- a/njs/njs_function.c +++ b/njs/njs_function.c @@ -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), }; diff --git a/njs/njs_function.h b/njs/njs_function.h index 7f17fbc0..796ae79c 100644 --- a/njs/njs_function.h +++ b/njs/njs_function.h @@ -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; diff --git a/njs/njs_generator.c b/njs/njs_generator.c index 25992f8f..305521c0 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -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 diff --git a/njs/njs_number.c b/njs/njs_number.c index 53ee7671..2468ce5e 100644 --- a/njs/njs_number.c +++ b/njs/njs_number.c @@ -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), }; diff --git a/njs/njs_object.c b/njs/njs_object.c index a412ec8a..14f183d7 100644 --- a/njs/njs_object.c +++ b/njs/njs_object.c @@ -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), }; diff --git a/njs/njs_regexp.c b/njs/njs_regexp.c index 91945332..7d238343 100644 --- a/njs/njs_regexp.c +++ b/njs/njs_regexp.c @@ -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), }; diff --git a/njs/njs_string.c b/njs/njs_string.c index 13fe0661..21447442 100644 --- a/njs/njs_string.c +++ b/njs/njs_string.c @@ -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), }; diff --git a/njs/njs_vm.c b/njs/njs_vm.c index 80dbf791..da9793af 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -2806,7 +2806,6 @@ fail: dst->data = NULL; return NXT_ERROR; - } diff --git a/njs/njs_vm.h b/njs/njs_vm.h index b7b59f33..bfe83926 100644 --- a/njs/njs_vm.h +++ b/njs/njs_vm.h @@ -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]; }; diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index bde2ed3d..1232ee44 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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,