]> git.kaiwu.me - njs.git/commitdiff
Functions were not exported.
authorIgor Sysoev <igor@sysoev.ru>
Thu, 5 Jan 2017 12:55:49 +0000 (15:55 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Thu, 5 Jan 2017 12:55:49 +0000 (15:55 +0300)
The bug was introduced in 4337ed48d6d6.

njs/njs_generator.c
njs/njs_parser.c
njs/njs_variable.c
njs/njscript.c

index 2fe7236e286b0cb6b5595e0824bca60c1fe4c1fa..805159cb3516b4b1fc4141abf574f21bc1fca595 100644 (file)
@@ -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);
 }
index 512251dffd30758fffc023db45731ef64d42369e..8fb2c18216f343bdcd2036e9e27297a45efdbec2 100644 (file)
@@ -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;
index 0a61f26ee2f9dfea8253ad2b58d9f07d9bb89db0..9a5e59475526173336f6e36f8bfbae20b047fbbb 100644 (file)
@@ -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;
index a550118254ef861be61145b9d66d47d16b4fd2e7..884c9e006c6e64046413c731c0ec53882eed9225 100644 (file)
@@ -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;