8000 Fixed WASM compatibility by avoiding panic due to absence of `os.Exe… · go-python/gpython@ed47ed3 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed47ed3

Browse files
vasilevncw
authored andcommitted
Fixed WASM compatibility by avoiding panic due to absence of os.Executable() in "js" and "wasip1" targets.
1 parent e9cde5f commit ed47ed3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

stdlib/sys/sys.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package sys
1919

2020
import (
2121
"os"
22+
"runtime"
2223

2324
"github.com/go-python/gpython/py"
2425
)
@@ -659,7 +660,14 @@ func init() {
659660

660661
executable, err := os.Executable()
661662
if err != nil {
662-
panic(err)
663+
switch runtime.GOOS {
664+
case "js", "wasip1":
665+
// These platforms don't implement os.Executable (at least as of Go
666+
// 1.21), see https://github.com/tailscale/tailscale/pull/8325
667+
executable = "gpython"
668+
default:
669+
panic(err)
670+
}
663671
}
664672

665673
globals := py.StringDict{

0 commit comments

Comments
 (0)
0