Welcome! Log In Create A New Profile

Advanced

[njs] Trailer content after script is optional.

July 17, 2017 07:54AM
details: http://hg.nginx.org/njs/rev/bef6842774f6
branches:
changeset: 386:bef6842774f6
user: Igor Sysoev <igor@sysoev.ru>
date: Mon Jul 17 14:46:35 2017 +0300
description:
Trailer content after script is optional.

diffstat:

njs/njs_parser.c | 16 ++++++++++++----
njs/njs_vm.h | 2 ++
njs/njscript.c | 2 ++
njs/njscript.h | 2 ++
njs/test/njs_unit_test.c | 10 ++++++++--
5 files changed, 26 insertions(+), 6 deletions(-)

diffs (110 lines):

diff -r 0ad7f75f9dbf -r bef6842774f6 njs/njs_parser.c
--- a/njs/njs_parser.c Fri Jul 07 19:17:26 2017 +0300
+++ b/njs/njs_parser.c Mon Jul 17 14:46:35 2017 +0300
@@ -115,7 +115,7 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p
return NULL;
}

- if (token == NJS_TOKEN_CLOSE_BRACE) {
+ if (token == NJS_TOKEN_CLOSE_BRACE && vm->trailer) {
parser->lexer->start--;
break;
}
@@ -332,9 +332,13 @@ njs_parser_statement(njs_vm_t *vm, njs_p
return njs_parser_block_statement(vm, parser);

case NJS_TOKEN_CLOSE_BRACE:
- parser->node = NULL;
- nxt_thread_log_debug("BLOCK END");
- return token;
+ if (vm->trailer) {
+ parser->node = NULL;
+ nxt_thread_log_debug("BLOCK END");
+ return token;
+ }
+
+ /* Fall through. */

default:
token = njs_parser_expression(vm, parser, token);
@@ -1043,6 +1047,10 @@ njs_parser_switch_statement(njs_vm_t *vm

parser->node = NULL;

+ if (token == NJS_TOKEN_CLOSE_BRACE) {
+ break;
+ }
+
} else if (branch == NULL) {
/* The first switch statment is not "case/default" keyword. */
return NJS_TOKEN_ILLEGAL;
diff -r 0ad7f75f9dbf -r bef6842774f6 njs/njs_vm.h
--- a/njs/njs_vm.h Fri Jul 07 19:17:26 2017 +0300
+++ b/njs/njs_vm.h Mon Jul 17 14:46:35 2017 +0300
@@ -902,6 +902,8 @@ struct njs_vm_s {

nxt_trace_t trace;
nxt_random_t random;
+
+ uint8_t trailer; /* 1 bit */
};


diff -r 0ad7f75f9dbf -r bef6842774f6 njs/njscript.c
--- a/njs/njscript.c Fri Jul 07 19:17:26 2017 +0300
+++ b/njs/njscript.c Mon Jul 17 14:46:35 2017 +0300
@@ -173,6 +173,8 @@ njs_vm_create(njs_vm_opt_t *options)
vm->trace.size = 2048;
vm->trace.handler = njs_parser_trace_handler;
vm->trace.data = vm;
+
+ vm->trailer = options->trailer;
}

return vm;
diff -r 0ad7f75f9dbf -r bef6842774f6 njs/njscript.h
--- a/njs/njscript.h Fri Jul 07 19:17:26 2017 +0300
+++ b/njs/njscript.h Mon Jul 17 14:46:35 2017 +0300
@@ -69,6 +69,8 @@ typedef struct {
nxt_lvlhsh_t *externals;
njs_vm_shared_t *shared;
nxt_mem_cache_pool_t *mcp;
+
+ uint8_t trailer; /* 1 bit */
} njs_vm_opt_t;


diff -r 0ad7f75f9dbf -r bef6842774f6 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Fri Jul 07 19:17:26 2017 +0300
+++ b/njs/test/njs_unit_test.c Mon Jul 17 14:46:35 2017 +0300
@@ -28,6 +28,12 @@ typedef struct {

static njs_unit_test_t njs_test[] =
{
+ { nxt_string("}"),
+ nxt_string("SyntaxError: Unexpected token \"}\" in 1") },
+
+ { nxt_string("1}"),
+ nxt_string("SyntaxError: Unexpected token \"}\" in 1") },
+
/* Variable declarations. */

{ nxt_string("var x"),
@@ -1898,7 +1904,7 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("var a = 3; if (true) if (false); else; a = 2; a"),
nxt_string("2") },

- { nxt_string("var a = [3], b; if (1==1||2==2) { b = '1'+'2'+a[0] }; b }"),
+ { nxt_string("var a = [3], b; if (1==1||2==2) { b = '1'+'2'+a[0] }; b"),
nxt_string("123") },

{ nxt_string("(function(){ if(true) return 1 else return 0; })()"),
@@ -2122,7 +2128,7 @@ static njs_unit_test_t njs_test[] =
nxt_string("10") },

{ nxt_string("var a = [1,2,3,4,5]; var s = 0, i;"
- "for (i in a) if (a[i] > 4) break; s += a[i] } s"),
+ "for (i in a) if (a[i] > 4) break; s += a[i]; s"),
nxt_string("5") },

/**/
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Trailer content after script is optional.

Igor Sysoev 872 July 17, 2017 07:54AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 83
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready