details:   
https://github.com/nginx/njs/commit/f6a2a795e9df4911dde8d0c3f02dd5a83c610ca5
branches:  master
commit:    f6a2a795e9df4911dde8d0c3f02dd5a83c610ca5
user:      hongzhidao <hongzhi...@gmail.com>
date:      Wed, 19 Mar 2025 11:18:41 +0800
description:
QuickJS: fixed njs_qjs_object_completions().

This commit also exposed qjs_free_prop_enum() as public.

---
 external/njs_shell.c               |  5 ++---
 external/qjs_query_string_module.c | 13 -------------
 src/qjs.c                          | 13 +++++++++++++
 src/qjs.h                          |  2 ++
 4 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/external/njs_shell.c b/external/njs_shell.c
index 1228b374..aeab226c 100644
--- a/external/njs_shell.c
+++ b/external/njs_shell.c
@@ -2950,7 +2950,6 @@ njs_qjs_object_completions(njs_engine_t *engine, 
JSContext *ctx,
 
         for (n = 0; n < length; n++) {
             key.start = (u_char *) JS_AtomToCString(ctx, ptab[n].atom);
-            JS_FreeAtom(ctx, ptab[n].atom);
             if (njs_slow_path(key.start == NULL)) {
                 goto fail;
             }
@@ -2993,7 +2992,7 @@ next:
             JS_FreeCString(ctx, (const char *) key.start);
         }
 
-        js_free_rt(JS_GetRuntime(ctx), ptab);
+        qjs_free_prop_enum(ctx, ptab, length);
 
         prototype = JS_GetPrototype(ctx, object);
         if (JS_IsException(prototype)) {
@@ -3017,7 +3016,7 @@ fail:
     }
 
     if (ptab != NULL) {
-        js_free_rt(JS_GetRuntime(ctx), ptab);
+        qjs_free_prop_enum(ctx, ptab, length);
     }
 
     JS_FreeValue(ctx, object);
diff --git a/external/qjs_query_string_module.c 
b/external/qjs_query_string_module.c
index 3059ee1b..42322234 100644
--- a/external/qjs_query_string_module.c
+++ b/external/qjs_query_string_module.c
@@ -727,19 +727,6 @@ qjs_query_string_push_array(JSContext *cx, njs_chb_t 
*chain, JSValue key,
 }
 
 
-static void
-qjs_free_prop_enum(JSContext *cx, JSPropertyEnum *tab, uint32_t len)
-{
-    uint32_t  i;
-
-    for (i = 0; i < len; i++) {
-        JS_FreeAtom(cx, tab[i].atom);
-    }
-
-    js_free(cx, tab);
-}
-
-
 static JSValue
 qjs_query_string_stringify_internal(JSContext *cx, JSValue obj, njs_str_t *sep,
     njs_str_t *eq, JSValue encoder)
diff --git a/src/qjs.c b/src/qjs.c
index 15a575a2..52401983 100644
--- a/src/qjs.c
+++ b/src/qjs.c
@@ -1027,6 +1027,19 @@ qjs_string_create_chb(JSContext *cx, njs_chb_t *chain)
 }
 
 
+void
+qjs_free_prop_enum(JSContext *ctx, JSPropertyEnum *tab, uint32_t len)
+{
+    uint32_t  i;
+
+    for(i = 0; i < len; i++) {
+        JS_FreeAtom(ctx, tab[i].atom);
+    }
+
+    js_free(ctx, tab);
+}
+
+
 JSValue
 qjs_string_hex(JSContext *cx, const njs_str_t *src)
 {
diff --git a/src/qjs.h b/src/qjs.h
index 54f96dfe..7c13f039 100644
--- a/src/qjs.h
+++ b/src/qjs.h
@@ -127,6 +127,8 @@ JSValue qjs_typed_array_data(JSContext *ctx, JSValueConst 
value,
     JS_NewStringLen(ctx, (const char *) (data), len)
 JSValue qjs_string_create_chb(JSContext *cx, njs_chb_t *chain);
 
+void qjs_free_prop_enum(JSContext *ctx, JSPropertyEnum *tab, uint32_t len);
+
 JSValue qjs_string_hex(JSContext *cx, const njs_str_t *src);
 JSValue qjs_string_base64(JSContext *cx, const njs_str_t *src);
 JSValue qjs_string_base64url(JSContext *cx, const njs_str_t *src);
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel

Reply via email to