Skip to content

Commit bcec5f1

Browse files
Zxillyjohanbrandhorst
authored andcommitted
syscall,misc/wasm: fix path expansion on non-unix platforms
When running a go binary compiled to wasm using node.js on a Windows platform, the absolute path passed in is also incorrectly forced to expand. For example: E:\Project\CS_Project\gsv\testdata\result.gob.gz will results to open C:\Users\zxilly\AppData\Local\wasm-exec\go1.23rc1\E:\Project\CS_Project\gsv\testdata\result.gob.gz: No such file or directory C:\Users\zxilly\AppData\Local\wasm-exec\go1.23rc1 is the place of wasm_exec_node.js Fixes: #68820 Change-Id: Ic30c6242302f8915ac1b8ea9f24546935cbb791e GitHub-Last-Rev: f35ff1a GitHub-Pull-Request: #68255 Reviewed-on: https://go-review.googlesource.com/c/go/+/595797 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Johan Brandhorst-Satzkorn <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Johan Brandhorst-Satzkorn <[email protected]>
1 parent c8ccbcd commit bcec5f1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

misc/wasm/wasm_exec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@
7373
}
7474
}
7575

76+
if (!globalThis.path) {
77+
globalThis.path = {
78+
resolve(...pathSegments) {
79+
return pathSegments.join("/");
80+
}
81+
}
82+
}
83+
7684
if (!globalThis.crypto) {
7785
throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
7886
}

misc/wasm/wasm_exec_node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if (process.argv.length < 3) {
1111

1212
globalThis.require = require;
1313
globalThis.fs = require("fs");
14+
globalThis.path = require("path");
1415
globalThis.TextEncoder = require("util").TextEncoder;
1516
globalThis.TextDecoder = require("util").TextDecoder;
1617

src/syscall/fs_js.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
func now() (sec int64, nsec int32)
1717

1818
var jsProcess = js.Global().Get("process")
19+
var jsPath = js.Global().Get("path")
1920
var jsFS = js.Global().Get("fs")
2021
var constants = jsFS.Get("constants")
2122

@@ -101,10 +102,8 @@ func Open(path string, openmode int, perm uint32) (int, error) {
101102
}
102103
}
103104

104-
if path[0] != '/' {
105-
cwd := jsProcess.Call("cwd").String()
106-
path = cwd + "/" + path
107-
}
105+
path = jsPath.Call("resolve", path).String()
106+
108107
f := &jsFile{
109108
path: path,
110109
entries: entries,

0 commit comments

Comments
 (0)