aboutsummaryrefslogtreecommitdiff
path: root/src/syscall
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-12-01 12:15:45 -0500
committerRuss Cox <rsc@golang.org>2021-12-13 18:45:54 +0000
commit2580d0e08d5e9f979b943758d3c49877fb2324cb (patch)
tree3aafccfd81087734156a1778ce2321adf345f271 /src/syscall
parent083ef5462494e81ee23316245c5d65085a3f62d9 (diff)
downloadgo-2580d0e08d5e9f979b943758d3c49877fb2324cb.tar.gz
go-2580d0e08d5e9f979b943758d3c49877fb2324cb.zip
all: gofmt -w -r 'interface{} -> any' src
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/syscall')
-rw-r--r--src/syscall/fs_js.go4
-rw-r--r--src/syscall/js/func.go4
-rw-r--r--src/syscall/js/js.go18
-rw-r--r--src/syscall/js/js_test.go18
-rw-r--r--src/syscall/net_js.go3
-rw-r--r--src/syscall/syscall_windows.go6
6 files changed, 26 insertions, 27 deletions
diff --git a/src/syscall/fs_js.go b/src/syscall/fs_js.go
index 84a554e8b9..3541446b0b 100644
--- a/src/syscall/fs_js.go
+++ b/src/syscall/fs_js.go
@@ -491,14 +491,14 @@ func Pipe(fd []int) error {
return ENOSYS
}
-func fsCall(name string, args ...interface{}) (js.Value, error) {
+func fsCall(name string, args ...any) (js.Value, error) {
type callResult struct {
val js.Value
err error
}
c := make(chan callResult, 1)
- f := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
+ f := js.FuncOf(func(this js.Value, args []js.Value) any {
var res callResult
if len(args) >= 1 { // on Node.js 8, fs.utimes calls the callback without any arguments
diff --git a/src/syscall/js/func.go b/src/syscall/js/func.go
index 77fb9e66ca..cc94972364 100644
--- a/src/syscall/js/func.go
+++ b/src/syscall/js/func.go
@@ -10,7 +10,7 @@ import "sync"
var (
funcsMu sync.Mutex
- funcs = make(map[uint32]func(Value, []Value) interface{})
+ funcs = make(map[uint32]func(Value, []Value) any)
nextFuncID uint32 = 1
)
@@ -38,7 +38,7 @@ type Func struct {
// new goroutine.
//
// Func.Release must be called to free up resources when the function will not be invoked any more.
-func FuncOf(fn func(this Value, args []Value) interface{}) Func {
+func FuncOf(fn func(this Value, args []Value) any) Func {
funcsMu.Lock()
id := nextFuncID
nextFuncID++
diff --git a/src/syscall/js/js.go b/src/syscall/js/js.go
index d80d5d63de..a5210faf7f 100644
--- a/src/syscall/js/js.go
+++ b/src/syscall/js/js.go
@@ -148,7 +148,7 @@ func Global() Value {
// | map[string]interface{} | new object |
//
// Panics if x is not one of the expected types.
-func ValueOf(x interface{}) Value {
+func ValueOf(x any) Value {
switch x := x.(type) {
case Value:
return x
@@ -192,13 +192,13 @@ func ValueOf(x interface{}) Value {
return floatValue(x)
case string:
return makeValue(stringVal(x))
- case []interface{}:
+ case []any:
a := arrayConstructor.New(len(x))
for i, s := range x {
a.SetIndex(i, s)
}
return a
- case map[string]interface{}:
+ case map[string]any:
o := objectConstructor.New()
for k, v := range x {
o.Set(k, v)
@@ -296,7 +296,7 @@ func valueGet(v ref, p string) ref
// Set sets the JavaScript property p of value v to ValueOf(x).
// It panics if v is not a JavaScript object.
-func (v Value) Set(p string, x interface{}) {
+func (v Value) Set(p string, x any) {
if vType := v.Type(); !vType.isObject() {
panic(&ValueError{"Value.Set", vType})
}
@@ -335,7 +335,7 @@ func valueIndex(v ref, i int) ref
// SetIndex sets the JavaScript index i of value v to ValueOf(x).
// It panics if v is not a JavaScript object.
-func (v Value) SetIndex(i int, x interface{}) {
+func (v Value) SetIndex(i int, x any) {
if vType := v.Type(); !vType.isObject() {
panic(&ValueError{"Value.SetIndex", vType})
}
@@ -347,7 +347,7 @@ func (v Value) SetIndex(i int, x interface{}) {
func valueSetIndex(v ref, i int, x ref)
-func makeArgs(args []interface{}) ([]Value, []ref) {
+func makeArgs(args []any) ([]Value, []ref) {
argVals := make([]Value, len(args))
argRefs := make([]ref, len(args))
for i, arg := range args {
@@ -374,7 +374,7 @@ func valueLength(v ref) int
// Call does a JavaScript call to the method m of value v with the given arguments.
// It panics if v has no method m.
// The arguments get mapped to JavaScript values according to the ValueOf function.
-func (v Value) Call(m string, args ...interface{}) Value {
+func (v Value) Call(m string, args ...any) Value {
argVals, argRefs := makeArgs(args)
res, ok := valueCall(v.ref, m, argRefs)
runtime.KeepAlive(v)
@@ -396,7 +396,7 @@ func valueCall(v ref, m string, args []ref) (ref, bool)
// Invoke does a JavaScript call of the value v with the given arguments.
// It panics if v is not a JavaScript function.
// The arguments get mapped to JavaScript values according to the ValueOf function.
-func (v Value) Invoke(args ...interface{}) Value {
+func (v Value) Invoke(args ...any) Value {
argVals, argRefs := makeArgs(args)
res, ok := valueInvoke(v.ref, argRefs)
runtime.KeepAlive(v)
@@ -415,7 +415,7 @@ func valueInvoke(v ref, args []ref) (ref, bool)
// New uses JavaScript's "new" operator with value v as constructor and the given arguments.
// It panics if v is not a JavaScript function.
// The arguments get mapped to JavaScript values according to the ValueOf function.
-func (v Value) New(args ...interface{}) Value {
+func (v Value) New(args ...any) Value {
argVals, argRefs := makeArgs(args)
res, ok := valueNew(v.ref, argRefs)
runtime.KeepAlive(v)
diff --git a/src/syscall/js/js_test.go b/src/syscall/js/js_test.go
index fa8c782459..f860a5bb50 100644
--- a/src/syscall/js/js_test.go
+++ b/src/syscall/js/js_test.go
@@ -364,8 +364,8 @@ func TestType(t *testing.T) {
}
}
-type object = map[string]interface{}
-type array = []interface{}
+type object = map[string]any
+type array = []any
func TestValueOf(t *testing.T) {
a := js.ValueOf(array{0, array{0, 42, 0}, 0})
@@ -388,7 +388,7 @@ func TestZeroValue(t *testing.T) {
func TestFuncOf(t *testing.T) {
c := make(chan struct{})
- cb := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
+ cb := js.FuncOf(func(this js.Value, args []js.Value) any {
if got := args[0].Int(); got != 42 {
t.Errorf("got %#v, want %#v", got, 42)
}
@@ -402,8 +402,8 @@ func TestFuncOf(t *testing.T) {
func TestInvokeFunction(t *testing.T) {
called := false
- cb := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
- cb2 := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
+ cb := js.FuncOf(func(this js.Value, args []js.Value) any {
+ cb2 := js.FuncOf(func(this js.Value, args []js.Value) any {
called = true
return 42
})
@@ -423,7 +423,7 @@ func TestInterleavedFunctions(t *testing.T) {
c1 := make(chan struct{})
c2 := make(chan struct{})
- js.Global().Get("setTimeout").Invoke(js.FuncOf(func(this js.Value, args []js.Value) interface{} {
+ js.Global().Get("setTimeout").Invoke(js.FuncOf(func(this js.Value, args []js.Value) any {
c1 <- struct{}{}
<-c2
return nil
@@ -432,7 +432,7 @@ func TestInterleavedFunctions(t *testing.T) {
<-c1
c2 <- struct{}{}
// this goroutine is running, but the callback of setTimeout did not return yet, invoke another function now
- f := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
+ f := js.FuncOf(func(this js.Value, args []js.Value) any {
return nil
})
f.Invoke()
@@ -440,7 +440,7 @@ func TestInterleavedFunctions(t *testing.T) {
func ExampleFuncOf() {
var cb js.Func
- cb = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
+ cb = js.FuncOf(func(this js.Value, args []js.Value) any {
fmt.Println("button clicked")
cb.Release() // release the function if the button will not be clicked again
return nil
@@ -593,7 +593,7 @@ func BenchmarkDOM(b *testing.B) {
}
func TestGlobal(t *testing.T) {
- ident := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
+ ident := js.FuncOf(func(this js.Value, args []js.Value) any {
return args[0]
})
defer ident.Release()
diff --git a/src/syscall/net_js.go b/src/syscall/net_js.go
index 253ab22dd9..2ed4e191bd 100644
--- a/src/syscall/net_js.go
+++ b/src/syscall/net_js.go
@@ -45,8 +45,7 @@ const (
SYS_FCNTL = 500 // unsupported
)
-type Sockaddr interface {
-}
+type Sockaddr any
type SockaddrInet4 struct {
Port int
diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go
index ecb1eeecf6..78e46a656d 100644
--- a/src/syscall/syscall_windows.go
+++ b/src/syscall/syscall_windows.go
@@ -169,7 +169,7 @@ func (e Errno) Timeout() bool {
}
// Implemented in runtime/syscall_windows.go.
-func compileCallback(fn interface{}, cleanstack bool) uintptr
+func compileCallback(fn any, cleanstack bool) uintptr
// NewCallback converts a Go function to a function pointer conforming to the stdcall calling convention.
// This is useful when interoperating with Windows code requiring callbacks.
@@ -177,7 +177,7 @@ func compileCallback(fn interface{}, cleanstack bool) uintptr
// Only a limited number of callbacks may be created in a single Go process, and any memory allocated
// for these callbacks is never released.
// Between NewCallback and NewCallbackCDecl, at least 1024 callbacks can always be created.
-func NewCallback(fn interface{}) uintptr {
+func NewCallback(fn any) uintptr {
return compileCallback(fn, true)
}
@@ -187,7 +187,7 @@ func NewCallback(fn interface{}) uintptr {
// Only a limited number of callbacks may be created in a single Go process, and any memory allocated
// for these callbacks is never released.
// Between NewCallback and NewCallbackCDecl, at least 1024 callbacks can always be created.
-func NewCallbackCDecl(fn interface{}) uintptr {
+func NewCallbackCDecl(fn any) uintptr {
return compileCallback(fn, false)
}