js: hand --locale to ICU instead of LC_ALL

A BCP 47 tag in LC_ALL is not a POSIX locale, so setlocale(LC_ALL, "")
failed for the rest of the process and for any child. In the REPL,
isocline took the terminal for non-UTF-8 and dropped every non-ASCII
keystroke. Set ICU's default locale through the new
v8__V8__SetDefaultLocale binding and leave the C library alone.

Pins zig-v8-fork to lightpanda-io/zig-v8-fork#209; CI links once that is
tagged and action.yml's zig-v8 is bumped.
This commit is contained in:
Adrià Arrufat committed 2026-09-23 11:18:44 +02:00
1 parent 1df5838bdb
commit 9c583f1fb0
2 files changed
+11 -9

No files matched your search

+2 -2
View File
@@ -5,8 +5,8 @@
.minimum_zig_version = "0.16.0",
.dependencies = .{
.v8 = .{
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/d3d7b41677a0015fdfa55a8b1caa4f214de6d209.tar.gz",
.hash = "v8-0.0.0-xddH624yAwC5_H_8T303uTxiSAnAu2zrxv6MHLhvLo6t",
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/0cc0b28d18f021c560d6f84b7e27e5a7ade9f8c8.tar.gz",
.hash = "v8-0.0.0-xddH6_g0AwBnqBwDOD22Mks8ODHFsH6SffwcpFoUSq3X",
},
// .v8 = .{ .path = "../zig-v8-fork" },
.brotli = .{
+9 -7
View File
@@ -30,18 +30,17 @@ pub const Options = struct {
timezone: ?[:0]const u8 = null,
};
/// ICU reads LC_ALL and TZ lazily on first use, so the environment must be
/// set here, before InitializeICU and before the platform starts its thread
/// pool (setenv is not safe once other threads may call getenv). ICU
/// canonicalizes a BCP 47 tag itself, script subtag included.
/// ICU reads TZ lazily on first use, so it must be set here, before
/// InitializeICU and before the platform starts its thread pool (setenv is not
/// safe once other threads may call getenv). The locale goes to ICU directly:
/// a BCP 47 tag in LC_ALL is not a POSIX locale, so it broke setlocale for the
/// rest of the process and for every child. ICU canonicalizes the tag itself,
/// script subtag included.
pub fn init(opts: Options) !Platform {
if (opts.v8_flags) |flags| {
v8.v8__V8__SetFlagsFromString(flags.ptr, flags.len);
}
if (opts.locale) |tag| {
_ = setenv("LC_ALL", tag, 1);
}
if (opts.timezone) |id| {
_ = setenv("TZ", id, 1);
}
@@ -49,6 +48,9 @@ pub fn init(opts: Options) !Platform {
if (v8.v8__V8__InitializeICU() == false) {
return error.FailedToInitializeICU;
}
if (opts.locale) |tag| {
if (!v8.v8__V8__SetDefaultLocale(tag)) return error.InvalidLocale;
}
// 0 - threadpool size, 0 == let v8 decide
// 1 - idle_task_support, 1 == enabled
const handle = v8.v8__Platform__NewDefaultPlatform(0, 1).?;