From 7cc1e47298226ea3dc12864edca3efb5ea2e23b3 Mon Sep 17 00:00:00 2001 From: buke <1013738+buke@users.noreply.github.com> Date: Fri, 5 Jun 2026 03:29:49 +0000 Subject: [PATCH] chore: sync quickjs-ng release v0.15.1 --- deps/quickjs-release.env | 8 ++-- deps/quickjs/CMakeLists.txt | 1 + deps/quickjs/api-test.c | 63 ++++++++++++++++++++++++++++++ deps/quickjs/docs/docs/projects.md | 4 ++ deps/quickjs/meson.build | 2 +- deps/quickjs/qjs.c | 16 +++++--- deps/quickjs/quickjs-libc.c | 43 ++++++++++++++------ deps/quickjs/quickjs.c | 7 ++++ deps/quickjs/quickjs.h | 2 +- 9 files changed, 122 insertions(+), 24 deletions(-) diff --git a/deps/quickjs-release.env b/deps/quickjs-release.env index 3b19c5c..1bbeed4 100644 --- a/deps/quickjs-release.env +++ b/deps/quickjs-release.env @@ -1,5 +1,5 @@ QUICKJS_NG_REPO="quickjs-ng/quickjs" -QUICKJS_NG_TAG="v0.15.0" -QUICKJS_NG_TARBALL_URL="https://api.github.com/repos/quickjs-ng/quickjs/tarball/v0.15.0" -QUICKJS_NG_RELEASE_URL="https://github.com/quickjs-ng/quickjs/releases/tag/v0.15.0" -QUICKJS_NG_RELEASED_AT="2026-05-21T20:51:23Z" +QUICKJS_NG_TAG="v0.15.1" +QUICKJS_NG_TARBALL_URL="https://api.github.com/repos/quickjs-ng/quickjs/tarball/v0.15.1" +QUICKJS_NG_RELEASE_URL="https://github.com/quickjs-ng/quickjs/releases/tag/v0.15.1" +QUICKJS_NG_RELEASED_AT="2026-06-04T14:57:07Z" diff --git a/deps/quickjs/CMakeLists.txt b/deps/quickjs/CMakeLists.txt index 82f3665..4b4bf8e 100644 --- a/deps/quickjs/CMakeLists.txt +++ b/deps/quickjs/CMakeLists.txt @@ -421,6 +421,7 @@ endif() if(QJS_BUILD_CLI_WITH_MIMALLOC OR QJS_BUILD_CLI_WITH_STATIC_MIMALLOC) find_package(mimalloc REQUIRED) + target_compile_definitions(qjs_exe PRIVATE QJS_USE_MIMALLOC) # Upstream mimalloc doesn't provide a way to know if both libraries are supported. if(QJS_BUILD_CLI_WITH_STATIC_MIMALLOC) target_link_libraries(qjs_exe PRIVATE mimalloc-static) diff --git a/deps/quickjs/api-test.c b/deps/quickjs/api-test.c index 7aa7dc8..a45dfb3 100644 --- a/deps/quickjs/api-test.c +++ b/deps/quickjs/api-test.c @@ -956,6 +956,68 @@ static void immutable_array_buffer(void) JS_FreeRuntime(rt); } +static void *sab_test_alloc(void *opaque, size_t size) +{ + return malloc(size); +} + +static void sab_test_free(void *opaque, void *ptr) +{ + free(ptr); +} + +static void shared_array_buffer_growth(void) +{ + JSRuntime *rt = new_runtime(); + JSContext *ctx = JS_NewContext(rt); + JSValue ret, exception; + + ret = eval(ctx, "new SharedArrayBuffer(16)"); + assert(!JS_IsException(ret)); + JS_FreeValue(ctx, ret); + + ret = eval(ctx, + "const sab = new SharedArrayBuffer(16, { maxByteLength: 16 });" + "sab.grow(16);" + "sab.byteLength === 16 && sab.maxByteLength === 16"); + assert(!JS_IsException(ret)); + assert(JS_IsBool(ret)); + assert(JS_VALUE_GET_BOOL(ret)); + JS_FreeValue(ctx, ret); + + ret = eval(ctx, "new SharedArrayBuffer(16, { maxByteLength: 16384 })"); + assert(JS_IsException(ret)); + assert(JS_HasException(ctx)); + exception = JS_GetException(ctx); + assert(JS_IsError(exception)); + JS_FreeValue(ctx, exception); + + JS_FreeContext(ctx); + JS_FreeRuntime(rt); + + JSSharedArrayBufferFunctions funcs = { + .sab_alloc = sab_test_alloc, + .sab_free = sab_test_free, + .sab_dup = NULL, + .sab_opaque = NULL, + }; + + rt = new_runtime(); + JS_SetSharedArrayBufferFunctions(rt, &funcs); + ctx = JS_NewContext(rt); + ret = eval(ctx, + "const sab = new SharedArrayBuffer(16, { maxByteLength: 16384 });" + "const u8 = new Uint8Array(sab);" + "sab.grow(16384);" + "u8[1024] === 0 && u8.byteLength === 16384"); + assert(!JS_IsException(ret)); + assert(JS_IsBool(ret)); + assert(JS_VALUE_GET_BOOL(ret)); + JS_FreeValue(ctx, ret); + JS_FreeContext(ctx); + JS_FreeRuntime(rt); +} + static void get_uint8array(void) { JSRuntime *rt = new_runtime(); @@ -1088,6 +1150,7 @@ int main(void) global_object_prototype(); slice_string_tocstring(); immutable_array_buffer(); + shared_array_buffer_growth(); get_uint8array(); new_symbol(); return 0; diff --git a/deps/quickjs/docs/docs/projects.md b/deps/quickjs/docs/docs/projects.md index cc7257e..8404aef 100644 --- a/deps/quickjs/docs/docs/projects.md +++ b/deps/quickjs/docs/docs/projects.md @@ -82,3 +82,7 @@ Golang bindings for QuickJS-NG using cgo ## [Nordstjernen](https://github.com/nordstjernen-web/nordstjernen) Nordstjernen web browser. + +## [quickjs-cpp](https://github.com/qr243vbi/quickjs-cpp) + +Header only library for quickjs-ng with modern C++ interface. diff --git a/deps/quickjs/meson.build b/deps/quickjs/meson.build index 35d7270..b7b1638 100644 --- a/deps/quickjs/meson.build +++ b/deps/quickjs/meson.build @@ -1,7 +1,7 @@ project( 'quickjs-ng', 'c', - version: '0.15.0', + version: '0.15.1', default_options: [ 'c_std=gnu11,c11', 'warning_level=3', diff --git a/deps/quickjs/qjs.c b/deps/quickjs/qjs.c index 939e151..bdf8d2d 100644 --- a/deps/quickjs/qjs.c +++ b/deps/quickjs/qjs.c @@ -372,11 +372,12 @@ static const JSMallocFunctions mi_mf = { #define PROG_NAME "qjs" -void help(void) +void help(int exit_status) { printf("QuickJS-ng version %s\n" "usage: " PROG_NAME " [options] [file [args]]\n" "-h --help list options\n" + "-v --version print version string and then exit\n" "-e --eval EXPR evaluate EXPR\n" "-i --interactive go to interactive mode\n" "-C --script load as JS classic script (default=autodetect)\n" @@ -392,7 +393,7 @@ void help(void) " --memory-limit n limit the memory usage to 'n' Kbytes\n" " --stack-size n limit the stack size to 'n' Kbytes\n" "-q --quit just instantiate the interpreter and quit\n", JS_GetVersion()); - exit(1); + exit(exit_status); } int main(int argc, char **argv) @@ -465,8 +466,11 @@ int main(int argc, char **argv) optarg = arg; } if (opt == 'h' || opt == '?' || !strcmp(longopt, "help")) { - help(); - continue; + help(0); + } + if (opt == 'v' || !strcmp(longopt, "version")) { + printf("%s\n",JS_GetVersion()); + return 0; } if (opt == 'e' || !strcmp(longopt, "eval")) { if (!optarg) { @@ -583,12 +587,12 @@ int main(int argc, char **argv) } else { fprintf(stderr, "qjs: unknown option '--%s'\n", longopt); } - help(); + help(1); } } if (compile_file && !out) - help(); + help(1); start: diff --git a/deps/quickjs/quickjs-libc.c b/deps/quickjs/quickjs-libc.c index 56c3845..6926733 100644 --- a/deps/quickjs/quickjs-libc.c +++ b/deps/quickjs/quickjs-libc.c @@ -4720,22 +4720,41 @@ static void js_dump_obj(JSContext *ctx, FILE *f, JSValueConst val) } } +#define JS_DUMP_ERROR_MAX_CAUSE_DEPTH 10 + static void js_std_dump_error1(JSContext *ctx, JSValueConst exception_val) { - JSValue val; + JSValue val, current; bool is_error; - - is_error = JS_IsError(exception_val); - js_dump_obj(ctx, stderr, exception_val); - if (is_error) { - val = JS_GetPropertyStr(ctx, exception_val, "stack"); - } else { - js_std_cmd(/*ErrorBackTrace*/2, ctx, &val); - } - if (!JS_IsUndefined(val)) { - js_dump_obj(ctx, stderr, val); - JS_FreeValue(ctx, val); + int depth; + + current = JS_DupValue(ctx, exception_val); + for (depth = 0; ; depth++) { + is_error = JS_IsError(current); + js_dump_obj(ctx, stderr, current); + if (is_error) { + val = JS_GetPropertyStr(ctx, current, "stack"); + } else if (depth == 0) { + js_std_cmd(/*ErrorBackTrace*/2, ctx, &val); + } else { + val = JS_UNDEFINED; + } + if (!JS_IsUndefined(val)) { + js_dump_obj(ctx, stderr, val); + JS_FreeValue(ctx, val); + } + if (!is_error || depth >= JS_DUMP_ERROR_MAX_CAUSE_DEPTH) + break; + val = JS_GetPropertyStr(ctx, current, "cause"); + if (JS_IsUndefined(val)) { + JS_FreeValue(ctx, val); + break; + } + fputs("Caused by: ", stderr); + JS_FreeValue(ctx, current); + current = val; } + JS_FreeValue(ctx, current); } void js_std_dump_error(JSContext *ctx) diff --git a/deps/quickjs/quickjs.c b/deps/quickjs/quickjs.c index 38a724f..11caae0 100644 --- a/deps/quickjs/quickjs.c +++ b/deps/quickjs/quickjs.c @@ -57748,6 +57748,13 @@ static JSValue js_array_buffer_constructor3(JSContext *ctx, JS_ThrowRangeError(ctx, "invalid max array buffer length"); goto fail; } + if (alloc_flag && class_id == JS_CLASS_SHARED_ARRAY_BUFFER && max_len && + *max_len > len && !rt->sab_funcs.sab_alloc) { + JS_ThrowTypeError(ctx, + "growable SharedArrayBuffer requires " + "SAB allocator hooks"); + goto fail; + } abuf = js_malloc(ctx, sizeof(*abuf)); if (!abuf) goto fail; diff --git a/deps/quickjs/quickjs.h b/deps/quickjs/quickjs.h index b9ed275..68d6f38 100644 --- a/deps/quickjs/quickjs.h +++ b/deps/quickjs/quickjs.h @@ -1409,7 +1409,7 @@ JS_EXTERN int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m, #define QJS_VERSION_MAJOR 0 #define QJS_VERSION_MINOR 15 -#define QJS_VERSION_PATCH 0 +#define QJS_VERSION_PATCH 1 #define QJS_VERSION_SUFFIX "" JS_EXTERN const char* JS_GetVersion(void);