std

package
v0.0.0-...-674084c Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const NativeEndian = unicode.LittleEndian

NativeEndian is the platform-specific endianness. We need this because certain things in JS, e.g., Uint16Array, use "native endianness".

Variables

This section is empty.

Functions

func Module

func Module(path string) []byte

Module returns the std source corresponding to the 'std' import

func Parse

func Parse(input []byte, format __std.Format) ([]byte, error)

Parse accepts a stringified object, and the format in which it was stringified, and returns a JSON stringified object.

func Unparse

func Unparse(jsonString []byte, format __std.Format) ([]byte, error)

Unparse accepts a JSON stringified object, and a format for reserialising it, and returns the reserialised object.

Types

type Directory

type Directory struct {
	Name  string     `json:"name"`
	Path  string     `json:"path"`
	Files []FileInfo `json:"files"`
}

Directory is the result from an std.dir RPC

func MakeDirectoryListing

func MakeDirectoryListing(r Sandbox, p, module string) (Directory, error)

MakeDirectoryListing returns a response to a Dir request, encoded ready to send to the V8 worker.

type FileInfo

type FileInfo struct {
	Name  string `json:"name"`
	Path  string `json:"path"`
	IsDir bool   `json:"isdir"`
}

FileInfo is the result from a std.fileinfo RPC (and used to represent each file, within Directory)

func MakeFileInfo

func MakeFileInfo(r Sandbox, path, module string) (FileInfo, error)

MakeFileInfo returns a response to a FileInfo request, encoded ready to send to the V8 worker.

type ModuleAccess

type ModuleAccess struct {
	// Does this module allow paths outside the sandbox?
	AllowPathsOutsideSandbox bool
	// The location within a virtual filesystem; usually, but not
	// necessarily, the root of the virtual filesystem.
	Loc vfs.Location
	// Writes don't go through a virtual filesystem. This flag means
	// "allow writes to the host filesystem with this module".
	AllowWriteToHost bool
}

ModuleAccess represents access to a module's resources

type ModuleAccesser

type ModuleAccesser interface {
	GetModuleAccess(string) (ModuleAccess, bool)
}

ModuleAccesser is an interface for getting the module back from a token

type ModuleResources

type ModuleResources struct {
	// contains filtered or unexported fields
}

ModuleResources keeps track of the base paths for modules, as well as generating the magic modules when they are imported.

func NewModuleResources

func NewModuleResources() *ModuleResources

NewModuleResources initialises a new ModuleResources

func (*ModuleResources) GetModuleAccess

func (r *ModuleResources) GetModuleAccess(token string) (ModuleAccess, bool)

GetModuleAccess looks up a module given a token.

func (*ModuleResources) MakeResourceModule

func (r *ModuleResources) MakeResourceModule(mod ModuleAccess) ([]byte, string)

MakeResourceModule generates resource module code (and path) given the importing module's base path.

type Options

type Options struct {
	// Verbose indicates if some operations, such as write, should print out what
	// they are doing.
	Verbose bool
	// Parameters is a structured set of input parameters.
	Parameters Params
	// Sandbox mediates reads and writes to the filesystem
	Sandbox Sandbox
	// DryRun instructs standard library functions to not complete operations that
	// would mutate something (eg. std.write()).
	DryRun bool
	// ExtMethods is where extension RPC methods are registered (the
	// standard ones are here, and take precedence)
	ExtMethods map[string]RPCFunc
}

Options are global configuration options to tweak the behavior of the standard library.

type Params

type Params map[string]interface{}

Params is a paramater store akin to a JSON object.

func NewParams

func NewParams() Params

NewParams creates an empty set of parameters.

func NewParamsFromFile

func NewParamsFromFile(path string) (Params, error)

NewParamsFromFile creates Params from a JSON or YAML file.

func NewParamsFromJSON

func NewParamsFromJSON(r io.Reader) (Params, error)

NewParamsFromJSON creates Params from a JSON object.

func NewParamsFromYAML

func NewParamsFromYAML(r io.Reader) (Params, error)

NewParamsFromYAML creates Params from a YAML object.

func (Params) Get

func (p Params) Get(path string) (interface{}, error)

Get retrieves a parameter.

func (Params) GetBool

func (p Params) GetBool(path string) (bool, error)

GetBool retrieves a boolean parameter.

func (Params) GetNumber

func (p Params) GetNumber(path string) (float64, error)

GetNumber retrieves a number parameter.

func (Params) GetObject

func (p Params) GetObject(path string) (Params, error)

GetObject retrieves a object parameter.

func (Params) GetString

func (p Params) GetString(path string) (string, error)

GetString retrieves a string parameter.

func (Params) Merge

func (p Params) Merge(a Params)

Merge merges two parameter stores.

func (Params) Set

func (p Params) Set(path string, v interface{})

Set sets a parameter.

func (Params) SetBool

func (p Params) SetBool(path string, b bool)

SetBool sets a boolean parameter.

func (Params) SetNumber

func (p Params) SetNumber(path string, f float64)

SetNumber sets a number parameter.

func (Params) SetObject

func (p Params) SetObject(path string, o Params)

SetObject sets an object parameter.

func (Params) SetString

func (p Params) SetString(path string, s string)

SetString sets a string parameter.

func (Params) String

func (p Params) String() string

type RPCFunc

type RPCFunc func([]interface{}) (interface{}, error)

RPCFunc is a function that can be registered for dispatch. The arguments each will either be []byte or JSON values; any result returned will be serialised to JSON.

type Sandbox

type Sandbox struct {
	// The location in a virtual filesystem that is the top-most that
	// can be read from
	Base vfs.Location
	// The top-most directory that can be written to
	WriteRoot string
	// Look-up for resources (i.e., for module-relative reads)
	Modules ModuleAccesser
	// For recording each read or write
	Recorder *record.Recorder
}

Sandbox mediates access to the filesystem by resolving relative paths to the host filesystem and resources (module-relative paths). Reads outside the base are forbidden and will return an error.

func (Sandbox) Read

func (r Sandbox) Read(relPath string, format __std.Format, encoding __std.Encoding, module string) ([]byte, error)

Read returns the contents of the file at `path`, relative to the root path or if given, the module directory identified by `module`.

func (Sandbox) Write

func (s Sandbox) Write(value []byte, path, module string, opts writeOpts) error

type Std

type Std struct {
	// contains filtered or unexported fields
}

Std represents the standard library.

func NewStd

func NewStd(options Options) *Std

NewStd creates a new instance of the standard library.

func (*Std) Execute

func (std *Std) Execute(msg []byte, res sender) []byte

Execute parses a message from v8 and execute the corresponding function.

Jump to

Keyboard shortcuts

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