[njs] Modules: improved generic external getters.

Dmitry Volyntsev xeioex at nginx.com
Sat Aug 20 05:08:18 UTC 2022


details:   https://hg.nginx.org/njs/rev/7d2fb383e424
branches:  
changeset: 1929:7d2fb383e424
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Aug 19 22:02:37 2022 -0700
description:
Modules: improved generic external getters.

diffstat:

 nginx/ngx_js.c       |  28 +++++++++++++++++-----------
 nginx/ngx_js.h       |   2 --
 nginx/ngx_js_fetch.c |   3 ++-
 3 files changed, 19 insertions(+), 14 deletions(-)

diffs (92 lines):

diff -r ae971e65f638 -r 7d2fb383e424 nginx/ngx_js.c
--- a/nginx/ngx_js.c	Fri Aug 19 21:38:55 2022 -0700
+++ b/nginx/ngx_js.c	Fri Aug 19 22:02:37 2022 -0700
@@ -34,6 +34,7 @@ static njs_external_t  ngx_js_ext_core[]
         .u.property = {
             .handler = ngx_js_ext_constant,
             .magic32 = NGX_LOG_INFO,
+            .magic16 = NGX_JS_NUMBER,
         }
     },
 
@@ -43,6 +44,7 @@ static njs_external_t  ngx_js_ext_core[]
         .u.property = {
             .handler = ngx_js_ext_constant,
             .magic32 = NGX_LOG_WARN,
+            .magic16 = NGX_JS_NUMBER,
         }
     },
 
@@ -52,6 +54,7 @@ static njs_external_t  ngx_js_ext_core[]
         .u.property = {
             .handler = ngx_js_ext_constant,
             .magic32 = NGX_LOG_ERR,
+            .magic16 = NGX_JS_NUMBER,
         }
     },
 
@@ -256,7 +259,20 @@ njs_int_t
 ngx_js_ext_constant(njs_vm_t *vm, njs_object_prop_t *prop,
     njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
-    njs_value_number_set(retval, njs_vm_prop_magic32(prop));
+    uint32_t  magic32;
+
+    magic32 = njs_vm_prop_magic32(prop);
+
+    switch (njs_vm_prop_magic16(prop)) {
+    case NGX_JS_NUMBER:
+        njs_value_number_set(retval, magic32);
+        break;
+
+    case NGX_JS_BOOLEAN:
+    default:
+        njs_value_boolean_set(retval, magic32);
+        break;
+    }
 
     return NJS_OK;
 }
@@ -288,16 +304,6 @@ ngx_js_ext_flags(njs_vm_t *vm, njs_objec
 
 
 njs_int_t
-ngx_js_ext_boolean(njs_vm_t *vm, njs_object_prop_t *prop,
-    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
-{
-    njs_value_boolean_set(retval, njs_vm_prop_magic32(prop));
-
-    return NJS_OK;
-}
-
-
-njs_int_t
 ngx_js_ext_log(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t level)
 {
diff -r ae971e65f638 -r 7d2fb383e424 nginx/ngx_js.h
--- a/nginx/ngx_js.h	Fri Aug 19 21:38:55 2022 -0700
+++ b/nginx/ngx_js.h	Fri Aug 19 22:02:37 2022 -0700
@@ -84,8 +84,6 @@ njs_int_t ngx_js_ext_constant(njs_vm_t *
     njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
 njs_int_t ngx_js_ext_flags(njs_vm_t *vm, njs_object_prop_t *prop,
     njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
-njs_int_t ngx_js_ext_boolean(njs_vm_t *vm, njs_object_prop_t *prop,
-    njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
 
 ngx_int_t ngx_js_core_init(njs_vm_t *vm, ngx_log_t *log);
 
diff -r ae971e65f638 -r 7d2fb383e424 nginx/ngx_js_fetch.c
--- a/nginx/ngx_js_fetch.c	Fri Aug 19 21:38:55 2022 -0700
+++ b/nginx/ngx_js_fetch.c	Fri Aug 19 22:02:37 2022 -0700
@@ -276,8 +276,9 @@ static njs_external_t  ngx_js_ext_http_r
         .name.string = njs_str("redirected"),
         .enumerable = 1,
         .u.property = {
-            .handler = ngx_js_ext_boolean,
+            .handler = ngx_js_ext_constant,
             .magic32 = 0,
+            .magic16 = NGX_JS_BOOLEAN,
         }
     },
 



More information about the nginx-devel mailing list