jsre

package
v1.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package jsre provides an execution environment for JavaScript.

JSRE is a generic JS runtime environment embedding the otto Javascript interpreter. <https://github.com/robertkrimen/otto>

It provides some helper functions to
- load code from files
- run code snippets
- require libraries
- bind native go objects

Because of JSRE, an user can utilize JavaScript in the console as needed. JSRE also provides two JavaScript libraries, bignumber.js and web3.js, for users to easily access Klaytn.

Source Files

Each file provides following features

  • completion.go : Provides functions for keyword completion
  • jsre.go : Wraps otto JavaScript interpreter and provides an event loop
  • pretty.go : Prints results to the standard output in more readable way

Index

Constants

This section is empty.

Variables

View Source
var (
	BigNumber_JS = deps.MustAsset("bignumber.js")
	Web3_JS      = deps.MustAsset("web3.js")
)
View Source
var (
	FunctionColor = color.New(color.FgMagenta).SprintfFunc()
	SpecialColor  = color.New(color.Bold).SprintfFunc()
	NumberColor   = color.New(color.FgRed).SprintfFunc()
	StringColor   = color.New(color.FgGreen).SprintfFunc()
	ErrorColor    = color.New(color.FgHiRed).SprintfFunc()
)

Functions

This section is empty.

Types

type JSRE

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

JSRE is a generic JS runtime environment embedding the otto JS interpreter. It provides some helper functions to - load code from files - run code snippets - require libraries - bind native go objects

func New

func New(assetPath string, output io.Writer) *JSRE

runtime must be stopped with Stop() after use and cannot be used after stopping

func (*JSRE) Bind

func (re *JSRE) Bind(name string, v interface{}) error

Bind assigns value v to a variable in the JS environment This method is deprecated, use Set.

func (*JSRE) Compile

func (re *JSRE) Compile(filename string, src interface{}) (err error)

Compile compiles and then runs a piece of JS code.

func (*JSRE) CompleteKeywords

func (jsre *JSRE) CompleteKeywords(line string) []string

CompleteKeywords returns potential continuations for the given line. Since line is evaluated, callers need to make sure that evaluating line does not have side effects.

func (*JSRE) Do

func (re *JSRE) Do(fn func(*otto.Otto))

Do executes the given function on the JS event loop.

func (*JSRE) Evaluate

func (re *JSRE) Evaluate(code string, w io.Writer) error

Evaluate executes code and pretty prints the result to the specified output stream.

func (*JSRE) Exec

func (re *JSRE) Exec(file string) error

Exec(file) loads and runs the contents of a file if a relative path is given, the jsre's assetPath is used

func (*JSRE) Get

func (re *JSRE) Get(ns string) (v otto.Value, err error)

Get returns the value of a variable in the JS environment.

func (*JSRE) Run

func (re *JSRE) Run(code string) (v otto.Value, err error)

Run runs a piece of JS code.

func (*JSRE) Set

func (re *JSRE) Set(ns string, v interface{}) (err error)

Set assigns value v to a variable in the JS environment.

func (*JSRE) Stop

func (re *JSRE) Stop(waitForCallbacks bool)

stops the event loop before exit, optionally waits for all timers to expire

Directories

Path Synopsis
Package deps contains the console's dependencies of Javascript libraries to be embedded in Go source code.
Package deps contains the console's dependencies of Javascript libraries to be embedded in Go source code.

Jump to

Keyboard shortcuts

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