Skip to content

syscall,misc/wasm: fix path expansion on non-unix platforms #68255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions misc/wasm/wasm_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
}
}

if (!globalThis.path) {
globalThis.path = {
resolve(...pathSegments) {
return pathSegments.join("/");
}
}
}

if (!globalThis.crypto) {
throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
}
Expand Down
1 change: 1 addition & 0 deletions misc/wasm/wasm_exec_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (process.argv.length < 3) {

globalThis.require = require;
globalThis.fs = require("fs");
globalThis.path = require("path");
globalThis.TextEncoder = require("util").TextEncoder;
globalThis.TextDecoder = require("util").TextDecoder;

Expand Down
7 changes: 3 additions & 4 deletions src/syscall/fs_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
func now() (sec int64, nsec int32)

var jsProcess = js.Global().Get("process")
var jsPath = js.Global().Get("path")
var jsFS = js.Global().Get("fs")
var constants = jsFS.Get("constants")

Expand Down Expand Up @@ -101,10 +102,8 @@ func Open(path string, openmode int, perm uint32) (int, error) {
}
}

if path[0] != '/' {
cwd := jsProcess.Call("cwd").String()
path = cwd + "/" + path
}
path = jsPath.Call("resolve", path).String()

f := &jsFile{
path: path,
entries: entries,
Expand Down