common

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(rt *goja.Runtime, v interface{}, ctxPtr *context.Context) map[string]interface{}

Bind the provided value v to the provided runtime

func BindToGlobal

func BindToGlobal(rt *goja.Runtime, data map[string]interface{}) func()

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 GetRuntime

func GetRuntime(ctx context.Context) *goja.Runtime

func MethodName

func MethodName(t 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() 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 RunES6String

func RunES6String(rt *goja.Runtime, src string) (goja.Value, error)

RunES6String Runs an ES6 string in the given runtime. Use this rather than writing ES5 in tests.

func RunString

func RunString(rt *goja.Runtime, src string) (goja.Value, error)

RunString Runs an string in the given runtime. Use this if writing ES5 in tests isn't a problem.

func Throw

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

Throws a JS error; avoids re-wrapping GoErrors.

func WithRuntime

func WithRuntime(ctx context.Context, rt *goja.Runtime) context.Context

Types

type FieldNameMapper

type FieldNameMapper struct{}

FieldNameMapper for goja.Runtime.SetFieldNameMapper()

func (FieldNameMapper) FieldName

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

func (FieldNameMapper) MethodName

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

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

Jump to

Keyboard shortcuts

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