]> git.kaiwu.me - njs.git/commitdiff
QuickJS: fixed njs_qjs_object_completions().
authorhongzhidao <hongzhidao@gmail.com>
Wed, 19 Mar 2025 03:18:41 +0000 (11:18 +0800)
committerhongzhidao <hongzhidao@gmail.com>
Wed, 19 Mar 2025 05:27:18 +0000 (13:27 +0800)
This commit also exposed qjs_free_prop_enum() as public.

external/njs_shell.c
external/qjs_query_string_module.c
src/qjs.c
src/qjs.h

index 1228b3746d29f5dd965120110f630d58488f786f..aeab226c2c7eb7f5a679d407588f0a7d972782ba 100644 (file)
@@ -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);
index 3059ee1becc1310a7b99ffe7ebcb0b443f4cb4be..42322234262eca6118daa2a867c27ebfcd9c1a8e 100644 (file)
@@ -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)
index 15a575a284df8bc05b7ca61c42547ec0287f0206..52401983ac520eb3d9e5cba1d54c60167a6b66fe 100644 (file)
--- 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)
 {
index 54f96dfec705d2b8b77da99c728349ca9f3897b9..7c13f0392f5f99fc5a2480378e9b8ae426009d5e 100644 (file)
--- 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);