]> git.kaiwu.me - njs.git/commitdiff
Added quiet option for vm to support bit-exact output in test262.
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 12 Apr 2019 17:48:44 +0000 (20:48 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Fri, 12 Apr 2019 17:48:44 +0000 (20:48 +0300)
njs/njs.h
njs/njs_generator.c
njs/njs_parser.c
njs/njs_shell.c
njs/test/njs_expect_test.exp

index fe79b8d6b4e3df03708440dba784807944ccbb83..54391d230f5a3f272624c790a73345a7a9d866e6 100644 (file)
--- 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;
 
 
index 35beb5804333a17a50508c44ed2b6170531fc5fa..145bba5621eb8ec0c7c7d30cbb37c722d6649122 100644 (file)
@@ -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;
index 8313e730e4df29e61bcd927a04fc11ea841bce21..9be874c12192f9c5f98b1c5ad5099947368eee54 100644 (file)
@@ -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 {
index c58a9662e9330d8a1d3adc0e6f82b61c62077e2d..d92d8b0c91d4ff3bacf1eaf793dfcb2b368d9f6b 100644 (file)
@@ -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;
 
index 029e65e958f9aee7206d46d1d3e20bc0e220923b..722cb48e370d00ef792b594b4ab74cb457596c52 100644 (file)
@@ -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!"