From 168dfe4d09f51e95ec53b41d662309fb4415f683 Mon Sep 17 00:00:00 2001 From: The Ghost of FOSS' Future <163201376+sneedgroup-holder@users.noreply.github.com> Date: Wed, 8 Jan 2025 23:00:34 +0000 Subject: [PATCH] Update qjs.c --- qjs.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/qjs.c b/qjs.c index de9baad..e5f3780 100644 --- a/qjs.c +++ b/qjs.c @@ -138,6 +138,20 @@ static int eval_file(JSContext *ctx, const char *filename, int module) uint8_t *buf; int ret, eval_flags; size_t buf_len; + buf = js_load_file(ctx, &buf_len, filename); + if (!buf) { + perror(filename); + exit(1); + } + + if (module < 0) { + module = (js__has_suffix(filename, ".mjs") || + JS_DetectModule((const char *)buf, buf_len)); + } + if (module) + eval_flags = JS_EVAL_TYPE_MODULE; + else + eval_flags = JS_EVAL_TYPE_GLOBAL; //POLYFILLS FOR QJS FILES BEGIN const char *pf = "globalThis.global = globalThis;\n" "global.console.error = console.log\n" @@ -167,23 +181,7 @@ static int eval_file(JSContext *ctx, const char *filename, int module) "}\n"; eval_buf(ctx, pf, strlen(pf), "", JS_EVAL_TYPE_MODULE); - - - buf = js_load_file(ctx, &buf_len, filename); - if (!buf) { - perror(filename); - exit(1); - } - - if (module < 0) { - module = (js__has_suffix(filename, ".mjs") || - JS_DetectModule((const char *)buf, buf_len)); - } - if (module) - eval_flags = JS_EVAL_TYPE_MODULE; - else - eval_flags = JS_EVAL_TYPE_GLOBAL; - + ret = eval_buf(ctx, buf, buf_len, filename, eval_flags); js_free(ctx, buf); return ret;