From 9c583f1fb09a4eeaf4c026c3610ceefebd5af76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Wed, 23 Sep 2026 11:18:44 +0200 Subject: [PATCH] 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. --- build.zig.zon | 4 ++-- src/browser/js/Platform.zig | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 851080c09..127a4edb9 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -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 = .{ diff --git a/src/browser/js/Platform.zig b/src/browser/js/Platform.zig index ca58de079..5525b848e 100644 --- a/src/browser/js/Platform.zig +++ b/src/browser/js/Platform.zig @@ -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).?;