Skip to content

Commit 2f167bb

Browse files
author
Fabrice Bellard
committed
export JS_FreePropertyEnum()
1 parent 9bce51e commit 2f167bb

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

quickjs-libc.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,9 +2938,7 @@ static char **build_envp(JSContext *ctx, JSValueConst obj)
29382938
JS_FreeCString(ctx, str);
29392939
}
29402940
done:
2941-
for(i = 0; i < len; i++)
2942-
JS_FreeAtom(ctx, tab[i].atom);
2943-
js_free(ctx, tab);
2941+
JS_FreePropertyEnum(ctx, tab, len);
29442942
return envp;
29452943
fail:
29462944
if (envp) {

quickjs.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7875,7 +7875,7 @@ static int num_keys_cmp(const void *p1, const void *p2, void *opaque)
78757875
return 1;
78767876
}
78777877

7878-
static void js_free_prop_enum(JSContext *ctx, JSPropertyEnum *tab, uint32_t len)
7878+
void JS_FreePropertyEnum(JSContext *ctx, JSPropertyEnum *tab, uint32_t len)
78797879
{
78807880
uint32_t i;
78817881
if (tab) {
@@ -7969,7 +7969,7 @@ static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,
79697969
/* set the "is_enumerable" field if necessary */
79707970
res = JS_GetOwnPropertyInternal(ctx, &desc, p, atom);
79717971
if (res < 0) {
7972-
js_free_prop_enum(ctx, tab_exotic, exotic_count);
7972+
JS_FreePropertyEnum(ctx, tab_exotic, exotic_count);
79737973
return -1;
79747974
}
79757975
if (res) {
@@ -8000,15 +8000,15 @@ static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,
80008000
if (atom_count < exotic_keys_count || atom_count > INT32_MAX) {
80018001
add_overflow:
80028002
JS_ThrowOutOfMemory(ctx);
8003-
js_free_prop_enum(ctx, tab_exotic, exotic_count);
8003+
JS_FreePropertyEnum(ctx, tab_exotic, exotic_count);
80048004
return -1;
80058005
}
80068006
/* XXX: need generic way to test for js_malloc(ctx, a * b) overflow */
80078007

80088008
/* avoid allocating 0 bytes */
80098009
tab_atom = js_malloc(ctx, sizeof(tab_atom[0]) * max_int(atom_count, 1));
80108010
if (!tab_atom) {
8011-
js_free_prop_enum(ctx, tab_exotic, exotic_count);
8011+
JS_FreePropertyEnum(ctx, tab_exotic, exotic_count);
80128012
return -1;
80138013
}
80148014

@@ -8053,7 +8053,7 @@ static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,
80538053
for(i = 0; i < len; i++) {
80548054
tab_atom[num_index].atom = __JS_AtomFromUInt32(i);
80558055
if (tab_atom[num_index].atom == JS_ATOM_NULL) {
8056-
js_free_prop_enum(ctx, tab_atom, num_index);
8056+
JS_FreePropertyEnum(ctx, tab_atom, num_index);
80578057
return -1;
80588058
}
80598059
tab_atom[num_index].is_enumerable = TRUE;
@@ -15553,7 +15553,7 @@ static __exception int js_for_in_prepare_prototype_chain_enum(JSContext *ctx,
1555315553
JS_FreeValue(ctx, obj1);
1555415554
goto fail;
1555515555
}
15556-
js_free_prop_enum(ctx, tab_atom, tab_atom_count);
15556+
JS_FreePropertyEnum(ctx, tab_atom, tab_atom_count);
1555715557
if (tab_atom_count != 0) {
1555815558
JS_FreeValue(ctx, obj1);
1555915559
goto slow_path;
@@ -15637,7 +15637,7 @@ static __exception int js_for_in_next(JSContext *ctx, JSValue *sp)
1563715637
JS_GPN_STRING_MASK | JS_GPN_SET_ENUM)) {
1563815638
return -1;
1563915639
}
15640-
js_free_prop_enum(ctx, it->tab_atom, it->atom_count);
15640+
JS_FreePropertyEnum(ctx, it->tab_atom, it->atom_count);
1564115641
it->tab_atom = tab_atom;
1564215642
it->atom_count = tab_atom_count;
1564315643
it->idx = 0;
@@ -16160,10 +16160,10 @@ static __exception int JS_CopyDataProperties(JSContext *ctx,
1616016160
if (ret < 0)
1616116161
goto exception;
1616216162
}
16163-
js_free_prop_enum(ctx, tab_atom, tab_atom_count);
16163+
JS_FreePropertyEnum(ctx, tab_atom, tab_atom_count);
1616416164
return 0;
1616516165
exception:
16166-
js_free_prop_enum(ctx, tab_atom, tab_atom_count);
16166+
JS_FreePropertyEnum(ctx, tab_atom, tab_atom_count);
1616716167
return -1;
1616816168
}
1616916169

@@ -38093,7 +38093,7 @@ static __exception int JS_ObjectDefineProperties(JSContext *ctx,
3809338093
ret = 0;
3809438094

3809538095
exception:
38096-
js_free_prop_enum(ctx, atoms, len);
38096+
JS_FreePropertyEnum(ctx, atoms, len);
3809738097
JS_FreeValue(ctx, props);
3809838098
JS_FreeValue(ctx, desc);
3809938099
return ret;
@@ -38364,12 +38364,12 @@ static JSValue js_object_getOwnPropertyDescriptors(JSContext *ctx, JSValueConst
3836438364
goto exception;
3836538365
}
3836638366
}
38367-
js_free_prop_enum(ctx, props, len);
38367+
JS_FreePropertyEnum(ctx, props, len);
3836838368
JS_FreeValue(ctx, obj);
3836938369
return r;
3837038370

3837138371
exception:
38372-
js_free_prop_enum(ctx, props, len);
38372+
JS_FreePropertyEnum(ctx, props, len);
3837338373
JS_FreeValue(ctx, obj);
3837438374
JS_FreeValue(ctx, r);
3837538375
return JS_EXCEPTION;
@@ -38449,7 +38449,7 @@ static JSValue JS_GetOwnPropertyNames2(JSContext *ctx, JSValueConst obj1,
3844938449
JS_FreeValue(ctx, r);
3845038450
r = JS_EXCEPTION;
3845138451
done:
38452-
js_free_prop_enum(ctx, atoms, len);
38452+
JS_FreePropertyEnum(ctx, atoms, len);
3845338453
JS_FreeValue(ctx, obj);
3845438454
return r;
3845538455
}
@@ -38710,11 +38710,11 @@ static JSValue js_object_seal(JSContext *ctx, JSValueConst this_val,
3871038710
JS_UNDEFINED, JS_UNDEFINED, desc_flags) < 0)
3871138711
goto exception;
3871238712
}
38713-
js_free_prop_enum(ctx, props, len);
38713+
JS_FreePropertyEnum(ctx, props, len);
3871438714
return JS_DupValue(ctx, obj);
3871538715

