diff --git a/src/njs_function.c b/src/njs_function.c index bfdf3f355..c677be573 100644 --- a/src/njs_function.c +++ b/src/njs_function.c @@ -1054,9 +1054,11 @@ njs_function_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, njs_chb_append_literal(&chain, "){"); - ret = njs_value_to_chain(vm, &chain, njs_argument(args, nargs - 1)); - if (njs_slow_path(ret < NJS_OK)) { - return ret; + if (nargs > 1) { + ret = njs_value_to_chain(vm, &chain, njs_argument(args, nargs - 1)); + if (njs_slow_path(ret < NJS_OK)) { + return ret; + } } njs_chb_append_literal(&chain, "})"); diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 530cf6ff8..2f0e318c4 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -14147,6 +14147,9 @@ static njs_unit_test_t njs_test[] = { njs_str("Function.constructor === Function"), njs_str("true") }, + { njs_str("Function.constructor()"), + njs_str("[object Function]") }, + { njs_str("function f() {} f.__proto__ === Function.prototype"), njs_str("true") },