From 56a5d07a7d88a513f76a7417384a07858c404fe2 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 25 Feb 2026 09:42:06 -0600 Subject: [PATCH] rm dupavlue and freevalue --- aseprite.c | 12 ------------ dxt.c | 9 --------- jpg.c | 8 -------- png.c | 7 ------- qoi.c | 8 -------- resize.c | 18 ------------------ stb_image_common.h | 12 +++++------- tga.c | 7 ------- 8 files changed, 5 insertions(+), 76 deletions(-) diff --git a/aseprite.c b/aseprite.c index fd951bc..d791876 100644 --- a/aseprite.c +++ b/aseprite.c @@ -109,15 +109,11 @@ JSValue js_aseprite_encode(JSContext *js, JSValue this_val, int argc, JSValueCon JSValue height_val = JS_GetPropertyStr(js, argv[1], "height"); if (!JS_IsNull(width_val)) JS_ToInt32(js, &width, width_val); if (!JS_IsNull(height_val)) JS_ToInt32(js, &height, height_val); - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); JSValue tile_w_val = JS_GetPropertyStr(js, argv[1], "tile_width"); JSValue tile_h_val = JS_GetPropertyStr(js, argv[1], "tile_height"); if (!JS_IsNull(tile_w_val)) JS_ToInt32(js, &tile_width, tile_w_val); if (!JS_IsNull(tile_h_val)) JS_ToInt32(js, &tile_height, tile_h_val); - JS_FreeValue(js, tile_w_val); - JS_FreeValue(js, tile_h_val); } // Allocate frames array @@ -135,13 +131,8 @@ JSValue js_aseprite_encode(JSContext *js, JSValue this_val, int argc, JSValueCon int frame_w, frame_h; if (JS_ToInt32(js, &frame_w, frame_w_val) < 0 || JS_ToInt32(js, &frame_h, frame_h_val) < 0) { free(frames); - JS_FreeValue(js, frame_w_val); - JS_FreeValue(js, frame_h_val); - JS_FreeValue(js, frame_val); return JS_ThrowTypeError(js, "frame %d has invalid dimensions", i); } - JS_FreeValue(js, frame_w_val); - JS_FreeValue(js, frame_h_val); // Set global dimensions if not specified if (width == 0) width = frame_w; @@ -151,8 +142,6 @@ JSValue js_aseprite_encode(JSContext *js, JSValue this_val, int argc, JSValueCon JSValue pixels_val = JS_GetPropertyStr(js, frame_val, "pixels"); size_t pixel_len; void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val); - JS_FreeValue(js, pixels_val); - JS_FreeValue(js, frame_val); if (pixel_data == NULL) { free(frames); @@ -177,7 +166,6 @@ JSValue js_aseprite_encode(JSContext *js, JSValue this_val, int argc, JSValueCon if (!JS_IsNull(duration_val)) { JS_ToInt32(js, &duration, duration_val); } - JS_FreeValue(js, duration_val); // Copy pixel data and set frame info frames[i].pixels = malloc(required_size); diff --git a/dxt.c b/dxt.c index 508b182..0cb3236 100644 --- a/dxt.c +++ b/dxt.c @@ -26,19 +26,13 @@ JSValue js_dxt_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue height_val = JS_GetPropertyStr(js, argv[0], "height"); if (JS_IsNull(width_val) || JS_IsNull(height_val)) { - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); return JS_ThrowTypeError(js, "dxt.encode requires width and height properties"); } int width, height; if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) { - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); return JS_ThrowTypeError(js, "width and height must be numbers"); } - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); if (width < 4 || height < 4) return JS_ThrowRangeError(js, "width and height must be at least 4 for DXT compression"); @@ -50,7 +44,6 @@ JSValue js_dxt_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels"); size_t pixel_len; void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val); - JS_FreeValue(js, pixels_val); if (pixel_data == NULL) return JS_EXCEPTION; if (!pixel_data) return JS_ThrowTypeError(js, "pixels blob has no data"); @@ -68,13 +61,11 @@ JSValue js_dxt_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a if (!JS_IsNull(type_val)) { JS_ToInt32(js, &compression_type, type_val); } - JS_FreeValue(js, type_val); JSValue quality_val = JS_GetPropertyStr(js, argv[1], "high_quality"); if (!JS_IsNull(quality_val)) { high_quality = JS_ToBool(js, quality_val); } - JS_FreeValue(js, quality_val); } // Determine alpha mode based on compression type diff --git a/jpg.c b/jpg.c index 77e9dfa..378cdda 100644 --- a/jpg.c +++ b/jpg.c @@ -51,19 +51,13 @@ JSValue js_jpg_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue height_val = JS_GetPropertyStr(js, argv[0], "height"); if (JS_IsNull(width_val) || JS_IsNull(height_val)) { - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); return JS_ThrowTypeError(js, "jpg.encode requires width and height properties"); } int width, height; if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) { - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); return JS_ThrowTypeError(js, "width and height must be numbers"); } - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); if (width < 1 || height < 1) return JS_ThrowRangeError(js, "width and height must be at least 1"); @@ -71,7 +65,6 @@ JSValue js_jpg_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels"); size_t pixel_len; void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val); - JS_FreeValue(js, pixels_val); if (pixel_data == NULL) return JS_EXCEPTION; if (!pixel_data) return JS_ThrowTypeError(js, "pixels blob has no data"); @@ -92,7 +85,6 @@ JSValue js_jpg_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a quality = qtmp; } } - JS_FreeValue(js, qv); } stbi_mem_buf buf = {0}; diff --git a/png.c b/png.c index 58ff164..62bc19b 100644 --- a/png.c +++ b/png.c @@ -51,19 +51,13 @@ JSValue js_png_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue height_val = JS_GetPropertyStr(js, argv[0], "height"); if (JS_IsNull(width_val) || JS_IsNull(height_val)) { - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); return JS_ThrowTypeError(js, "png.encode requires width and height properties"); } int width, height; if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) { - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); return JS_ThrowTypeError(js, "width and height must be numbers"); } - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); if (width < 1 || height < 1) return JS_ThrowRangeError(js, "width and height must be at least 1"); @@ -71,7 +65,6 @@ JSValue js_png_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels"); size_t pixel_len; void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val); - JS_FreeValue(js, pixels_val); if (pixel_data == NULL) return JS_EXCEPTION; if (!pixel_data) return JS_ThrowTypeError(js, "pixels blob has no data"); diff --git a/qoi.c b/qoi.c index 5039d23..9774d0c 100644 --- a/qoi.c +++ b/qoi.c @@ -25,19 +25,13 @@ JSValue js_qoi_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue height_val = JS_GetPropertyStr(js, argv[0], "height"); if (JS_IsNull(width_val) || JS_IsNull(height_val)) { - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); return JS_ThrowTypeError(js, "compress_qoi requires width and height properties"); } int width, height; if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) { - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); return JS_ThrowTypeError(js, "width and height must be numbers"); } - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); if (width < 1 || height < 1) return JS_ThrowRangeError(js, "width and height must be at least 1"); @@ -45,7 +39,6 @@ JSValue js_qoi_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a // Get pixel format JSValue format_val = JS_GetPropertyStr(js, argv[0], "format"); const char *format_str = JS_ToCString(js, format_val); - JS_FreeValue(js, format_val); if (!format_str) return JS_ThrowTypeError(js, "Invalid or missing pixel format"); @@ -60,7 +53,6 @@ JSValue js_qoi_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels"); size_t pixel_len; void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val); - JS_FreeValue(js, pixels_val); if (pixel_data == NULL) return JS_EXCEPTION; diff --git a/resize.c b/resize.c index 325697a..5da6093 100644 --- a/resize.c +++ b/resize.c @@ -19,19 +19,13 @@ JSValue js_resize_resize(JSContext *js, JSValue this_val, int argc, JSValueConst JSValue src_height_val = JS_GetPropertyStr(js, argv[0], "height"); if (JS_IsNull(src_width_val) || JS_IsNull(src_height_val)) { - JS_FreeValue(js, src_width_val); - JS_FreeValue(js, src_height_val); return JS_ThrowTypeError(js, "resize.resize requires image with width and height properties"); } int src_width, src_height; if (JS_ToInt32(js, &src_width, src_width_val) < 0 || JS_ToInt32(js, &src_height, src_height_val) < 0) { - JS_FreeValue(js, src_width_val); - JS_FreeValue(js, src_height_val); return JS_ThrowTypeError(js, "width and height must be numbers"); } - JS_FreeValue(js, src_width_val); - JS_FreeValue(js, src_height_val); // Get destination dimensions int dst_width, dst_height; @@ -48,7 +42,6 @@ JSValue js_resize_resize(JSContext *js, JSValue this_val, int argc, JSValueConst JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels"); size_t pixel_len; void *src_pixels = js_get_blob_data(js, &pixel_len, pixels_val); - JS_FreeValue(js, pixels_val); if (src_pixels == NULL) return JS_EXCEPTION; if (!src_pixels) return JS_ThrowTypeError(js, "pixels blob has no data"); @@ -75,7 +68,6 @@ JSValue js_resize_resize(JSContext *js, JSValue this_val, int argc, JSValueConst JS_FreeCString(js, filter_str); } } - JS_FreeValue(js, filter_val); } // Allocate destination buffer @@ -128,12 +120,8 @@ JSValue js_resize_fit(JSContext *js, JSValue this_val, int argc, JSValueConst *a int src_width, src_height; if (JS_ToInt32(js, &src_width, src_width_val) < 0 || JS_ToInt32(js, &src_height, src_height_val) < 0) { - JS_FreeValue(js, src_width_val); - JS_FreeValue(js, src_height_val); return JS_ThrowTypeError(js, "image must have width and height"); } - JS_FreeValue(js, src_width_val); - JS_FreeValue(js, src_height_val); int max_width, max_height; if (JS_ToInt32(js, &max_width, argv[1]) < 0 || JS_ToInt32(js, &max_height, argv[2]) < 0) @@ -158,9 +146,6 @@ JSValue js_resize_fit(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue result = js_resize_resize(js, this_val, 4, new_args); - JS_FreeValue(js, new_args[1]); - JS_FreeValue(js, new_args[2]); - return result; } @@ -183,9 +168,6 @@ JSValue js_resize_square(JSContext *js, JSValue this_val, int argc, JSValueConst JSValue result = js_resize_resize(js, this_val, 4, new_args); - JS_FreeValue(js, new_args[1]); - JS_FreeValue(js, new_args[2]); - return result; } diff --git a/stb_image_common.h b/stb_image_common.h index 8c6f736..e99d7d2 100644 --- a/stb_image_common.h +++ b/stb_image_common.h @@ -75,19 +75,17 @@ JSValue js_##fmt##_encode(JSContext *js, JSValue this_val, int argc, JSValueCons JSValue height_val = JS_GetPropertyStr(js, argv[0], "height"); \ \ if (JS_IsNull(width_val) || JS_IsNull(height_val)) { \ - JS_FreeValue(js, width_val); \ - JS_FreeValue(js, height_val); \ + \ + \ return JS_ThrowTypeError(js, #fmt ".encode requires width and height properties"); \ } \ \ int width, height; \ if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) { \ - JS_FreeValue(js, width_val); \ - JS_FreeValue(js, height_val); \ + \ + \ return JS_ThrowTypeError(js, "width and height must be numbers"); \ } \ - JS_FreeValue(js, width_val); \ - JS_FreeValue(js, height_val); \ \ if (width < 1 || height < 1) \ return JS_ThrowRangeError(js, "width and height must be at least 1"); \ @@ -95,7 +93,7 @@ JSValue js_##fmt##_encode(JSContext *js, JSValue this_val, int argc, JSValueCons JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels"); \ size_t pixel_len; \ void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val); \ - JS_FreeValue(js, pixels_val); \ + \ \ if (pixel_data == NULL) return JS_EXCEPTION; \ if (!pixel_data) return JS_ThrowTypeError(js, "pixels blob has no data"); \ diff --git a/tga.c b/tga.c index 7914f3d..1950fd3 100644 --- a/tga.c +++ b/tga.c @@ -51,19 +51,13 @@ JSValue js_tga_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue height_val = JS_GetPropertyStr(js, argv[0], "height"); if (JS_IsNull(width_val) || JS_IsNull(height_val)) { - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); return JS_ThrowTypeError(js, "tga.encode requires width and height properties"); } int width, height; if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) { - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); return JS_ThrowTypeError(js, "width and height must be numbers"); } - JS_FreeValue(js, width_val); - JS_FreeValue(js, height_val); if (width < 1 || height < 1) return JS_ThrowRangeError(js, "width and height must be at least 1"); @@ -71,7 +65,6 @@ JSValue js_tga_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels"); size_t pixel_len; void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val); - JS_FreeValue(js, pixels_val); if (pixel_data == NULL) return JS_EXCEPTION; if (!pixel_data) return JS_ThrowTypeError(js, "pixels blob has no data");