[njs] Fixed expect tests for systems where echo -e is not available.
details: http://hg.nginx.org/njs/rev/f3ed1e9fa8d2 branches: changeset: 440:f3ed1e9fa8d2 user: Dmitry Volyntsevdate: Fri Feb 09 20:34:44 2018 +0300 description: Fixed expect tests for systems where echo -e is not available. diffstat: njs/test/njs_expect_test.exp | 6 ++ njs/test/non_utf8| 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diffs (35 lines): diff -r 0a9fbf9e925f -r f3ed1e9fa8d2 njs/test/njs_expect_test.exp --- a/njs/test/njs_expect_test.exp Fri Feb 09 20:12:41 2018 +0300 +++ b/njs/test/njs_expect_test.exp Fri Feb 09 20:34:44 2018 +0300 @@ -196,8 +196,6 @@ set file [open njs_test_file w] puts -nonewline $file "αβZγ" flush $file -exec /bin/echo -ne {\x80\x80} > njs_test_file_non_utf8 - njs_test { {"var fs = require('fs')\r\n" "undefined\r\n>> "} @@ -277,14 +275,14 @@ njs_test { njs_test { {"var fs = require('fs')\r\n" "undefined\r\n>> "} -{"fs.readFileSync('njs_test_file_non_utf8').charCodeAt(1)\r\n" +{"fs.readFileSync('./njs/test/non_utf8').charCodeAt(1)\r\n" "128"} } njs_test { {"var fs = require('fs')\r\n" "undefined\r\n>> "} -{"fs.readFileSync('njs_test_file_non_utf8', 'utf8')\r\n" +{"fs.readFileSync('./njs/test/non_utf8', 'utf8')\r\n" "Error: Non-UTF8 file, convertion is not implemented"} } diff -r 0a9fbf9e925f -r f3ed1e9fa8d2 njs/test/non_utf8 --- /dev/null Thu Jan 01 00:00:00 1970 + +++ b/njs/test/non_utf8 Fri Feb 09 20:34:44 2018 +0300 @@ -0,0 +1,1 @@ + \ No newline at end of file ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Fixed Object's methods for the undefined value.
details: http://hg.nginx.org/njs/rev/0a9fbf9e925f branches: changeset: 439:0a9fbf9e925f user: Dmitry Volyntsevdate: Fri Feb 09 20:12:41 2018 +0300 description: Fixed Object's methods for the undefined value. diffstat: njs/njs_object.c | 24 njs/test/njs_unit_test.c | 40 2 files changed, 44 insertions(+), 20 deletions(-) diffs (166 lines): diff -r 03eebf0e08cc -r 0a9fbf9e925f njs/njs_object.c --- a/njs/njs_object.c Fri Feb 09 20:11:17 2018 +0300 +++ b/njs/njs_object.c Fri Feb 09 20:12:41 2018 +0300 @@ -741,8 +741,8 @@ njs_object_freeze(njs_vm_t *vm, njs_valu nxt_lvlhsh_each_t lhe; if (nargs < 2 || !njs_is_object([1])) { -njs_exception_type_error(vm, NULL, NULL); -return NXT_ERROR; +vm->retval = njs_value_void; +return NXT_OK; } object = args[1].data.u.object; @@ -780,8 +780,8 @@ njs_object_is_frozen(njs_vm_t *vm, njs_v const njs_value_t *retval; if (nargs < 2 || !njs_is_object([1])) { -njs_exception_type_error(vm, NULL, NULL); -return NXT_ERROR; +vm->retval = njs_string_true; +return NXT_OK; } retval = _string_false; @@ -827,8 +827,8 @@ njs_object_seal(njs_vm_t *vm, njs_value_ nxt_lvlhsh_each_t lhe; if (nargs < 2 || !njs_is_object([1])) { -njs_exception_type_error(vm, NULL, NULL); -return NXT_ERROR; +vm->retval = (nargs < 2) ? njs_value_void : args[1]; +return NXT_OK; } object = args[1].data.u.object; @@ -865,8 +865,8 @@ njs_object_is_sealed(njs_vm_t *vm, njs_v const njs_value_t *retval; if (nargs < 2 || !njs_is_object([1])) { -njs_exception_type_error(vm, NULL, NULL); -return NXT_ERROR; +vm->retval = njs_string_true; +return NXT_OK; } retval = _string_false; @@ -907,8 +907,8 @@ njs_object_prevent_extensions(njs_vm_t * njs_index_t unused) { if (nargs < 2 || !njs_is_object([1])) { -njs_exception_type_error(vm, NULL, NULL); -return NXT_ERROR; +vm->retval = (nargs < 2) ? njs_value_void : args[1]; +return NXT_OK; } args[1].data.u.object->extensible = 0; @@ -926,8 +926,8 @@ njs_object_is_extensible(njs_vm_t *vm, n const njs_value_t *retval; if (nargs < 2 || !njs_is_object([1])) { -njs_exception_type_error(vm, NULL, NULL); -return NXT_ERROR; +vm->retval = njs_string_false; +return NXT_OK; } retval = args[1].data.u.object->extensible ? _string_true diff -r 03eebf0e08cc -r 0a9fbf9e925f njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Fri Feb 09 20:11:17 2018 +0300 +++ b/njs/test/njs_unit_test.c Fri Feb 09 20:12:41 2018 +0300 @@ -6433,6 +6433,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("Object.defineProperties(Object.freeze({}), {b:{}})"), nxt_string("TypeError") }, +{ nxt_string("Object.freeze()"), + nxt_string("undefined") }, + { nxt_string("var o = Object.freeze({a:1}); o.a = 2; o.a"), nxt_string("1") }, @@ -6535,11 +6538,14 @@ static njs_unit_test_t njs_test[] = { nxt_string("Object.isFrozen(new RegExp(''))"), nxt_string("false") }, +{ nxt_string("Object.isFrozen()"), + nxt_string("true") }, + { nxt_string("Object.isFrozen(1)"), - nxt_string("TypeError") }, + nxt_string("true") }, { nxt_string("Object.isFrozen('')"), - nxt_string("TypeError") }, + nxt_string("true") }, { nxt_string("Object.isFrozen(Object.defineProperties({}, {a:{value:1}}))"), nxt_string("false") }, @@ -6586,11 +6592,14 @@ static njs_unit_test_t njs_test[] = { nxt_string("var o = Object.seal({a:{b:1}}); o.a.b = 2; o.a.b"), nxt_string("2") }, +{ nxt_string("Object.seal()"), + nxt_string("undefined") }, + { nxt_string("Object.seal(1)"), - nxt_string("TypeError") }, + nxt_string("1") }, { nxt_string("Object.seal('')"), - nxt_string("TypeError") }, + nxt_string("") }, { nxt_string("Object.isSealed({a:1})"), nxt_string("false") }, @@ -6607,11 +6616,14 @@ static njs_unit_test_t njs_test[] = { nxt_string("Object.isSealed(new RegExp(''))"), nxt_string("false") }, +{ nxt_string("Object.isSealed()"), + nxt_string("true") }, + { nxt_string("Object.isSealed(1)"), - nxt_string("TypeError") }, + nxt_string("true") }, { nxt_string("Object.isSealed('')"), - nxt_string("TypeError") }, + nxt_string("true") }, { nxt_string("Object.isSealed(Object.defineProperties({}, {a:{value:1}}))"), nxt_string("false") }, @@ -6660,6 +6672,15 @@ static njs_unit_test_t njs_test[] = { nxt_string("var o = Object.preventExtensions({a:1}); o.b = 1; o.b"), nxt_string("undefined") }, +{ nxt_string("Object.preventExtensions()"), +
[njs] Fixed the calculation of the scope indices for variables.
details: http://hg.nginx.org/njs/rev/03eebf0e08cc branches: changeset: 438:03eebf0e08cc user: Dmitry Volyntsevdate: Fri Feb 09 20:11:17 2018 +0300 description: Fixed the calculation of the scope indices for variables. diffstat: njs/njs_parser.h | 14 +--- njs/njs_variable.c | 80 +-- njs/test/njs_unit_test.c | 21 3 files changed, 93 insertions(+), 22 deletions(-) diffs (221 lines): diff -r 05605a9f0ad7 -r 03eebf0e08cc njs/njs_parser.h --- a/njs/njs_parser.h Fri Feb 09 19:16:19 2018 +0300 +++ b/njs/njs_parser.h Fri Feb 09 20:11:17 2018 +0300 @@ -235,11 +235,15 @@ struct njs_parser_scope_s { nxt_lvlhsh_tvariables; nxt_lvlhsh_treferences; -nxt_array_t *values[2]; /* Array of njs_value_t. */ +/* + * 0: local scope index; + * 1: closure scope index. + */ +nxt_array_t *values[2]; /* Array of njs_value_t. */ njs_index_t next_index[2]; njs_scope_t type:8; -uint8_t nesting;/* 4 bits */ +uint8_t nesting; /* 4 bits */ uint8_t argument_closures; }; @@ -248,9 +252,9 @@ typedef struct njs_parser_node_snjs_ struct njs_parser_node_s { njs_token_t token:16; -uint8_t ctor:1; /* 1 bit */ -uint8_t temporary; /* 1 bit */ -uint8_t reference; /* 1 bit */ +uint8_t ctor:1; /* 1 bit */ +uint8_t temporary; /* 1 bit */ +uint8_t reference; /* 1 bit */ uint32_ttoken_line; uint32_tvariable_name_hash; diff -r 05605a9f0ad7 -r 03eebf0e08cc njs/njs_variable.c --- a/njs/njs_variable.cFri Feb 09 19:16:19 2018 +0300 +++ b/njs/njs_variable.cFri Feb 09 20:11:17 2018 +0300 @@ -223,15 +223,17 @@ njs_variable_reference(njs_vm_t *vm, njs } -njs_ret_t -njs_variables_scope_reference(njs_vm_t *vm, njs_parser_scope_t *scope) +static njs_ret_t +njs_variables_scope_resolve(njs_vm_t *vm, njs_parser_scope_t *scope, +nxt_bool_t local_scope) { -njs_ret_t ret; -nxt_queue_t *nested; -njs_variable_t *var; -nxt_queue_link_t*lnk; -njs_parser_node_t *node; -nxt_lvlhsh_each_t lhe; +njs_ret_t ret; +nxt_queue_t *nested; +njs_variable_t*var; +nxt_queue_link_t *lnk; +njs_parser_node_t *node; +nxt_lvlhsh_each_t lhe; +njs_variable_scope_t vs; nested = >nested; @@ -241,7 +243,7 @@ njs_variables_scope_reference(njs_vm_t * { scope = nxt_queue_link_data(lnk, njs_parser_scope_t, link); -ret = njs_variables_scope_reference(vm, scope); +ret = njs_variables_scope_resolve(vm, scope, local_scope); if (nxt_slow_path(ret != NXT_OK)) { return NXT_ERROR; } @@ -255,6 +257,25 @@ njs_variables_scope_reference(njs_vm_t * break; } +if (!local_scope) { +ret = njs_variable_find(vm, node, ); +if (nxt_slow_path(ret != NXT_OK)) { +continue; +} + +if (vs.scope->type == NJS_SCOPE_GLOBAL) { +continue; +} + +if (node->scope->nesting == vs.scope->nesting) { +/* + * A variable is referenced locally here, but may be + * referenced non-locally in other places, skipping. + */ +continue; +} +} + var = njs_variable_get(vm, node); if (nxt_slow_path(var == NULL)) { return NXT_ERROR; @@ -266,6 +287,31 @@ njs_variables_scope_reference(njs_vm_t * } +njs_ret_t +njs_variables_scope_reference(njs_vm_t *vm, njs_parser_scope_t *scope) +{ +njs_ret_t ret; + +/* + * Calculating proper scope types for variables. + * A variable is considered to be local variable if it is referenced + * only in the local scope (reference and definition nestings are the same). + */ + +ret = njs_variables_scope_resolve(vm, scope, 0); +if (nxt_slow_path(ret != NXT_OK)) { +return NXT_ERROR; +} + +ret = njs_variables_scope_resolve(vm, scope, 1); +if (nxt_slow_path(ret != NXT_OK)) { +return NXT_ERROR; +} + +return NXT_OK; +} + + njs_index_t njs_variable_typeof(njs_vm_t *vm, njs_parser_node_t *node) { @@ -309,7 +355,7 @@ njs_variable_t * njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node) { nxt_int_t ret; -nxt_uint_t
Re: Permanent structure to accumulate data
Unfortunately, the question is ambiguous. You can put it into the structure, you initialized `mycf = ngx_pcalloc(cf->pool, size)`, where cf is `ngx_conf_t *cf`, if you want to save it per location. Then you can get it in the handler, using `mycf = ngx_http_get_module_loc_conf(r, ngx_http_your_module);`... There are many another places, where you can put it. E. g. just as static variable like `static int var`, so valid per module-scope. But you should provide more info what exactly you want do. For example another issue may be also multiple-workers at all (that are processes, not the threads in nginx), so if it should be exactly one counter across all workers, then you should put it into the shared memory (or somewhere in shared pools, using ngx_slab_alloc functions). The good example would be own nginx module "ngx_http_limit_conn_module". Because otherwise, each worker will just get its own counter. Regards, Serg. Am 09.02.2018 17:31, schrieb Antonio Nappa: > Hello, > > I am looking for a structure that I can use to store a counter in the module, > this structure should not be reset every time there is a new request. > > I have made tests with the module custom ctx and the module custom srv > configuration without success, which means every time there is a new request > the field becomes zero. > > Thanks, Antonio > > ___ > nginx-devel mailing list > nginx-devel@nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel [1] Links: -- [1] http://mailman.nginx.org/mailman/listinfo/nginx-devel ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
Permanent structure to accumulate data
Hello, I am looking for a structure that I can use to store a counter in the module, this structure should not be reset every time there is a new request. I have made tests with the module custom ctx and the module custom srv configuration without success, which means every time there is a new request the field becomes zero. Thanks, Antonio ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Interactive shell: fixed non-ascii character support.
details: http://hg.nginx.org/njs/rev/05605a9f0ad7 branches: changeset: 437:05605a9f0ad7 user: Dmitry Volyntsevdate: Fri Feb 09 19:16:19 2018 +0300 description: Interactive shell: fixed non-ascii character support. diffstat: njs/njs.c| 3 +++ njs/test/njs_expect_test.exp | 8 2 files changed, 11 insertions(+), 0 deletions(-) diffs (38 lines): diff -r 624f79e326d5 -r 05605a9f0ad7 njs/njs.c --- a/njs/njs.c Fri Feb 09 19:16:18 2018 +0300 +++ b/njs/njs.c Fri Feb 09 19:16:19 2018 +0300 @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -459,6 +460,8 @@ njs_editline_init(njs_vm_t *vm) rl_attempted_completion_function = njs_completion_handler; rl_basic_word_break_characters = (char *) " \t\n\"\\'`@$><=;,|&{("; +setlocale(LC_ALL, ""); + njs_completion.completions = njs_vm_completions(vm, NULL); if (njs_completion.completions == NULL) { return NXT_ERROR; diff -r 624f79e326d5 -r 05605a9f0ad7 njs/test/njs_expect_test.exp --- a/njs/test/njs_expect_test.exp Fri Feb 09 19:16:18 2018 +0300 +++ b/njs/test/njs_expect_test.exp Fri Feb 09 19:16:19 2018 +0300 @@ -182,6 +182,14 @@ njs_test { "JSON.parse(Error()\r\nSyntaxError: Unexpected token \"\" in 1"} } +# Non-ASCII characters +njs_test { +{"'絵文字'\r\n" + "絵文字"} +{"var v = 'абвгдеёжзийкл';v[10]\r\n" + "й"} +} + # require('fs') set file [open njs_test_file w] ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Reporting njs version by CLI.
details: http://hg.nginx.org/njs/rev/624f79e326d5 branches: changeset: 436:624f79e326d5 user: Dmitry Volyntsevdate: Fri Feb 09 19:16:18 2018 +0300 description: Reporting njs version by CLI. diffstat: njs/njs.c| 14 -- njs/test/njs_expect_test.exp | 5 ++--- 2 files changed, 14 insertions(+), 5 deletions(-) diffs (67 lines): diff -r 2f266ec441c3 -r 624f79e326d5 njs/njs.c --- a/njs/njs.c Fri Feb 09 19:16:18 2018 +0300 +++ b/njs/njs.c Fri Feb 09 19:16:18 2018 +0300 @@ -41,6 +41,7 @@ typedef enum { typedef struct { char*file; +nxt_int_t version; nxt_int_t disassemble; nxt_int_t interactive; } njs_opts_t; @@ -137,6 +138,11 @@ main(int argc, char **argv) return (ret == NXT_DONE) ? EXIT_SUCCESS : EXIT_FAILURE; } +if (opts.version != 0) { +printf("%s\n", NJS_VERSION); +return EXIT_SUCCESS; +} + mcp = nxt_mem_cache_pool_create(_vm_mem_cache_pool_proto, NULL, NULL, 2 * nxt_pagesize(), 128, 512, 16); if (nxt_slow_path(mcp == NULL)) { @@ -189,6 +195,10 @@ njs_get_options(njs_opts_t *opts, int ar opts->disassemble = 1; break; +case 'V': +opts->version = 1; +break; + default: fprintf(stderr, "Unknown argument: \"%s\"\n", argv[i]); ret = NXT_ERROR; @@ -197,7 +207,7 @@ njs_get_options(njs_opts_t *opts, int ar case 'h': case '?': -printf("Usage: %s [|-] [-d]\n", argv[0]); +printf("Usage: %s [|-] [-dV]\n", argv[0]); return ret; } } @@ -254,7 +264,7 @@ njs_interactive_shell(njs_opts_t *opts, return NXT_ERROR; } -printf("interactive njscript\n\n"); +printf("interactive njscript %s\n\n", NJS_VERSION); printf("v. -> the properties and prototype methods of v.\n"); printf("type console.help() for more information\n\n"); diff -r 2f266ec441c3 -r 624f79e326d5 njs/test/njs_expect_test.exp --- a/njs/test/njs_expect_test.exp Fri Feb 09 19:16:18 2018 +0300 +++ b/njs/test/njs_expect_test.exp Fri Feb 09 19:16:18 2018 +0300 @@ -5,9 +5,8 @@ proc njs_test {body} { spawn -nottycopy njs -expect "interactive njscript\r -\r -v. -> the properties and prototype methods of v.\r +expect -re "interactive njscript \\d+\.\\d+\.\\d+\r\n\r" +expect "v. -> the properties and prototype methods of v.\r type console.help() for more information\r \r >> " ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Using hg archive to make dist.
details: http://hg.nginx.org/njs/rev/2f266ec441c3 branches: changeset: 435:2f266ec441c3 user: Dmitry Volyntsevdate: Fri Feb 09 19:16:18 2018 +0300 description: Using hg archive to make dist. diffstat: Makefile | 14 ++ njs/njscript.h | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-) diffs (40 lines): diff -r c69b48375b90 -r 2f266ec441c3 Makefile --- a/Makefile Wed Nov 22 20:38:10 2017 +0300 +++ b/Makefile Fri Feb 09 19:16:18 2018 +0300 @@ -1,5 +1,3 @@ - -NJS_VER = 0.1.15 NXT_LIB = nxt @@ -100,12 +98,12 @@ clean: rm -f $(NXT_LIB)/Makefile.conf $(NXT_LIB)/nxt_auto_config.h dist: - make clean - mkdir njs-$(NJS_VER) - cp -rp configure Makefile LICENSE README CHANGES $(NXT_LIB) njs nginx \ - njs-$(NJS_VER) - tar czf njs-$(NJS_VER).tar.gz njs-$(NJS_VER) - rm -rf njs-$(NJS_VER) + NJS_VER=`grep NJS_VERSION njs/njscript.h | sed -e 's/.*"\(.*\)".*/\1/'`; \ + rm -rf njs-$${NJS_VER} \ + && hg archive njs-$${NJS_VER}.tar.gz \ + -p njs-$${NJS_VER} \ + -X ".hg*" \ + && echo njs-$${NJS_VER}.tar.gz done $(NXT_LIB)/nxt_auto_config.h: @echo diff -r c69b48375b90 -r 2f266ec441c3 njs/njscript.h --- a/njs/njscript.hWed Nov 22 20:38:10 2017 +0300 +++ b/njs/njscript.hFri Feb 09 19:16:18 2018 +0300 @@ -7,6 +7,8 @@ #ifndef _NJSCRIPT_H_INCLUDED_ #define _NJSCRIPT_H_INCLUDED_ +#define NJS_VERSION "0.1.15" + typedef intptr_tnjs_ret_t; typedef uintptr_t njs_index_t; ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
Re: [PATCH] HTTP/2: copy additional headers in the pushed requests
Hello! On Thu, Feb 08, 2018 at 08:56:31PM +, Piotr Sikora via nginx-devel wrote: > Hi Ruslan, > > > http header: "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) > AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36" > > http header: "Accept: > text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8" > > http header: "Accept-Encoding: gzip, deflate, br" > > http header: "Accept-Language: > ru,en-US;q=0.9,en;q=0.8,zh-TW;q=0.7,zh;q=0.6" > > (...) > > http header: "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) > AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36" > > http header: "Accept: image/webp,image/apng,image/*,*/*;q=0.8" > > http header: "Accept-Encoding: gzip, deflate, br" > > http header: "Accept-Language: > ru,en-US;q=0.9,en;q=0.8,zh-TW;q=0.7,zh;q=0.6" > > > http header: "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; > rv:52.0) Gecko/20100101 Firefox/52.0" > > http header: "Accept: > text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" > > http header: "Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3" > > http header: "Accept-Encoding: gzip, deflate" > > (...) > > http header: "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; > rv:52.0) Gecko/20100101 Firefox/52.0" > > http header: "Accept: */*" > > http header: "Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3" > > http header: "Accept-Encoding: gzip, deflate" > > In both examples, User-Agent, Accept-Encoding and Accept-Language are the > same, and Accept is (an extension-specific?) subset of the "/" request, > which proves that this is in fact a good idea. In both examples Accept headers are different, and this can easily result in different responses if content negotiation is used. I don't see how it proves anything but the fact that content negotiation should be avoided when using HTTP/2 push. -- Maxim Dounin http://mdounin.ru/ ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel