mirror of https://github.com/golang/go.git
syscall, misc/wasm: fix path expansion on non-unix platforms
This commit is contained in:
parent
82c371a307
commit
f35ff1a2ee
|
|
@ -73,6 +73,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!globalThis.path) {
|
||||||
|
globalThis.path = {
|
||||||
|
resolve(...pathSegments) {
|
||||||
|
return pathSegments.join("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!globalThis.crypto) {
|
if (!globalThis.crypto) {
|
||||||
throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
|
throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ if (process.argv.length < 3) {
|
||||||
|
|
||||||
globalThis.require = require;
|
globalThis.require = require;
|
||||||
globalThis.fs = require("fs");
|
globalThis.fs = require("fs");
|
||||||
|
globalThis.path = require("path");
|
||||||
globalThis.TextEncoder = require("util").TextEncoder;
|
globalThis.TextEncoder = require("util").TextEncoder;
|
||||||
globalThis.TextDecoder = require("util").TextDecoder;
|
globalThis.TextDecoder = require("util").TextDecoder;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import (
|
||||||
func now() (sec int64, nsec int32)
|
func now() (sec int64, nsec int32)
|
||||||
|
|
||||||
var jsProcess = js.Global().Get("process")
|
var jsProcess = js.Global().Get("process")
|
||||||
|
var jsPath = js.Global().Get("path")
|
||||||
var jsFS = js.Global().Get("fs")
|
var jsFS = js.Global().Get("fs")
|
||||||
var constants = jsFS.Get("constants")
|
var constants = jsFS.Get("constants")
|
||||||
|
|
||||||
|
|
@ -101,10 +102,8 @@ func Open(path string, openmode int, perm uint32) (int, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if path[0] != '/' {
|
path = jsPath.Call("resolve", path).String()
|
||||||
cwd := jsProcess.Call("cwd").String()
|
|
||||||
path = cwd + "/" + path
|
|
||||||
}
|
|
||||||
f := &jsFile{
|
f := &jsFile{
|
||||||
path: path,
|
path: path,
|
||||||
entries: entries,
|
entries: entries,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue