Welcome! Log In Create A New Profile

Advanced

[njs] Fixed Function constructor handling when called without arguments.

Anonymous User
July 05, 2024 09:30PM
details: https://github.com/nginx/njs/commit/b593dd4aba0f5c730c1d90072cdee7dd9a93beed
branches: master
commit: b593dd4aba0f5c730c1d90072cdee7dd9a93beed
user: Vadim Zhestikov <v.zhestikov@f5.com>
date: Tue, 2 Jul 2024 14:55:03 -0700
description:
Fixed Function constructor handling when called without arguments.

Corrected the behavior of Function.constructor() when invoked without arguments
relative to an object.

---
src/njs_function.c | 8 +++++---
src/test/njs_unit_test.c | 3 +++
2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/njs_function.c b/src/njs_function.c
index bfdf3f35..c677be57 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 530cf6ff..2f0e318c 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") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed Function constructor handling when called without arguments.

Anonymous User 128 July 05, 2024 09:30PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 184
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready