Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: remove custom JS_FreePropEnum function #687

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/mod_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ static JSValue tjs_spawn(JSContext *ctx, JSValue this_val, int argc, JSValue *ar
}
options.env = js_mallocz(ctx, sizeof(*options.env) * (plen + 1));
if (!options.env) {
JS_FreePropEnum(ctx, ptab, plen);
JS_FreePropertyEnum(ctx, ptab, plen);
JS_FreeValue(ctx, js_env);
goto fail;
}
for (int i = 0; i < plen; i++) {
JSValue prop = JS_GetProperty(ctx, js_env, ptab[i].atom);
if (JS_IsException(prop)) {
JS_FreePropEnum(ctx, ptab, plen);
JS_FreePropertyEnum(ctx, ptab, plen);
JS_FreeValue(ctx, js_env);
goto fail;
}
Expand All @@ -309,15 +309,15 @@ static JSValue tjs_spawn(JSContext *ctx, JSValue this_val, int argc, JSValue *ar
if (!options.env[i]) {
JS_FreeCString(ctx, key);
JS_FreeCString(ctx, value);
JS_FreePropEnum(ctx, ptab, plen);
JS_FreePropertyEnum(ctx, ptab, plen);
JS_FreeValue(ctx, js_env);
goto fail;
}
snprintf(options.env[i], len, "%s=%s", key, value);
JS_FreeCString(ctx, key);
JS_FreeCString(ctx, value);
}
JS_FreePropEnum(ctx, ptab, plen);
JS_FreePropertyEnum(ctx, ptab, plen);
}
JS_FreeValue(ctx, js_env);

Expand Down
6 changes: 3 additions & 3 deletions src/mod_sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ static JSValue tjs__sqlite3_bind_params(JSContext *ctx, sqlite3_stmt *stmt, JSVa
JSAtom patom = ptab[i].atom;
JSValue prop = JS_GetProperty(ctx, params, patom);
if (JS_IsException(prop)) {
JS_FreePropEnum(ctx, ptab, plen);
JS_FreePropertyEnum(ctx, ptab, plen);
return JS_EXCEPTION;
}
const char *key = JS_AtomToCString(ctx, patom);
Expand All @@ -494,13 +494,13 @@ static JSValue tjs__sqlite3_bind_params(JSContext *ctx, sqlite3_stmt *stmt, JSVa
}
JS_FreeValue(ctx, prop);
JS_FreeCString(ctx, key);
JS_FreePropEnum(ctx, ptab, plen);
JS_FreePropertyEnum(ctx, ptab, plen);
return JS_EXCEPTION;
}
JS_FreeValue(ctx, prop);
JS_FreeCString(ctx, key);
}
JS_FreePropEnum(ctx, ptab, plen);
JS_FreePropertyEnum(ctx, ptab, plen);
} else {
return JS_ThrowTypeError(ctx, "Invalid bind parameters type: expected object or array");
}
Expand Down
10 changes: 0 additions & 10 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,6 @@ void tjs_call_handler(JSContext *ctx, JSValue func, int argc, JSValue *argv) {
JS_FreeValue(ctx, ret);
}

void JS_FreePropEnum(JSContext *ctx, JSPropertyEnum *tab, uint32_t len) {
uint32_t i;
if (tab) {
for (i = 0; i < len; i++) {
JS_FreeAtom(ctx, tab[i].atom);
}
js_free(ctx, tab);
}
}

JSValue TJS_InitPromise(JSContext *ctx, TJSPromise *p) {
JSValue rfuncs[2];
p->p = JS_NewPromiseCapability(ctx, rfuncs);
Expand Down
1 change: 0 additions & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ void tjs_addr2obj(JSContext *ctx, JSValue obj, const struct sockaddr *sa, bool s
void tjs_call_handler(JSContext *ctx, JSValue func, int argc, JSValue *argv);
void tjs_dump_error(JSContext *ctx);
void tjs_dump_error1(JSContext *ctx, JSValue exception_val);
void JS_FreePropEnum(JSContext *ctx, JSPropertyEnum *tab, uint32_t len);

typedef struct {
JSValue p;
Expand Down
Loading