details: http://hg.nginx.org/njs/rev/649e5804b971 branches: changeset: 548:649e5804b971 user: xei...@nginx.com date: Tue Jun 26 18:27:33 2018 +0700 description: Adding support for multiple arguments in console.log().
diffstat: njs/njs_shell.c | 24 +++++++++++++++--------- njs/test/njs_expect_test.exp | 6 +++--- 2 files changed, 18 insertions(+), 12 deletions(-) diffs (57 lines): diff -r 31e0580b3c02 -r 649e5804b971 njs/njs_shell.c --- a/njs/njs_shell.c Fri Jun 29 22:36:41 2018 +0300 +++ b/njs/njs_shell.c Tue Jun 26 18:27:33 2018 +0700 @@ -622,20 +622,26 @@ static njs_ret_t njs_ext_console_log(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { - nxt_str_t msg; + nxt_str_t msg; + nxt_uint_t n; - msg.length = 0; - msg.start = NULL; + n = 1; - if (nargs >= 2 - && njs_vm_value_to_ext_string(vm, &msg, njs_argument(args, 1), 0) - == NJS_ERROR) - { + while (n < nargs) { + if (njs_vm_value_to_ext_string(vm, &msg, njs_argument(args, n), 0) + == NJS_ERROR) + { + return NJS_ERROR; + } - return NJS_ERROR; + printf("%s%.*s", (n != 1) ? " " : "", (int) msg.length, msg.start); + + n++; } - printf("%.*s\n", (int) msg.length, msg.start); + if (nargs > 1) { + printf("\n"); + } vm->retval = njs_value_void; diff -r 31e0580b3c02 -r 649e5804b971 njs/test/njs_expect_test.exp --- a/njs/test/njs_expect_test.exp Fri Jun 29 22:36:41 2018 +0300 +++ b/njs/test/njs_expect_test.exp Tue Jun 26 18:27:33 2018 +0700 @@ -162,11 +162,11 @@ njs_test { # console object njs_test { {"console.log()\r\n" - "console.log()\r\n\r\nundefined\r\n>> "} + "console.log()\r\nundefined\r\n>> "} {"console.log(1)\r\n" "console.log(1)\r\n1\r\nundefined\r\n>> "} - {"console.log('abc')\r\n" - "console.log('abc')\r\nabc\r\nundefined\r\n>> "} + {"console.log(1, 'a')\r\n" + "console.log(1, 'a')\r\n1 a\r\nundefined\r\n>> "} {"console.help()\r\n" "console.help()\r\nVM built-in objects:"} } _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel