From f6b658a4dbc27d758d5ceff20911c3339f61d79e Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Thu, 5 Jan 2017 15:55:49 +0300 Subject: [PATCH] Functions were not exported. The bug was introduced in 4337ed48d6d6. --- 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(-) diff --git a/njs/njs_generator.c b/njs/njs_generator.c index 2fe7236e..805159cb 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -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 --git a/njs/njs_parser.c b/njs/njs_parser.c index 512251df..8fb2c182 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -383,6 +383,7 @@ njs_parser_match(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token, 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 *vm, njs_parser_t *parser) 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 *vm, njs_parser_t *parser) 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 --git a/njs/njs_variable.c b/njs/njs_variable.c index 0a61f26e..9a5e5947 100644 --- a/njs/njs_variable.c +++ b/njs/njs_variable.c @@ -439,8 +439,7 @@ njs_vm_function(njs_vm_t *vm, nxt_str_t *name) 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 --git a/njs/njscript.c b/njs/njscript.c index a5501182..884c9e00 100644 --- a/njs/njscript.c +++ b/njs/njscript.c @@ -190,6 +190,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end, 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 **start, u_char *end, 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 **start, u_char *end, vm->global_scope = parser->local_scope; vm->scope_size = parser->scope_size; + vm->variables_hash = parser->scope->variables; vm->parser = NULL; -- 2.47.3