From: Dmitry Volyntsev Date: Fri, 12 Apr 2019 17:48:44 +0000 (+0300) Subject: Added quiet option for vm to support bit-exact output in test262. X-Git-Tag: 0.3.1~6 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=a79f4e434ae5db81fd501ec6cbd463cd9e769c3f;p=njs.git Added quiet option for vm to support bit-exact output in test262. --- diff --git a/njs/njs.h b/njs/njs.h index fe79b8d6..54391d23 100644 --- a/njs/njs.h +++ b/njs/njs.h @@ -149,6 +149,7 @@ typedef struct { uint8_t backtrace; /* 1 bit */ uint8_t sandbox; /* 1 bit */ uint8_t module; /* 1 bit */ + uint8_t quiet; /* 1 bit */ } njs_vm_opt_t; diff --git a/njs/njs_generator.c b/njs/njs_generator.c index 35beb580..145bba56 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -3246,7 +3246,14 @@ njs_generate_function_debug(njs_vm_t *vm, const nxt_str_t *name, debug->lambda = lambda; debug->line = node->token_line; - debug->file = node->scope->file; + + if (!vm->options.quiet) { + debug->file = node->scope->file; + + } else { + debug->file = nxt_string_value(""); + } + debug->name = (name != NULL) ? *name : no_label; return NXT_OK; diff --git a/njs/njs_parser.c b/njs/njs_parser.c index 8313e730..9be874c1 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -2378,7 +2378,7 @@ njs_parser_scope_error(njs_vm_t *vm, njs_parser_scope_t *scope, p = end - width; } - if (file->length != 0) { + if (file->length != 0 && !vm->options.quiet) { p = nxt_sprintf(p, end, " in %V:%uD", file, line); } else { diff --git a/njs/njs_shell.c b/njs/njs_shell.c index c58a9662..d92d8b0c 100644 --- a/njs/njs_shell.c +++ b/njs/njs_shell.c @@ -228,28 +228,28 @@ main(int argc, char **argv) nxt_memzero(&vm_options, sizeof(njs_vm_opt_t)); - if (!opts.quiet) { - if (opts.file == NULL) { - p = getcwd(path, sizeof(path)); - if (p == NULL) { - nxt_error("getcwd() failed:%s\n", strerror(errno)); - ret = NXT_ERROR; - goto done; - } - - memcpy(path + nxt_strlen(path), "/shell", sizeof("/shell")); - opts.file = path; + if (opts.file == NULL) { + p = getcwd(path, sizeof(path)); + if (p == NULL) { + nxt_error("getcwd() failed:%s\n", strerror(errno)); + ret = NXT_ERROR; + goto done; } - vm_options.file.start = (u_char *) opts.file; - vm_options.file.length = nxt_strlen(opts.file); + memcpy(path + nxt_strlen(path), "/shell", sizeof("/shell")); + opts.file = path; } + vm_options.file.start = (u_char *) opts.file; + vm_options.file.length = nxt_strlen(opts.file); + vm_options.init = !opts.interactive; vm_options.accumulative = opts.interactive; vm_options.backtrace = 1; + vm_options.quiet = opts.quiet; vm_options.sandbox = opts.sandbox; vm_options.module = opts.module; + vm_options.ops = &njs_console_ops; vm_options.external = &njs_console; diff --git a/njs/test/njs_expect_test.exp b/njs/test/njs_expect_test.exp index 029e65e9..722cb48e 100644 --- a/njs/test/njs_expect_test.exp +++ b/njs/test/njs_expect_test.exp @@ -715,5 +715,8 @@ njs_test { "12\r\n"} } "-p njs/test/module/" +njs_run "-q ./njs/test/module/normal.js" \ + "SyntaxError: Cannot find module \"hash.js\" in 5" + njs_run "-p njs/test/module/libs/ -d ./njs/test/module/normal.js" \ "passed!"