]> git.kaiwu.me - quickjs.git/commitdiff
removed memory leak and fixes Object.isFrozen/isSealed (#631)
authorFabrice Bellard <fabrice@bellard.org>
Sat, 28 Nov 2026 10:00:28 +0000 (11:00 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 28 Nov 2026 10:00:28 +0000 (11:00 +0100)
quickjs.c

index 498ac39bbd5e726930545a6eeb19e716d96ac272..d2be04994ae3c4dcb04d4f47b9f34ecf166ac331 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -42143,10 +42143,17 @@ static JSValue js_object_isSealed(JSContext *ctx, JSValueConst this_val,
     JSPropertyEnum *props;
     uint32_t len, i;
     int flags, res;
-
+    JSValue ret;
+    
     if (!JS_IsObject(obj))
         return JS_TRUE;
 
+    res = JS_IsExtensible(ctx, obj);
+    if (res < 0)
+        return JS_EXCEPTION;
+    if (res)
+        return JS_FALSE;
+
     p = JS_VALUE_GET_OBJ(obj);
     flags = JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK;
     if (JS_GetOwnPropertyNamesInternal(ctx, &props, &len, p, flags))
@@ -42157,28 +42164,23 @@ static JSValue js_object_isSealed(JSContext *ctx, JSValueConst this_val,
         JSAtom prop = props[i].atom;
 
         res = JS_GetOwnPropertyInternal(ctx, &desc, p, prop);
-        if (res < 0)
-            goto exception;
+        if (res < 0) {
+            ret = JS_EXCEPTION;
+            goto done;
+        }
         if (res) {
             js_free_desc(ctx, &desc);
             if ((desc.flags & JS_PROP_CONFIGURABLE)
             ||  (is_frozen && (desc.flags & JS_PROP_WRITABLE))) {
-                res = FALSE;
+                ret = JS_FALSE;
                 goto done;
             }
         }
     }
-    res = JS_IsExtensible(ctx, obj);
-    if (res < 0)
-        return JS_EXCEPTION;
-    res ^= 1;
+    ret = JS_TRUE;
 done:
     JS_FreePropertyEnum(ctx, props, len);
-    return JS_NewBool(ctx, res);
-
-exception:
-    JS_FreePropertyEnum(ctx, props, len);
-    return JS_EXCEPTION;
+    return ret;
 }
 
 static JSValue js_object_fromEntries(JSContext *ctx, JSValueConst this_val,