details: https://github.com/nginx/njs/commit/030712507797c42db146c7ee0399a882f47e6ebe branches: master commit: 030712507797c42db146c7ee0399a882f47e6ebe user: Dmitry Volyntsev <xei...@nginx.com> date: Thu, 12 Jun 2025 17:33:35 -0700 description: Parser: simplifed working with function variables.
--- src/njs_builtin.c | 10 ---------- src/njs_function.c | 10 ++-------- src/njs_parser.c | 3 +-- src/njs_value.c | 11 +---------- src/njs_variable.c | 13 ++++++------- src/njs_variable.h | 3 +-- 6 files changed, 11 insertions(+), 39 deletions(-) diff --git a/src/njs_builtin.c b/src/njs_builtin.c index 230b4c1c..c960fe1f 100644 --- a/src/njs_builtin.c +++ b/src/njs_builtin.c @@ -759,7 +759,6 @@ njs_global_this_prop_handler(njs_vm_t *vm, njs_object_prop_t *prop, { njs_value_t *value; njs_variable_t *var; - njs_function_t *function; njs_rbtree_node_t *rb_node; njs_variable_node_t *node, var_node; @@ -788,15 +787,6 @@ njs_global_this_prop_handler(njs_vm_t *vm, njs_object_prop_t *prop, value = njs_scope_valid_value(vm, var->index); - if (var->type == NJS_VARIABLE_FUNCTION && njs_is_undefined(value)) { - njs_value_assign(value, &var->value); - - function = njs_function_value_copy(vm, value); - if (njs_slow_path(function == NULL)) { - return NJS_ERROR; - } - } - if (setval != NULL) { njs_value_assign(value, setval); } diff --git a/src/njs_function.c b/src/njs_function.c index 90a54204..7db342f6 100644 --- a/src/njs_function.c +++ b/src/njs_function.c @@ -934,9 +934,8 @@ njs_function_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop, uint32_t unused, njs_value_t *value, njs_value_t *setval, njs_value_t *retval) { - njs_value_t *proto, proto_value, *cons; - njs_object_t *prototype; - njs_function_t *function; + njs_value_t *proto, proto_value, *cons; + njs_object_t *prototype; if (setval == NULL) { prototype = njs_object_alloc(vm); @@ -949,11 +948,6 @@ njs_function_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop, setval = &proto_value; } - function = njs_function_value_copy(vm, value); - if (njs_slow_path(function == NULL)) { - return NJS_ERROR; - } - proto = njs_function_property_prototype_set(vm, njs_object_hash(value), setval); if (njs_slow_path(proto == NULL)) { diff --git a/src/njs_parser.c b/src/njs_parser.c index 3cd56fdf..de11b8c9 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -7091,8 +7091,7 @@ njs_parser_function_declaration(njs_parser_t *parser, njs_lexer_token_t *token, njs_lexer_consume_token(parser->lexer, 1); - var = njs_variable_function_add(parser, parser->scope, atom_id, - NJS_VARIABLE_FUNCTION); + var = njs_variable_function_add(parser, parser->scope, atom_id); if (var == NULL) { return NJS_ERROR; } diff --git a/src/njs_value.c b/src/njs_value.c index 0c616a37..fe64afe6 100644 --- a/src/njs_value.c +++ b/src/njs_value.c @@ -562,7 +562,6 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *value, uint32_t index; njs_int_t ret; njs_object_t *obj; - njs_function_t *function; njs_assert(atom_id != NJS_ATOM_STRING_unknown); @@ -585,6 +584,7 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *value, case NJS_OBJECT: case NJS_ARRAY: + case NJS_FUNCTION: case NJS_ARRAY_BUFFER: case NJS_DATA_VIEW: case NJS_TYPED_ARRAY: @@ -595,15 +595,6 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *value, obj = njs_object(value); break; - case NJS_FUNCTION: - function = njs_function_value_copy(vm, value); - if (njs_slow_path(function == NULL)) { - return NJS_ERROR; - } - - obj = &function->object; - break; - case NJS_UNDEFINED: case NJS_NULL: default: diff --git a/src/njs_variable.c b/src/njs_variable.c index bdf0d959..b65e5934 100644 --- a/src/njs_variable.c +++ b/src/njs_variable.c @@ -36,7 +36,7 @@ njs_variable_add(njs_parser_t *parser, njs_parser_scope_t *scope, njs_variable_t * njs_variable_function_add(njs_parser_t *parser, njs_parser_scope_t *scope, - uintptr_t atom_id, njs_variable_type_t type) + uintptr_t atom_id) { njs_bool_t ctor; njs_variable_t *var; @@ -44,14 +44,15 @@ njs_variable_function_add(njs_parser_t *parser, njs_parser_scope_t *scope, njs_parser_scope_t *root; njs_function_lambda_t *lambda; - root = njs_variable_scope_find(parser, scope, atom_id, type); + root = njs_variable_scope_find(parser, scope, atom_id, + NJS_VARIABLE_FUNCTION); if (njs_slow_path(root == NULL)) { njs_parser_ref_error(parser, "scope not found"); return NULL; } - var = njs_variable_scope_add(parser, root, scope, atom_id, type, - NJS_INDEX_ERROR); + var = njs_variable_scope_add(parser, root, scope, atom_id, + NJS_VARIABLE_FUNCTION, NJS_INDEX_ERROR); if (njs_slow_path(var == NULL)) { return NULL; } @@ -77,7 +78,7 @@ njs_variable_function_add(njs_parser_t *parser, njs_parser_scope_t *scope, } var->index = njs_scope_index(root->type, root->items, NJS_LEVEL_LOCAL, - type); + NJS_VARIABLE_FUNCTION); declr->lambda = lambda; declr->async = !ctor; @@ -86,7 +87,6 @@ njs_variable_function_add(njs_parser_t *parser, njs_parser_scope_t *scope, root->items++; var->type = NJS_VARIABLE_FUNCTION; - var->function = 1; return var; } @@ -174,7 +174,6 @@ njs_variable_scope_find(njs_parser_t *parser, njs_parser_scope_t *scope, if (var != NULL && var->scope == root) { if (var->self) { - var->function = 0; return scope; } diff --git a/src/njs_variable.h b/src/njs_variable.h index 2ed5220a..db40de75 100644 --- a/src/njs_variable.h +++ b/src/njs_variable.h @@ -26,7 +26,6 @@ typedef struct { njs_bool_t self; njs_bool_t init; njs_bool_t closure; - njs_bool_t function; njs_parser_scope_t *scope; njs_parser_scope_t *original; @@ -62,7 +61,7 @@ typedef struct { njs_variable_t *njs_variable_add(njs_parser_t *parser, njs_parser_scope_t *scope, uintptr_t atom_id, njs_variable_type_t type); njs_variable_t *njs_variable_function_add(njs_parser_t *parser, - njs_parser_scope_t *scope, uintptr_t atom_id, njs_variable_type_t type); + njs_parser_scope_t *scope, uintptr_t atom_id); njs_variable_t * njs_label_add(njs_vm_t *vm, njs_parser_scope_t *scope, uintptr_t atom_id); njs_variable_t *njs_label_find(njs_vm_t *vm, njs_parser_scope_t *scope, _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel