[njs] Fixed backtraces for native modules imported with import statement.

Dmitry Volyntsev xeioex at nginx.com
Mon Feb 14 14:28:29 UTC 2022


details:   https://hg.nginx.org/njs/rev/040d1b318a15
branches:  
changeset: 1824:040d1b318a15
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Feb 14 14:10:26 2022 +0000
description:
Fixed backtraces for native modules imported with import statement.

Previously, the module name was missing when exception is reported
for a native module function imported with import statement.

diffstat:

 external/njs_crypto_module.c       |  8 ++++++++
 external/njs_fs_module.c           |  8 ++++++++
 external/njs_query_string_module.c |  8 ++++++++
 src/test/njs_unit_test.c           |  5 +++++
 4 files changed, 29 insertions(+), 0 deletions(-)

diffs (69 lines):

diff -r bede4b8a693a -r 040d1b318a15 external/njs_crypto_module.c
--- a/external/njs_crypto_module.c	Mon Feb 14 14:10:04 2022 +0000
+++ b/external/njs_crypto_module.c	Mon Feb 14 14:10:26 2022 +0000
@@ -231,6 +231,14 @@ static njs_external_t  njs_ext_crypto_hm
 static njs_external_t  njs_ext_crypto_crypto[] = {
 
     {
+        .flags = NJS_EXTERN_PROPERTY | NJS_EXTERN_SYMBOL,
+        .name.symbol = NJS_SYMBOL_TO_STRING_TAG,
+        .u.property = {
+            .value = "crypto",
+        }
+    },
+
+    {
         .flags = NJS_EXTERN_METHOD,
         .name.string = njs_str("createHash"),
         .writable = 1,
diff -r bede4b8a693a -r 040d1b318a15 external/njs_fs_module.c
--- a/external/njs_fs_module.c	Mon Feb 14 14:10:04 2022 +0000
+++ b/external/njs_fs_module.c	Mon Feb 14 14:10:26 2022 +0000
@@ -228,6 +228,14 @@ static njs_fs_entry_t njs_flags_table[] 
 static njs_external_t  njs_ext_fs[] = {
 
     {
+        .flags = NJS_EXTERN_PROPERTY | NJS_EXTERN_SYMBOL,
+        .name.symbol = NJS_SYMBOL_TO_STRING_TAG,
+        .u.property = {
+            .value = "fs",
+        }
+    },
+
+    {
         .flags = NJS_EXTERN_METHOD,
         .name.string = njs_str("access"),
         .writable = 1,
diff -r bede4b8a693a -r 040d1b318a15 external/njs_query_string_module.c
--- a/external/njs_query_string_module.c	Mon Feb 14 14:10:04 2022 +0000
+++ b/external/njs_query_string_module.c	Mon Feb 14 14:10:26 2022 +0000
@@ -33,6 +33,14 @@ static njs_int_t njs_query_string_init(n
 static njs_external_t  njs_ext_query_string[] = {
 
     {
+        .flags = NJS_EXTERN_PROPERTY | NJS_EXTERN_SYMBOL,
+        .name.symbol = NJS_SYMBOL_TO_STRING_TAG,
+        .u.property = {
+            .value = "querystring",
+        }
+    },
+
+    {
         .flags = NJS_EXTERN_METHOD,
         .name.string = njs_str("parse"),
         .writable = 1,
diff -r bede4b8a693a -r 040d1b318a15 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Mon Feb 14 14:10:04 2022 +0000
+++ b/src/test/njs_unit_test.c	Mon Feb 14 14:10:26 2022 +0000
@@ -21243,6 +21243,11 @@ static njs_unit_test_t  njs_shared_test[
               "    at fs.readFileSync (native)\n"
               "    at main (:1)\n") },
 
+    { njs_str("import fs from 'fs'; fs.readFileSync()"),
+      njs_str("TypeError: \"path\" must be a string or Buffer\n"
+              "    at fs.readFileSync (native)\n"
+              "    at main (:1)\n") },
+
     { njs_str("var f = new Function('return 1;'); f();"),
       njs_str("1") },
 



More information about the nginx-devel mailing list