staticcheck linters broke until recent golangci-lint. Now, normal behaviour of enforcing no nil context works again. Ex. ``` assemblyscript/assemblyscript_example_test.go:16:25: SA1012: do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use (staticcheck) r := wazero.NewRuntime(nil) ``` Since default lint already checks for nil context, this removes our permission of nil context args. The original reason we permitted nil is no longer valid: we once allowed context to be stashed in config, and removed that as it caused bugs. We forgot to undo allowing nil explicitly. Note: this doesn't particularly check in our code for nil context, similar as we don't particularly check in our code for nil anything else. End users should use linters as none of our parameters should be nil anyway. Signed-off-by: Adrian Cole <adrian@tetrate.io>
125 lines
3.1 KiB
Go
125 lines
3.1 KiB
Go
package wasm
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/tetratelabs/wazero/api"
|
|
)
|
|
|
|
type mutableGlobal struct {
|
|
g *GlobalInstance
|
|
}
|
|
|
|
// compile-time check to ensure mutableGlobal is a api.Global.
|
|
var _ api.Global = &mutableGlobal{}
|
|
|
|
// Type implements the same method as documented on api.Global.
|
|
func (g *mutableGlobal) Type() api.ValueType {
|
|
return g.g.Type.ValType
|
|
}
|
|
|
|
// Get implements the same method as documented on api.Global.
|
|
func (g *mutableGlobal) Get(_ context.Context) uint64 {
|
|
return g.g.Val
|
|
}
|
|
|
|
// Set implements the same method as documented on api.MutableGlobal.
|
|
func (g *mutableGlobal) Set(_ context.Context, v uint64) {
|
|
g.g.Val = v
|
|
}
|
|
|
|
// String implements fmt.Stringer
|
|
func (g *mutableGlobal) String() string {
|
|
switch g.Type() {
|
|
case ValueTypeI32, ValueTypeI64:
|
|
return fmt.Sprintf("global(%d)", g.Get(context.Background()))
|
|
case ValueTypeF32:
|
|
return fmt.Sprintf("global(%f)", api.DecodeF32(g.Get(context.Background())))
|
|
case ValueTypeF64:
|
|
return fmt.Sprintf("global(%f)", api.DecodeF64(g.Get(context.Background())))
|
|
default:
|
|
panic(fmt.Errorf("BUG: unknown value type %X", g.Type()))
|
|
}
|
|
}
|
|
|
|
type globalI32 uint64
|
|
|
|
// compile-time check to ensure globalI32 is a api.Global
|
|
var _ api.Global = globalI32(0)
|
|
|
|
// Type implements the same method as documented on api.Global.
|
|
func (g globalI32) Type() api.ValueType {
|
|
return ValueTypeI32
|
|
}
|
|
|
|
// Get implements the same method as documented on api.Global.
|
|
func (g globalI32) Get(_ context.Context) uint64 {
|
|
return uint64(g)
|
|
}
|
|
|
|
// String implements fmt.Stringer
|
|
func (g globalI32) String() string {
|
|
return fmt.Sprintf("global(%d)", g)
|
|
}
|
|
|
|
type globalI64 uint64
|
|
|
|
// compile-time check to ensure globalI64 is a api.Global
|
|
var _ api.Global = globalI64(0)
|
|
|
|
// Type implements the same method as documented on api.Global.
|
|
func (g globalI64) Type() api.ValueType {
|
|
return ValueTypeI64
|
|
}
|
|
|
|
// Get implements the same method as documented on api.Global.
|
|
func (g globalI64) Get(_ context.Context) uint64 {
|
|
return uint64(g)
|
|
}
|
|
|
|
// String implements fmt.Stringer
|
|
func (g globalI64) String() string {
|
|
return fmt.Sprintf("global(%d)", g)
|
|
}
|
|
|
|
type globalF32 uint64
|
|
|
|
// compile-time check to ensure globalF32 is a api.Global
|
|
var _ api.Global = globalF32(0)
|
|
|
|
// Type implements the same method as documented on api.Global.
|
|
func (g globalF32) Type() api.ValueType {
|
|
return ValueTypeF32
|
|
}
|
|
|
|
// Get implements the same method as documented on api.Global.
|
|
func (g globalF32) Get(_ context.Context) uint64 {
|
|
return uint64(g)
|
|
}
|
|
|
|
// String implements fmt.Stringer
|
|
func (g globalF32) String() string {
|
|
return fmt.Sprintf("global(%f)", api.DecodeF32(g.Get(context.Background())))
|
|
}
|
|
|
|
type globalF64 uint64
|
|
|
|
// compile-time check to ensure globalF64 is a api.Global
|
|
var _ api.Global = globalF64(0)
|
|
|
|
// Type implements the same method as documented on api.Global.
|
|
func (g globalF64) Type() api.ValueType {
|
|
return ValueTypeF64
|
|
}
|
|
|
|
// Get implements the same method as documented on api.Global.
|
|
func (g globalF64) Get(_ context.Context) uint64 {
|
|
return uint64(g)
|
|
}
|
|
|
|
// String implements fmt.Stringer
|
|
func (g globalF64) String() string {
|
|
return fmt.Sprintf("global(%f)", api.DecodeF64(g.Get(context.Background())))
|
|
}
|