From 014f56e05449eccc69b807385b8937a0e8dbf76a Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 3 Dec 2025 22:49:59 -0600 Subject: [PATCH] fix blob get --- sdl/audio.c | 4 ++-- sdl/surface.c | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/sdl/audio.c b/sdl/audio.c index da82ded6..93aa561a 100644 --- a/sdl/audio.c +++ b/sdl/audio.c @@ -298,8 +298,8 @@ JSC_CCALL(convert_audio_samples, SDL_AudioSpec dst_spec = js2SDL_AudioSpec(js, argv[1]); size_t src_len; void *src_data = js_get_blob_data(js, &src_len, argv[2]); - if (src_data == -1) - ret = JS_EXCEPTION; + if (src_data == -1) { + ret = JS_EXCEPTION; } else { Uint8 *dst_data = NULL; int dst_len = 0; diff --git a/sdl/surface.c b/sdl/surface.c index 27443885..b74782f8 100644 --- a/sdl/surface.c +++ b/sdl/surface.c @@ -711,9 +711,14 @@ static SDL_Surface* image_to_surface(JSContext *js, JSValue img_obj) // Get pixels JSValue pixels_val = JS_GetPropertyStr(js, img_obj, "pixels"); size_t pixel_len; - void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val, &pixel_data); + void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val); + + if (pixel_data == -1) { + JS_FreeValue(js, pixels_val); + return NULL; + } - if (blob_result == -1 || blob_result == 0 || !pixel_data) { + if (!pixel_data) { JS_FreeValue(js, pixels_val); return NULL; } @@ -947,19 +952,13 @@ JSC_CCALL(surface_convert_generic, // Get source pixels JSValue src_pixels_val = JS_GetPropertyStr(js, argv[0], "pixels"); size_t src_len; - void *src_pixels; - int blob_result = js_get_blob_data(js, &src_len, src_pixels_val, &src_pixels); + void *src_pixels = js_get_blob_data(js, &src_len, src_pixels_val); - if (blob_result == -1) { + if (src_pixels == -1) { JS_FreeValue(js, src_pixels_val); return JS_EXCEPTION; } - if (blob_result == 0 || !src_pixels) { - JS_FreeValue(js, src_pixels_val); - return JS_ThrowTypeError(js, "source pixels must be an ArrayBuffer"); - } - // Get source pitch (optional, calculate if not provided) int src_pitch; JSValue src_pitch_val = JS_GetPropertyStr(js, argv[0], "pitch");