瀏覽代碼

Meta: Initialize the WASM JS REPL with a known time zone

The runtime environment of the WASM REPL does not have time zone
information; the file system is virtual (does not have /etc/localtime),
and the TZ environment variable is not set. This causes LibTimeZone to
always fall back to UTC.

Instead, we can get the time zone from the user's browser before we
enter this limited environment. The REPL website will pass the time zone
into the WASM REPL.
Timothy Flynn 2 年之前
父節點
當前提交
91b3a3bb58
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      Meta/Lagom/Wasm/js_repl.cpp

+ 5 - 1
Meta/Lagom/Wasm/js_repl.cpp

@@ -29,6 +29,7 @@
 #include <fcntl.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
 #ifndef AK_OS_EMSCRIPTEN
 #ifndef AK_OS_EMSCRIPTEN
@@ -349,8 +350,11 @@ private:
     int m_group_stack_depth { 0 };
     int m_group_stack_depth { 0 };
 };
 };
 
 
-extern "C" int initialize_repl()
+extern "C" int initialize_repl(char const* time_zone)
 {
 {
+    if (time_zone)
+        setenv("TZ", time_zone, 1);
+
     g_vm = JS::VM::create();
     g_vm = JS::VM::create();
     g_vm->enable_default_host_import_module_dynamically_hook();
     g_vm->enable_default_host_import_module_dynamically_hook();