Documentation ¶
Index ¶
- Constants
- func Bind(rt *goja.Runtime, v interface{}, ctxPtr *context.Context) map[string]interface{}deprecated
- func BindToGlobal(rt *goja.Runtime, data map[string]interface{}) func()
- func FieldName(t reflect.Type, f reflect.StructField) string
- func GetReader(data interface{}) (io.Reader, error)
- func GetRuntime(ctx context.Context) *goja.Runtimedeprecated
- func IsInterruptError(err error) bool
- func MethodName(t reflect.Type, m reflect.Method) string
- func NewRandSource() goja.RandSource
- func Throw(rt *goja.Runtime, err error)
- func ToBytes(data interface{}) ([]byte, error)
- func ToString(data interface{}) (string, error)
- func UnwrapGojaInterruptedError(err error) error
- func WithInitEnv(ctx context.Context, initEnv *InitEnvironment) context.Contextdeprecated
- func WithRuntime(ctx context.Context, rt *goja.Runtime) context.Contextdeprecated
- type FieldNameMapper
- type InitContextError
- type InitEnvironment
- type InterruptError
Constants ¶
const AbortTest = "test aborted"
AbortTest is the reason emitted when a test script calls test.abort()
Variables ¶
This section is empty.
Functions ¶
func Bind
deprecated
Bind the provided value v to the provided runtime
Deprecated: JS modules can implement the modules.VU interface for getting the context, goja runtime and the VU State, so the goja.Runtime.Set method can be used for data binding.
func BindToGlobal ¶
BindToGlobal Binds an object's members to the global scope. Returns a function that un-binds them. Note that this will panic if passed something that isn't a struct; please don't do that.
func FieldName ¶
func FieldName(t reflect.Type, f reflect.StructField) string
FieldName Returns the JS name for an exported struct field. The name is snake_cased, with respect for certain common initialisms (URL, ID, HTTP, etc).
func GetReader ¶ added in v0.32.0
GetReader tries to return an io.Reader value from an exported goja value.
func GetRuntime
deprecated
func IsInterruptError ¶ added in v0.36.0
IsInterruptError returns true if err is *InterruptError.
func MethodName ¶
MethodName Returns the JS name for an exported method. The first letter of the method's name is lowercased, otherwise it is unaltered.
func NewRandSource ¶
func NewRandSource() goja.RandSource
NewRandSource is copied from goja's source code: https://github.com/dop251/goja/blob/master/goja/main.go#L44 The returned RandSource is NOT safe for concurrent use: https://golang.org/pkg/math/rand/#NewSource
func UnwrapGojaInterruptedError ¶ added in v0.36.0
UnwrapGojaInterruptedError returns the internal error handled by goja.
func WithInitEnv
deprecated
added in
v0.32.0
func WithInitEnv(ctx context.Context, initEnv *InitEnvironment) context.Context
WithInitEnv attaches the given init environment to the context.
Deprecated: Implement the modules.VU interface for sharing the init environment.
Types ¶
type FieldNameMapper ¶
type FieldNameMapper struct{}
FieldNameMapper for goja.Runtime.SetFieldNameMapper()
func (FieldNameMapper) FieldName ¶
func (FieldNameMapper) FieldName(t reflect.Type, f reflect.StructField) string
FieldName is part of the goja.FieldNameMapper interface https://godoc.org/github.com/dop251/goja#FieldNameMapper
func (FieldNameMapper) MethodName ¶
MethodName is part of the goja.FieldNameMapper interface https://godoc.org/github.com/dop251/goja#FieldNameMapper
type InitContextError ¶ added in v0.23.0
type InitContextError string
InitContextError is an error that happened during the a test init context
func NewInitContextError ¶ added in v0.23.0
func NewInitContextError(msg string) InitContextError
NewInitContextError returns a new InitContextError with the provided message
func (InitContextError) Error ¶ added in v0.23.0
func (i InitContextError) Error() string
func (InitContextError) String ¶ added in v0.23.0
func (i InitContextError) String() string
type InitEnvironment ¶ added in v0.32.0
type InitEnvironment struct { Logger logrus.FieldLogger FileSystems map[string]afero.Fs CWD *url.URL Registry *metrics.Registry }
InitEnvironment contains properties that can be accessed by Go code executed in the k6 init context. It can be accessed by calling common.GetInitEnv().
func GetInitEnv
deprecated
added in
v0.32.0
func GetInitEnv(ctx context.Context) *InitEnvironment
GetInitEnv retrieves the attached init environment struct from the given context.
Deprecated: Use modules.VU for get the init environment.
func (*InitEnvironment) GetAbsFilePath ¶ added in v0.32.0
func (ie *InitEnvironment) GetAbsFilePath(filename string) string
GetAbsFilePath should be used to access the FileSystems, since afero has a bug when opening files with relative paths - it caches them from the FS root, not the current working directory... So, if necessary, this method will transform any relative paths into absolute ones, using the CWD.
TODO: refactor? It was copied from https://github.com/k6io/k6/blob/c51095ad7304bdd1e82cdb33c91abc331533b886/js/initcontext.go#L211-L222
type InterruptError ¶ added in v0.36.0
type InterruptError struct {
Reason string
}
InterruptError is an error that halts engine execution
func (*InterruptError) Error ¶ added in v0.36.0
func (i *InterruptError) Error() string
Error returns the reason of the interruption.
func (*InterruptError) ExitCode ¶ added in v0.36.0
func (i *InterruptError) ExitCode() errext.ExitCode
ExitCode returns the status code used when the k6 process exits.