Skip to content

Commit 9e2a4f4

Browse files
neelancebradfitz
authored andcommitted
syscall: remove support for O_NONBLOCK and O_SYNC on js/wasm
This commit removes O_NONBLOCK on js/wasm. O_SYNC can't be removed, because it is referenced by the os package, so instead its use returns an error. On Windows, the options O_NONBLOCK and O_SYNC are not available when opening a file with Node.js. This caused the initialization of the syscall package to panic. The simplest solution is to not support these two options on js/wasm at all. Code written for js/wasm is supposed to be portable, so platform-specific options should not be used. Fixes golang#26524. Change-Id: I366aa3cdcfa59dfa9dc513368259f363ca090f00 Reviewed-on: https://go-review.googlesource.com/126600 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 137f2fb commit 9e2a4f4

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

misc/wasm/wasm_exec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
let outputBuf = "";
3939
global.fs = {
40-
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1, O_NONBLOCK: -1, O_SYNC: -1 }, // unused
40+
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused
4141
writeSync(fd, buf) {
4242
outputBuf += decoder.decode(buf);
4343
const nl = outputBuf.lastIndexOf("\n");

src/syscall/fs_js.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package syscall
88

99
import (
10+
"errors"
1011
"io"
1112
"sync"
1213
"syscall/js"
@@ -20,14 +21,12 @@ var jsFS = js.Global().Get("fs")
2021
var constants = jsFS.Get("constants")
2122

2223
var (
23-
nodeWRONLY = constants.Get("O_WRONLY").Int()
24-
nodeRDWR = constants.Get("O_RDWR").Int()
25-
nodeCREATE = constants.Get("O_CREAT").Int()
26-
nodeTRUNC = constants.Get("O_TRUNC").Int()
27-
nodeAPPEND = constants.Get("O_APPEND").Int()
28-
nodeEXCL = constants.Get("O_EXCL").Int()
29-
nodeNONBLOCK = constants.Get("O_NONBLOCK").Int()
30-
nodeSYNC = constants.Get("O_SYNC").Int()
24+
nodeWRONLY = constants.Get("O_WRONLY").Int()
25+
nodeRDWR = constants.Get("O_RDWR").Int()
26+
nodeCREATE = constants.Get("O_CREAT").Int()
27+
nodeTRUNC = constants.Get("O_TRUNC").Int()
28+
nodeAPPEND = constants.Get("O_APPEND").Int()
29+
nodeEXCL = constants.Get("O_EXCL").Int()
3130
)
3231

3332
type jsFile struct {
@@ -78,11 +77,8 @@ func Open(path string, openmode int, perm uint32) (int, error) {
7877
if openmode&O_EXCL != 0 {
7978
flags |= nodeEXCL
8079
}
81-
if openmode&O_NONBLOCK != 0 {
82-
flags |= nodeNONBLOCK
83-
}
8480
if openmode&O_SYNC != 0 {
85-
flags |= nodeSYNC
81+
return 0, errors.New("syscall.Open: O_SYNC is not supported by js/wasm")
8682
}
8783

8884
jsFD, err := fsCall("openSync", path, flags, perm)

src/syscall/syscall_js.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,12 @@ const (
103103
O_WRONLY = 1
104104
O_RDWR = 2
105105

106-
O_CREAT = 0100
107-
O_CREATE = O_CREAT
108-
O_TRUNC = 01000
109-
O_APPEND = 02000
110-
O_EXCL = 0200
111-
O_NONBLOCK = 04000
112-
O_SYNC = 010000
106+
O_CREAT = 0100
107+
O_CREATE = O_CREAT
108+
O_TRUNC = 01000
109+
O_APPEND = 02000
110+
O_EXCL = 0200
111+
O_SYNC = 010000
113112

114113
O_CLOEXEC = 0
115114
)

0 commit comments

Comments
 (0)