Skip to content

Commit f35ff1a

Browse files
committed
syscall, misc/wasm: fix path expansion on non-unix platforms
1 parent 82c371a commit f35ff1a

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

misc/wasm/wasm_exec.js

+8
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

+1
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

+3-4
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)