3871638716
exception:
38717-
js_free_prop_enum(ctx, props, len);
38717+
JS_FreePropertyEnum(ctx, props, len);
3871838718
return JS_EXCEPTION;
3871938719
}
3872038720

@@ -38756,11 +38756,11 @@ static JSValue js_object_isSealed(JSContext *ctx, JSValueConst this_val,
3875638756
return JS_EXCEPTION;
3875738757
res ^= 1;
3875838758
done:
38759-
js_free_prop_enum(ctx, props, len);
38759+
JS_FreePropertyEnum(ctx, props, len);
3876038760
return JS_NewBool(ctx, res);
3876138761

3876238762
exception:
38763-
js_free_prop_enum(ctx, props, len);
38763+
JS_FreePropertyEnum(ctx, props, len);
3876438764
return JS_EXCEPTION;
3876538765
}
3876638766

@@ -46089,7 +46089,7 @@ static JSValue internalize_json_property(JSContext *ctx, JSValueConst holder,
4608946089
goto fail;
4609046090
}
4609146091
}
46092-
js_free_prop_enum(ctx, atoms, len);
46092+
JS_FreePropertyEnum(ctx, atoms, len);
4609346093
atoms = NULL;
4609446094
name_val = JS_AtomToValue(ctx, name);
4609546095
if (JS_IsException(name_val))
@@ -46101,7 +46101,7 @@ static JSValue internalize_json_property(JSContext *ctx, JSValueConst holder,
4610146101
JS_FreeValue(ctx, val);
4610246102
return res;
4610346103
fail:
46104-
js_free_prop_enum(ctx, atoms, len);
46104+
JS_FreePropertyEnum(ctx, atoms, len);
4610546105
JS_FreeValue(ctx, val);
4610646106
return JS_EXCEPTION;
4610746107
}
@@ -47475,14 +47475,14 @@ static int js_proxy_get_own_property_names(JSContext *ctx,
4747547475
}
4747647476
}
4747747477

47478-
js_free_prop_enum(ctx, tab2, len2);
47478+
JS_FreePropertyEnum(ctx, tab2, len2);
4747947479
JS_FreeValue(ctx, prop_array);
4748047480
*ptab = tab;
4748147481
*plen = len;
4748247482
return 0;
4748347483
fail:
47484-
js_free_prop_enum(ctx, tab2, len2);
47485-
js_free_prop_enum(ctx, tab, len);
47484+
JS_FreePropertyEnum(ctx, tab2, len2);
47485+
JS_FreePropertyEnum(ctx, tab, len);
4748647486
JS_FreeValue(ctx, prop_array);
4748747487
return -1;
4748847488
}

quickjs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,8 @@ JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
805805

806806
int JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
807807
uint32_t *plen, JSValueConst obj, int flags);
808+
void JS_FreePropertyEnum(JSContext *ctx, JSPropertyEnum *tab,
809+
uint32_t len);
808810
int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,
809811
JSValueConst obj, JSAtom prop);
810812

0 commit comments

Comments
 (0)