]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: remove support for O_NONBLOCK and O_SYNC on js/wasm
authorRichard Musiol <mail@richard-musiol.de>
Sat, 28 Jul 2018 11:45:02 +0000 (13:45 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 31 Jul 2018 17:03:39 +0000 (17:03 +0000)
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 #26524.

Change-Id: I366aa3cdcfa59dfa9dc513368259f363ca090f00
Reviewed-on: https://go-review.googlesource.com/126600
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/wasm/wasm_exec.js
src/syscall/fs_js.go
src/syscall/syscall_js.go

index 02a753c823036047e5474f427d4a34181bed7f02..f3772652da3f757011f5bd0141a9597fcac6a51a 100644 (file)
@@ -37,7 +37,7 @@
 
                let outputBuf = "";
                global.fs = {
-                       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
+                       constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused
                        writeSync(fd, buf) {
                                outputBuf += decoder.decode(buf);
                                const nl = outputBuf.lastIndexOf("\n");
index 36e9140759265574d57ae2f9c25862f3e600d94b..00d6c769791efd0ab0abfa203a2d07b8666fb27e 100644 (file)
@@ -7,6 +7,7 @@
 package syscall
 
 import (
+       "errors"
        "io"
        "sync"
        "syscall/js"
@@ -20,14 +21,12 @@ var jsFS = js.Global().Get("fs")
 var constants = jsFS.Get("constants")
 
 var (
-       nodeWRONLY   = constants.Get("O_WRONLY").Int()
-       nodeRDWR     = constants.Get("O_RDWR").Int()
-       nodeCREATE   = constants.Get("O_CREAT").Int()
-       nodeTRUNC    = constants.Get("O_TRUNC").Int()
-       nodeAPPEND   = constants.Get("O_APPEND").Int()
-       nodeEXCL     = constants.Get("O_EXCL").Int()
-       nodeNONBLOCK = constants.Get("O_NONBLOCK").Int()
-       nodeSYNC     = constants.Get("O_SYNC").Int()
+       nodeWRONLY = constants.Get("O_WRONLY").Int()
+       nodeRDWR   = constants.Get("O_RDWR").Int()
+       nodeCREATE = constants.Get("O_CREAT").Int()
+       nodeTRUNC  = constants.Get("O_TRUNC").Int()
+       nodeAPPEND = constants.Get("O_APPEND").Int()
+       nodeEXCL   = constants.Get("O_EXCL").Int()
 )
 
 type jsFile struct {
@@ -78,11 +77,8 @@ func Open(path string, openmode int, perm uint32) (int, error) {
        if openmode&O_EXCL != 0 {
                flags |= nodeEXCL
        }
-       if openmode&O_NONBLOCK != 0 {
-               flags |= nodeNONBLOCK
-       }
        if openmode&O_SYNC != 0 {
-               flags |= nodeSYNC
+               return 0, errors.New("syscall.Open: O_SYNC is not supported by js/wasm")
        }
 
        jsFD, err := fsCall("openSync", path, flags, perm)
index 356d925462ca020989996ddd96debfe49240c53d..6822eec8359cabdaefc26c96dbf1f8b8ad3c856d 100644 (file)
@@ -103,13 +103,12 @@ const (
        O_WRONLY = 1
        O_RDWR   = 2
 
-       O_CREAT    = 0100
-       O_CREATE   = O_CREAT
-       O_TRUNC    = 01000
-       O_APPEND   = 02000
-       O_EXCL     = 0200
-       O_NONBLOCK = 04000
-       O_SYNC     = 010000
+       O_CREAT  = 0100
+       O_CREATE = O_CREAT
+       O_TRUNC  = 01000
+       O_APPEND = 02000
+       O_EXCL   = 0200
+       O_SYNC   = 010000
 
        O_CLOEXEC = 0
 )