lambda->nlocal = node->scope->items;
lambda->temp = node->scope->temp;
- if (node->scope->declarations != NULL) {
- arr = node->scope->declarations;
- lambda->declarations = arr->start;
- lambda->ndeclarations = arr->items;
- }
+ arr = node->scope->declarations;
+ lambda->declarations = (arr != NULL) ? arr->start : NULL;
+ lambda->ndeclarations = (arr != NULL) ? arr->items : 0;
return NJS_OK;
}
return NULL;
}
- if (var->index == NJS_INDEX_ERROR || !var->function) {
- root = njs_function_scope(scope);
- if (njs_slow_path(scope == NULL)) {
- return NULL;
- }
+ root = njs_function_scope(scope);
+ if (njs_slow_path(scope == NULL)) {
+ return NULL;
+ }
- ctor = parser->node->token_type != NJS_TOKEN_ASYNC_FUNCTION_DECLARATION;
+ ctor = parser->node->token_type != NJS_TOKEN_ASYNC_FUNCTION_DECLARATION;
- lambda = njs_function_lambda_alloc(parser->vm, ctor);
- if (lambda == NULL) {
- return NULL;
- }
+ lambda = njs_function_lambda_alloc(parser->vm, ctor);
+ if (lambda == NULL) {
+ return NULL;
+ }
- var->value.data.u.lambda = lambda;
+ njs_set_invalid(&var->value);
+ var->value.data.u.lambda = lambda;
- declr = njs_variable_scope_function_add(parser, root);
- if (njs_slow_path(declr == NULL)) {
- return NULL;
- }
+ declr = njs_variable_scope_function_add(parser, root);
+ if (njs_slow_path(declr == NULL)) {
+ return NULL;
+ }
- var->index = njs_scope_index(root->type, root->items, NJS_LEVEL_LOCAL,
- type);
+ var->index = njs_scope_index(root->type, root->items, NJS_LEVEL_LOCAL,
+ type);
- declr->value = &var->value;
- declr->index = var->index;
+ declr->value = &var->value;
+ declr->index = var->index;
- root->items++;
- }
+ root->items++;
var->type = NJS_VARIABLE_FUNCTION;
var->function = 1;
"myFoo(1,2);" ),
njs_str("") },
+ { njs_str("function f(...rest) {};"
+ "function f(a, b) {return a + b};"
+ "f(1,2)"),
+ njs_str("3") },
+
+ { njs_str("function f() { function q() {} };"
+ "function f() { };"
+ "f()"),
+ njs_str("undefined") },
+
/* arrow functions. */
{ njs_str("()"),