common

package
v0.54.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2024 License: AGPL-3.0 Imports: 17 Imported by: 191

Documentation

Overview

Package common contains helpers for interacting with the JavaScript runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyCustomUserMetadata added in v0.45.0

func ApplyCustomUserMetadata(tagsAndMeta *metrics.TagsAndMeta, key string, val sobek.Value) error

ApplyCustomUserMetadata modifies the given metrics.TagsAndMeta object with the given custom metadata and their value.

func ApplyCustomUserTag added in v0.41.0

func ApplyCustomUserTag(tagsAndMeta *metrics.TagsAndMeta, key string, val sobek.Value) error

ApplyCustomUserTag modifies the given metrics.TagsAndMeta object with the given custom tag and theirs value.

func ApplyCustomUserTags added in v0.41.0

func ApplyCustomUserTags(rt *sobek.Runtime, tagsAndMeta *metrics.TagsAndMeta, keyValues sobek.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(_ 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 added in v0.38.0

func FreezeObject(rt *sobek.Runtime, obj sobek.Value) error

FreezeObject replicates the JavaScript Object.freeze function.

func GetReader added in v0.32.0

func GetReader(data interface{}) (io.Reader, error)

GetReader tries to return an io.Reader value from an exported Sobek value.

func IsAsyncFunction added in v0.45.0

func IsAsyncFunction(rt *sobek.Runtime, val sobek.Value) bool

IsAsyncFunction checks if the provided value is an AsyncFunction

func IsNullish added in v0.44.0

func IsNullish(v sobek.Value) bool

IsNullish checks if the given value is nullish, i.e. nil, undefined or null.

func MethodName

func MethodName(_ reflect.Type, m reflect.Method) string

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() sobek.RandSource

NewRandSource is copied from Sobek's source code: https://github.com/grafana/sobek/blob/master/sobek/main.go#L44 The returned RandSource is NOT safe for concurrent use: https://golang.org/pkg/math/rand/#NewSource

func Throw

func Throw(rt *sobek.Runtime, err error)

Throw a JS error; avoids re-wrapping GoErrors.

func ToBytes added in v0.32.0

func ToBytes(data interface{}) ([]byte, error)

ToBytes tries to return a byte slice from compatible types.

func ToString added in v0.32.0

func ToString(data interface{}) (string, error)

ToString tries to return a string from compatible types.

func UnwrapSobekInterruptedError added in v0.53.0

func UnwrapSobekInterruptedError(err error) error

UnwrapSobekInterruptedError returns the internal error handled by Sobek.

Types

type Events added in v0.46.0

type Events struct {
	Global, Local event.Subscriber
}

Events are the event subscriber interfaces for the global event system, and the local (per-VU) event system.

type FieldNameMapper

type FieldNameMapper struct{}

FieldNameMapper for sobek.Runtime.SetFieldNameMapper()

func (FieldNameMapper) FieldName

FieldName is part of the sobek.FieldNameMapper interface https://godoc.org/github.com/grafana/sobek#FieldNameMapper

func (FieldNameMapper) MethodName

func (FieldNameMapper) MethodName(t reflect.Type, m reflect.Method) string

MethodName is part of the sobek.FieldNameMapper interface https://godoc.org/github.com/grafana/sobek#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 {
	*lib.TestPreInitState
	FileSystems map[string]fsext.Fs
	CWD         *url.URL
}

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 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL