Welcome! Log In Create A New Profile

Advanced

[njs] Functions were not exported.

January 05, 2017 08:22AM
details: http://hg.nginx.org/njs/rev/c11a7e133205
branches:
changeset: 298:c11a7e133205
user: Igor Sysoev <igor@sysoev.ru>
date: Thu Jan 05 15:55:49 2017 +0300
description:
Functions were not exported.

The bug was introduced in 4337ed48d6d6.

diffstat:

njs/njs_generator.c | 8 +++++++-
njs/njs_parser.c | 8 ++++++--
njs/njs_variable.c | 3 +--
njs/njscript.c | 9 ++++++++-
4 files changed, 22 insertions(+), 6 deletions(-)

diffs (98 lines):

diff -r fe8027493a08 -r c11a7e133205 njs/njs_generator.c
--- a/njs/njs_generator.c Tue Jan 03 19:38:17 2017 +0300
+++ b/njs/njs_generator.c Thu Jan 05 15:55:49 2017 +0300
@@ -1964,9 +1964,15 @@ static nxt_int_t
njs_generate_function_declaration(njs_vm_t *vm, njs_parser_t *parser,
njs_parser_node_t *node)
{
+ njs_variable_t *var;
njs_function_lambda_t *lambda;

- lambda = node->u.value.data.u.function->u.lambda;
+ var = njs_variable_get(vm, node, NJS_NAME_DECLARATION);
+ if (nxt_slow_path(var == NULL)) {
+ return NXT_ERROR;
+ }
+
+ lambda = var->value.data.u.function->u.lambda;

return njs_generate_function_scope(vm, lambda, node);
}
diff -r fe8027493a08 -r c11a7e133205 njs/njs_parser.c
--- a/njs/njs_parser.c Tue Jan 03 19:38:17 2017 +0300
+++ b/njs/njs_parser.c Thu Jan 05 15:55:49 2017 +0300
@@ -383,6 +383,7 @@ njs_parser_match(njs_vm_t *vm, njs_parse
static njs_token_t
njs_parser_function_declaration(njs_vm_t *vm, njs_parser_t *parser)
{
+ njs_ret_t ret;
njs_token_t token;
njs_variable_t *var;
njs_function_t *function;
@@ -409,6 +410,11 @@ njs_parser_function_declaration(njs_vm_t
return NJS_TOKEN_ERROR;
}

+ ret = njs_variable_reference(vm, parser, node);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return NJS_TOKEN_ERROR;
+ }
+
token = njs_parser_token(parser);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
@@ -425,8 +431,6 @@ njs_parser_function_declaration(njs_vm_t
var->value.type = NJS_FUNCTION;
var->value.data.truth = 1;

- node->u.value = var->value;
-
parser = njs_parser_function_create(vm, parser);
if (nxt_slow_path(parser == NULL)) {
return NJS_TOKEN_ERROR;
diff -r fe8027493a08 -r c11a7e133205 njs/njs_variable.c
--- a/njs/njs_variable.c Tue Jan 03 19:38:17 2017 +0300
+++ b/njs/njs_variable.c Thu Jan 05 15:55:49 2017 +0300
@@ -439,8 +439,7 @@ njs_vm_function(njs_vm_t *vm, nxt_str_t

var = lhq.value;

- value = (njs_value_t *) ((u_char *) vm->global_scope
- + njs_offset(var->index) - NJS_INDEX_GLOBAL_OFFSET);
+ value = njs_global_variable_value(vm, var);

if (njs_is_function(value)) {
return value->data.u.function;
diff -r fe8027493a08 -r c11a7e133205 njs/njscript.c
--- a/njs/njscript.c Tue Jan 03 19:38:17 2017 +0300
+++ b/njs/njscript.c Thu Jan 05 15:55:49 2017 +0300
@@ -190,6 +190,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
nxt_int_t ret;
njs_lexer_t *lexer;
njs_parser_t *parser;
+ njs_variable_t *var;
njs_parser_node_t *node;

parser = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_parser_t));
@@ -221,7 +222,12 @@ njs_vm_compile(njs_vm_t *vm, u_char **st

if (function != NULL) {
if (node->token == NJS_TOKEN_CALL) {
- *function = node->right->u.value.data.u.function;
+ var = njs_variable_get(vm, node->right, NJS_NAME_DECLARATION);
+ if (nxt_slow_path(var == NULL)) {
+ return NJS_ERROR;
+ }
+
+ *function = var->value.data.u.function;

} else {
*function = NULL;
@@ -239,6 +245,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st

vm->global_scope = parser->local_scope;
vm->scope_size = parser->scope_size;
+ vm->variables_hash = parser->scope->variables;

vm->parser = NULL;

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

[njs] Functions were not exported.

Igor Sysoev 1053 January 05, 2017 08:22AM



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

Online Users

Guests: 303
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready