From 38a3697e28f628f527697240fe4b15be3edbb9f6 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Mon, 19 Jan 2026 14:39:55 -0600 Subject: [PATCH] meme --- internal/engine.cm | 2 -- source/quickjs.c | 61 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/internal/engine.cm b/internal/engine.cm index 078355a7..e539d440 100644 --- a/internal/engine.cm +++ b/internal/engine.cm @@ -56,8 +56,6 @@ globalThis.ends_with = function(str, suffix) { var js = use_embed('js') var fd = use_embed('fd') -os.print(fd) - // Get the shop path from HOME environment var home = os.getenv('HOME') || os.getenv('USERPROFILE') if (!home) { diff --git a/source/quickjs.c b/source/quickjs.c index 25e5ee83..51823c02 100644 --- a/source/quickjs.c +++ b/source/quickjs.c @@ -36572,36 +36572,61 @@ static JSValue js_cell_meme(JSContext *ctx, JSValueConst this_val, if (JS_IsException(result)) return result; - /* Apply mixins */ - for (int i = 1; i < argc; i++) { - JSValue mix = argv[i]; - if (!JS_IsObject(mix) || JS_IsNull(mix) || JS_IsArray(ctx, mix)) - continue; + if (argc < 2) + return result; - JSPropertyEnum *tab; - uint32_t len; + JSValue mixins = argv[1]; - if (JS_GetOwnPropertyNames(ctx, &tab, &len, mix, - JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) < 0) { + /* Helper function to apply a single mixin */ + #define APPLY_MIXIN(mix) do { \ + if (!JS_IsObject(mix) || JS_IsNull(mix) || JS_IsArray(ctx, mix)) \ + break; \ + JSPropertyEnum *tab; \ + uint32_t len; \ + if (JS_GetOwnPropertyNames(ctx, &tab, &len, mix, \ + JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) < 0) { \ + JS_FreeValue(ctx, result); \ + return JS_EXCEPTION; \ + } \ + for (uint32_t j = 0; j < len; j++) { \ + JSValue val = JS_GetProperty(ctx, mix, tab[j].atom); \ + if (JS_IsException(val)) { \ + for (uint32_t k = j; k < len; k++) \ + JS_FreeAtom(ctx, tab[k].atom); \ + js_free(ctx, tab); \ + JS_FreeValue(ctx, result); \ + return JS_EXCEPTION; \ + } \ + JS_SetProperty(ctx, result, tab[j].atom, val); \ + JS_FreeAtom(ctx, tab[j].atom); \ + } \ + js_free(ctx, tab); \ + } while (0) + + if (JS_IsArray(ctx, mixins)) { + /* Array of mixins */ + int64_t len; + if (js_get_length64(ctx, &len, mixins)) { JS_FreeValue(ctx, result); return JS_EXCEPTION; } - for (uint32_t j = 0; j < len; j++) { - JSValue val = JS_GetProperty(ctx, mix, tab[j].atom); - if (JS_IsException(val)) { - for (uint32_t k = j; k < len; k++) - JS_FreeAtom(ctx, tab[k].atom); - js_free(ctx, tab); + for (int64_t i = 0; i < len; i++) { + JSValue mix = JS_GetPropertyInt64(ctx, mixins, i); + if (JS_IsException(mix)) { JS_FreeValue(ctx, result); return JS_EXCEPTION; } - JS_SetProperty(ctx, result, tab[j].atom, val); - JS_FreeAtom(ctx, tab[j].atom); + APPLY_MIXIN(mix); + JS_FreeValue(ctx, mix); } - js_free(ctx, tab); + } else if (JS_IsObject(mixins) && !JS_IsNull(mixins)) { + /* Single mixin object */ + APPLY_MIXIN(mixins); } + #undef APPLY_MIXIN + return result; }