[njs] Fixed native frame arguments number.

Dmitry Volyntsev xeioex at nginx.com
Mon Mar 18 13:51:43 UTC 2019


details:   https://hg.nginx.org/njs/rev/8868eed51544
branches:  
changeset: 832:8868eed51544
user:      hongzhidao <hongzhidao at gmail.com>
date:      Mon Mar 18 16:05:27 2019 +0300
description:
Fixed native frame arguments number.

diffstat:

 njs/njs_function.c       |   1 +
 njs/test/njs_unit_test.c |  11 +++++++++++
 2 files changed, 12 insertions(+), 0 deletions(-)

diffs (39 lines):

diff -r 9a87bf103c47 -r 8868eed51544 njs/njs_function.c
--- a/njs/njs_function.c	Sun Mar 17 21:22:30 2019 +0800
+++ b/njs/njs_function.c	Mon Mar 18 16:05:27 2019 +0300
@@ -310,6 +310,7 @@ njs_function_lambda_frame(njs_vm_t *vm, 
 
     } else {
         n = function->args_offset;
+        native_frame->nargs += n - 1;
 
         do {
             *value++ = *bound++;
diff -r 9a87bf103c47 -r 8868eed51544 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Sun Mar 17 21:22:30 2019 +0800
+++ b/njs/test/njs_unit_test.c	Mon Mar 18 16:05:27 2019 +0300
@@ -6306,6 +6306,14 @@ static njs_unit_test_t  njs_test[] =
                  "var b = f.bind('1', '2', '3'); b.apply()"),
       nxt_string("123") },
 
+    { nxt_string("var obj = {prop:'abc'}; "
+                 "var func = function(x) { "
+                 "    return this === obj && x === 1 && arguments[0] === 1 "
+                 "           && arguments.length === 1 && this.prop === 'abc';"
+                 "};"
+                 "Function.prototype.bind.call(func, obj, 1)()"),
+      nxt_string("true") },
+
     { nxt_string("function F(a, b) { this.a = a + b }"
                  "var o = new F(1, 2);"
                  "o.a"),
@@ -6457,6 +6465,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("(function(){arguments.length = 1; return arguments.length;})(1,2,3)"),
       nxt_string("1") },
 
+     { nxt_string("(function(){return arguments[3];}).bind(null, 0)('a','b','c')"),
+       nxt_string("c") },
+
     { nxt_string("(function(){return arguments.callee;})()"),
       nxt_string("TypeError: \"caller\", \"callee\" properties may not be accessed") },
 


More information about the nginx-devel mailing list