From: Dmitry Volyntsev Date: Wed, 17 May 2023 07:39:56 +0000 (-0700) Subject: Fixed implicit name for a function expression declared in arrays. X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=417dd4ebf897d3f5cb06bb2f6fd72730d996700a;p=njs.git Fixed implicit name for a function expression declared in arrays. --- diff --git a/src/njs_generator.c b/src/njs_generator.c index b8f4e44d..6a47dc11 100644 --- a/src/njs_generator.c +++ b/src/njs_generator.c @@ -3235,9 +3235,12 @@ njs_generate_assignment_end(njs_vm_t *vm, njs_generator_t *generator, switch (lvalue->token_type) { case NJS_TOKEN_PROPERTY_INIT: - if ((expr->token_type == NJS_TOKEN_FUNCTION - || expr->token_type == NJS_TOKEN_FUNCTION_EXPRESSION - || expr->token_type == NJS_TOKEN_ASYNC_FUNCTION_EXPRESSION)) + if ((object->token_type == NJS_TOKEN_OBJECT + || (object->token_type == NJS_TOKEN_OBJECT_VALUE + && object->u.object->token_type == NJS_TOKEN_OBJECT)) + && (expr->token_type == NJS_TOKEN_FUNCTION + || expr->token_type == NJS_TOKEN_FUNCTION_EXPRESSION + || expr->token_type == NJS_TOKEN_ASYNC_FUNCTION_EXPRESSION)) { if (property->token_type == NJS_TOKEN_STRING) { njs_value_assign(&expr->u.value.data.u.lambda->name, diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index aca3a520..c8a70d2c 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -3925,6 +3925,9 @@ static njs_unit_test_t njs_test[] = { njs_str("var obj = {}; ({[obj](){}}); typeof obj"), njs_str("object") }, + { njs_str("[function(){}][0].name"), + njs_str("") }, + { njs_str("var called = false;" "({" " [{toString(){ if (called) throw 'OOps'; called = true; return 'a'}}](){}"