From a4c18244a6b36fd0d11f99cd4c8a4cd9b8f5b60f Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 26 Jun 2018 18:27:33 +0700 Subject: [PATCH] Adding support for multiple arguments in console.log(). --- njs/njs_shell.c | 24 +++++++++++++++--------- njs/test/njs_expect_test.exp | 6 +++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/njs/njs_shell.c b/njs/njs_shell.c index 36bc1334..e014f85e 100644 --- a/njs/njs_shell.c +++ b/njs/njs_shell.c @@ -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; + } + + printf("%s%.*s", (n != 1) ? " " : "", (int) msg.length, msg.start); - return NJS_ERROR; + n++; } - printf("%.*s\n", (int) msg.length, msg.start); + if (nargs > 1) { + printf("\n"); + } vm->retval = njs_value_void; diff --git a/njs/test/njs_expect_test.exp b/njs/test/njs_expect_test.exp index 9f91f147..ef9b5e52 100644 --- a/njs/test/njs_expect_test.exp +++ b/njs/test/njs_expect_test.exp @@ -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:"} } -- 2.47.3