[njs] Added njs.version_number property.

Dmitry Volyntsev xeioex at nginx.com
Fri Apr 29 03:30:27 UTC 2022


details:   https://hg.nginx.org/njs/rev/900d3ba62bcb
branches:  
changeset: 1847:900d3ba62bcb
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Apr 28 17:59:03 2022 -0700
description:
Added njs.version_number property.

diffstat:

 src/njs.h                |  1 +
 src/njs_builtin.c        |  8 ++++++++
 src/test/njs_unit_test.c |  7 ++++---
 3 files changed, 13 insertions(+), 3 deletions(-)

diffs (53 lines):

diff -r 4d71bdf8663d -r 900d3ba62bcb src/njs.h
--- a/src/njs.h	Thu Apr 28 17:49:59 2022 -0700
+++ b/src/njs.h	Thu Apr 28 17:59:03 2022 -0700
@@ -12,6 +12,7 @@
 #include <njs_auto_config.h>
 
 #define NJS_VERSION                 "0.7.4"
+#define NJS_VERSION_NUMBER          0x000704
 
 
 #include <unistd.h>                 /* STDOUT_FILENO, STDERR_FILENO */
diff -r 4d71bdf8663d -r 900d3ba62bcb src/njs_builtin.c
--- a/src/njs_builtin.c	Thu Apr 28 17:49:59 2022 -0700
+++ b/src/njs_builtin.c	Thu Apr 28 17:59:03 2022 -0700
@@ -1693,6 +1693,14 @@ static const njs_object_prop_t  njs_njs_
 
     {
         .type = NJS_PROPERTY,
+        .name = njs_string("version_number"),
+        .value = njs_value(NJS_NUMBER, 1, NJS_VERSION_NUMBER),
+        .configurable = 1,
+        .enumerable = 1,
+    },
+
+    {
+        .type = NJS_PROPERTY,
         .name = njs_string("dump"),
         .value = njs_native_function(njs_ext_dump, 0),
         .configurable = 1,
diff -r 4d71bdf8663d -r 900d3ba62bcb src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Thu Apr 28 17:49:59 2022 -0700
+++ b/src/test/njs_unit_test.c	Thu Apr 28 17:59:03 2022 -0700
@@ -13448,6 +13448,10 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("Object.values(njs)[0] === njs.version"),
       njs_str("true") },
 
+    { njs_str("njs.version.split('.')"
+              ".map(v => parseInt(v)).reduce((p, c) => p * 256 + c) == njs.version_number"),
+      njs_str("true") },
+
     { njs_str("Object.values(process)"),
       njs_str("") },
 
@@ -17644,9 +17648,6 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("var o = Object.defineProperty({}, 'a', { set(){}, enumerable: true }); njs.dump(o)"),
       njs_str("{a:'[Setter]'}") },
 
-    { njs_str("njs.dump(njs) == `njs {version:'${njs.version}'}`"),
-      njs_str("true") },
-
     { njs_str("var a = []; a[0] = a; njs.dump(a)"),
       njs_str("[[Circular]]") },
 



More information about the nginx-devel mailing list