Documentation ¶
Overview ¶
Package common contains helpers for interacting with the JavaScript runtime.
Index ¶
- func ApplyCustomUserMetadata(tagsAndMeta *metrics.TagsAndMeta, key string, val goja.Value) error
- func ApplyCustomUserTag(tagsAndMeta *metrics.TagsAndMeta, key string, val goja.Value) error
- func ApplyCustomUserTags(rt *goja.Runtime, tagsAndMeta *metrics.TagsAndMeta, keyValues goja.Value) error
- func FieldName(t reflect.Type, f reflect.StructField) string
- func FreezeObject(rt *goja.Runtime, obj goja.Value) error
- func GetReader(data interface{}) (io.Reader, error)
- func IsAsyncFunction(rt *goja.Runtime, val goja.Value) bool
- func IsNullish(v goja.Value) bool
- func MethodName(t reflect.Type, m reflect.Method) string
- func NewRandSource() goja.RandSource
- func RunWithPanicCatching(logger logrus.FieldLogger, rt *goja.Runtime, fn func() error) (err error)
- func Throw(rt *goja.Runtime, err error)
- func ToBytes(data interface{}) ([]byte, error)
- func ToString(data interface{}) (string, error)
- func UnwrapGojaInterruptedError(err error) error
- type FieldNameMapper
- type InitContextError
- type InitEnvironment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyCustomUserMetadata ¶
ApplyCustomUserMetadata modifies the given metrics.TagsAndMeta object with the given custom metadata and their value.
func ApplyCustomUserTag ¶
ApplyCustomUserTag modifies the given metrics.TagsAndMeta object with the given custom tag and theirs value.
func ApplyCustomUserTags ¶
func ApplyCustomUserTags(rt *goja.Runtime, tagsAndMeta *metrics.TagsAndMeta, keyValues goja.Value) error
ApplyCustomUserTags modifies the given metrics.TagsAndMeta object with the user specified custom tags and metadata. It expects to receive the `keyValues` object in the `{key1: value1, key2: value2, ...}` format.
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 FreezeObject ¶
FreezeObject replicates the JavaScript Object.freeze function.
func IsAsyncFunction ¶
IsAsyncFunction checks if the provided value is an AsyncFunction
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 RunWithPanicCatching ¶
RunWithPanicCatching catches panic and converts into an InterruptError error that should abort a script
func UnwrapGojaInterruptedError ¶
UnwrapGojaInterruptedError returns the internal error handled by goja.
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 ¶
type InitContextError string
InitContextError is an error that happened during the a test init context
func NewInitContextError ¶
func NewInitContextError(msg string) InitContextError
NewInitContextError returns a new InitContextError with the provided message
func (InitContextError) Error ¶
func (i InitContextError) Error() string
func (InitContextError) String ¶
func (i InitContextError) String() string
type InitEnvironment ¶
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 (*InitEnvironment) GetAbsFilePath ¶
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