]> git.kaiwu.me - njs.git/commitdiff
Shell: improved filenames reporting in exceptions.
authorhongzhidao <hongzhidao@gmail.com>
Wed, 6 Feb 2019 04:27:41 +0000 (12:27 +0800)
committerhongzhidao <hongzhidao@gmail.com>
Wed, 6 Feb 2019 04:27:41 +0000 (12:27 +0800)
Makefile
njs/njs_core.h
njs/njs_shell.c
njs/test/njs_expect_test.exp
nxt/Makefile
nxt/nxt_file.c [new file with mode: 0644]
nxt/nxt_file.h [new file with mode: 0644]

index cedb074d2695ccc134cdbad38808e811f9a657d2..f7a364f5ab84dd5a7fa6bed60db13ea8892072df 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,7 @@ $(NXT_BUILDDIR)/libnjs.a: \
        $(NXT_BUILDDIR)/nxt_sha2.o \
        $(NXT_BUILDDIR)/nxt_pcre.o \
        $(NXT_BUILDDIR)/nxt_time.o \
+       $(NXT_BUILDDIR)/nxt_file.o \
        $(NXT_BUILDDIR)/nxt_malloc.o \
        $(NXT_BUILDDIR)/nxt_mp.o \
        $(NXT_BUILDDIR)/nxt_sprintf.o \
@@ -96,6 +97,7 @@ $(NXT_BUILDDIR)/libnjs.a: \
                $(NXT_BUILDDIR)/nxt_sha2.o \
                $(NXT_BUILDDIR)/nxt_pcre.o \
                $(NXT_BUILDDIR)/nxt_time.o \
+               $(NXT_BUILDDIR)/nxt_file.o \
                $(NXT_BUILDDIR)/nxt_malloc.o \
                $(NXT_BUILDDIR)/nxt_mp.o \
                $(NXT_BUILDDIR)/nxt_sprintf.o \
index 614c2069e63a2db15692dcc7f2ca00bcc4a90490..40f43728db5314dc7ce8d83bb0f906916654b71e 100644 (file)
@@ -25,6 +25,7 @@
 #include <nxt_lvlhsh.h>
 #include <nxt_random.h>
 #include <nxt_time.h>
+#include <nxt_file.h>
 #include <nxt_malloc.h>
 #include <nxt_mp.h>
 #include <nxt_sprintf.h>
index 0645812efbb386a2e38573e1221ef75adf71e6b3..26a24ade33513958ce11cc81c600412c4ea60afd 100644 (file)
@@ -215,8 +215,10 @@ main(int argc, char **argv)
     nxt_memzero(&vm_options, sizeof(njs_vm_opt_t));
 
     if (opts.file != NULL) {
-        vm_options.file.start = (u_char *) opts.file;
-        vm_options.file.length = strlen(opts.file);
+        nxt_file_name(&vm_options.file, opts.file);
+
+    } else {
+        vm_options.file = nxt_string_value("shell");
     }
 
     vm_options.init = !opts.interactive;
@@ -1071,4 +1073,3 @@ lvlhsh_pool_free(void *pool, void *p, size_t size)
 {
     nxt_mp_free(pool, p);
 }
-
index 8b56a096d9c073791e5cd41c909129a20257ff48..4ddd2bdfc1c09b9d9a8cd6dbb12e051cb4bd27a8 100644 (file)
@@ -269,7 +269,7 @@ njs_test {
     {"JSON.parse(Error())\r\n"
      "JSON.parse(Error())\r\nSyntaxError: Unexpected token at position 0*at JSON.parse (native)"}
     {"JSON.parse(Error()\r\n"
-     "JSON.parse(Error()\r\nSyntaxError: Unexpected token \"\" in 1"}
+     "JSON.parse(Error()\r\nSyntaxError: Unexpected token \"\" in shell:1"}
 }
 
 njs_test {
@@ -281,7 +281,7 @@ njs_test {
 
 njs_test {
     {"(function() { throw 'test' })()\r\n"
-     "test\r\n    at anonymous (:1)"}
+     "test\r\n    at anonymous (shell:1)"}
 }
 
 # Non-ASCII characters
index 407f905090df5f628a5d36df6f8b6f02be309307..f65e7422ba6000b0f5beba13c4cc52fff7e5da94 100644 (file)
@@ -21,6 +21,7 @@ $(NXT_BUILDDIR)/libnxt.a: \
        $(NXT_BUILDDIR)/nxt_malloc.o \
        $(NXT_BUILDDIR)/nxt_trace.o \
        $(NXT_BUILDDIR)/nxt_time.o \
+       $(NXT_BUILDDIR)/nxt_file.o \
        $(NXT_BUILDDIR)/nxt_mp.o \
        $(NXT_BUILDDIR)/nxt_sprintf.o \
 
@@ -40,6 +41,7 @@ $(NXT_BUILDDIR)/libnxt.a: \
                $(NXT_BUILDDIR)/nxt_pcre.o \
                $(NXT_BUILDDIR)/nxt_malloc.o \
                $(NXT_BUILDDIR)/nxt_time.o \
+               $(NXT_BUILDDIR)/nxt_file.o \
                $(NXT_BUILDDIR)/nxt_trace.o \
                $(NXT_BUILDDIR)/nxt_mp.o \
                $(NXT_BUILDDIR)/nxt_sprintf.o \
@@ -221,6 +223,17 @@ $(NXT_BUILDDIR)/nxt_time.o: \
                -I$(NXT_LIB) \
                $(NXT_LIB)/nxt_time.c
 
+$(NXT_BUILDDIR)/nxt_file.o: \
+       $(NXT_LIB)/nxt_auto_config.h \
+       $(NXT_LIB)/nxt_types.h \
+       $(NXT_LIB)/nxt_clang.h \
+       $(NXT_LIB)/nxt_file.h \
+       $(NXT_LIB)/nxt_file.c \
+
+       $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_file.o $(NXT_CFLAGS) \
+               -I$(NXT_LIB) \
+               $(NXT_LIB)/nxt_file.c
+
 $(NXT_BUILDDIR)/nxt_trace.o: \
        $(NXT_LIB)/nxt_auto_config.h \
        $(NXT_LIB)/nxt_types.h \
diff --git a/nxt/nxt_file.c b/nxt/nxt_file.c
new file mode 100644 (file)
index 0000000..2bf3aae
--- /dev/null
@@ -0,0 +1,33 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#include <nxt_auto_config.h>
+#include <nxt_types.h>
+#include <nxt_clang.h>
+#include <nxt_string.h>
+#include <nxt_file.h>
+
+#include <string.h>
+
+
+void
+nxt_file_name(nxt_str_t *name, char *path)
+{
+    char  *p;
+    size_t  length;
+
+    length = strlen(path);
+
+    for (p = path + length; p >= path; p--) {
+        if (*p == '/') {
+            p++;
+            break;
+        }
+    }
+
+    name->start = (u_char *) p;
+    name->length = length - (p - path);
+}
diff --git a/nxt/nxt_file.h b/nxt/nxt_file.h
new file mode 100644 (file)
index 0000000..545c5a0
--- /dev/null
@@ -0,0 +1,14 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#ifndef _NXT_FILE_H_INCLUDED_
+#define _NXT_FILE_H_INCLUDED_
+
+
+void nxt_file_name(nxt_str_t *name, char *path);
+
+
+#endif /* _NXT_FILE_H_INCLUDED_ */