Skip to content

Commit

Permalink
Fixed Function constructor handling when called without arguments.
Browse files Browse the repository at this point in the history
Corrected the behavior of Function.constructor() when invoked without arguments
relative to an object.
  • Loading branch information
VadimZhestikov authored and xeioex committed Jul 6, 2024
1 parent 7dda4b2 commit b593dd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/njs_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "})");
Expand Down
3 changes: 3 additions & 0 deletions src/test/njs_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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") },

Expand Down

0 comments on commit b593dd4

Please sign in to comment.