[njs] Fixed Function constructor in CLI.
Dmitry Volyntsev
xeioex at nginx.com
Mon Feb 14 14:28:31 UTC 2022
details: https://hg.nginx.org/njs/rev/4e045c33a32e
branches:
changeset: 1825:4e045c33a32e
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Mon Feb 14 14:10:47 2022 +0000
description:
Fixed Function constructor in CLI.
Previously, Function constructor exported its local variables to
vm->variables_hash. vm->variables_hash is used in njs CLI to query
global variables during console input completion. The exporting is
incorrect because it pollutes the global scope.
diffstat:
src/njs_function.c | 11 ++---------
src/njs_variable.c | 29 -----------------------------
src/njs_variable.h | 2 --
3 files changed, 2 insertions(+), 40 deletions(-)
diffs (85 lines):
diff -r 040d1b318a15 -r 4e045c33a32e src/njs_function.c
--- a/src/njs_function.c Mon Feb 14 14:10:26 2022 +0000
+++ b/src/njs_function.c Mon Feb 14 14:10:47 2022 +0000
@@ -1109,7 +1109,6 @@ njs_function_constructor(njs_vm_t *vm, n
njs_function_t *function;
njs_generator_t generator;
njs_parser_node_t *node;
- njs_parser_scope_t *scope;
njs_function_lambda_t *lambda;
const njs_token_type_t *type;
@@ -1215,20 +1214,14 @@ njs_function_constructor(njs_vm_t *vm, n
}
}
- scope = parser.scope;
-
- ret = njs_variables_copy(vm, &scope->variables, vm->variables_hash);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
-
ret = njs_generator_init(&generator, 0, 1);
if (njs_slow_path(ret != NJS_OK)) {
njs_internal_error(vm, "njs_generator_init() failed");
return NJS_ERROR;
}
- code = njs_generate_scope(vm, &generator, scope, &njs_entry_anonymous);
+ code = njs_generate_scope(vm, &generator, parser.scope,
+ &njs_entry_anonymous);
if (njs_slow_path(code == NULL)) {
if (!njs_is_error(&vm->retval)) {
njs_internal_error(vm, "njs_generate_scope() failed");
diff -r 040d1b318a15 -r 4e045c33a32e src/njs_variable.c
--- a/src/njs_variable.c Mon Feb 14 14:10:26 2022 +0000
+++ b/src/njs_variable.c Mon Feb 14 14:10:47 2022 +0000
@@ -106,35 +106,6 @@ njs_variable_scope_function_add(njs_pars
}
-
-njs_int_t
-njs_variables_copy(njs_vm_t *vm, njs_rbtree_t *variables,
- njs_rbtree_t *prev_variables)
-{
- njs_rbtree_node_t *node;
- njs_variable_node_t *var_node;
-
- node = njs_rbtree_min(prev_variables);
-
- while (njs_rbtree_is_there_successor(prev_variables, node)) {
- var_node = (njs_variable_node_t *) node;
-
- var_node = njs_variable_node_alloc(vm, var_node->variable,
- var_node->key);
- if (njs_slow_path(var_node == NULL)) {
- njs_memory_error(vm);
- return NJS_ERROR;
- }
-
- njs_rbtree_insert(variables, &var_node->node);
-
- node = njs_rbtree_node_successor(prev_variables, node);
- }
-
- return NJS_OK;
-}
-
-
static njs_parser_scope_t *
njs_variable_scope(njs_parser_scope_t *scope, uintptr_t unique_id,
njs_variable_t **retvar, njs_variable_type_t type)
diff -r 040d1b318a15 -r 4e045c33a32e src/njs_variable.h
--- a/src/njs_variable.h Mon Feb 14 14:10:26 2022 +0000
+++ b/src/njs_variable.h Mon Feb 14 14:10:47 2022 +0000
@@ -63,8 +63,6 @@ njs_variable_t *njs_variable_add(njs_par
njs_parser_scope_t *scope, uintptr_t unique_id, njs_variable_type_t type);
njs_variable_t *njs_variable_function_add(njs_parser_t *parser,
njs_parser_scope_t *scope, uintptr_t unique_id, njs_variable_type_t type);
-njs_int_t njs_variables_copy(njs_vm_t *vm, njs_rbtree_t *variables,
- njs_rbtree_t *prev_variables);
njs_variable_t * njs_label_add(njs_vm_t *vm, njs_parser_scope_t *scope,
uintptr_t unique_id);
njs_variable_t *njs_label_find(njs_vm_t *vm, njs_parser_scope_t *scope,
More information about the nginx-devel
mailing list