A JavaScript interpreter in Go (golang)

Related tags

Compiler otto
Overview

otto

--

import "github.com/robertkrimen/otto"

Package otto is a JavaScript parser and interpreter written natively in Go.

http://godoc.org/github.com/robertkrimen/otto

import (
   "github.com/robertkrimen/otto"
)

Run something in the VM

vm := otto.New()
vm.Run(`
    abc = 2 + 2;
    console.log("The value of abc is " + abc); // 4
`)

Get a value out of the VM

if value, err := vm.Get("abc"); err == nil {
    if value_int, err := value.ToInteger(); err == nil {
	fmt.Printf("", value_int, err)
    }
}

Set a number

vm.Set("def", 11)
vm.Run(`
    console.log("The value of def is " + def);
    // The value of def is 11
`)

Set a string

vm.Set("xyzzy", "Nothing happens.")
vm.Run(`
    console.log(xyzzy.length); // 16
`)

Get the value of an expression

value, _ = vm.Run("xyzzy.length")
{
    // value is an int64 with a value of 16
    value, _ := value.ToInteger()
}

An error happens

value, err = vm.Run("abcdefghijlmnopqrstuvwxyz.length")
if err != nil {
    // err = ReferenceError: abcdefghijlmnopqrstuvwxyz is not defined
    // If there is an error, then value.IsUndefined() is true
    ...
}

Set a Go function

vm.Set("sayHello", func(call otto.FunctionCall) otto.Value {
    fmt.Printf("Hello, %s.\n", call.Argument(0).String())
    return otto.Value{}
})

Set a Go function that returns something useful

vm.Set("twoPlus", func(call otto.FunctionCall) otto.Value {
    right, _ := call.Argument(0).ToInteger()
    result, _ := vm.ToValue(2 + right)
    return result
})

Use the functions in JavaScript

result, _ = vm.Run(`
    sayHello("Xyzzy");      // Hello, Xyzzy.
    sayHello();             // Hello, undefined

    result = twoPlus(2.0); // 4
`)

Parser

A separate parser is available in the parser package if you're just interested in building an AST.

http://godoc.org/github.com/robertkrimen/otto/parser

Parse and return an AST

filename := "" // A filename is optional
src := `
    // Sample xyzzy example
    (function(){
        if (3.14159 > 0) {
            console.log("Hello, World.");
            return;
        }

        var xyzzy = NaN;
        console.log("Nothing happens.");
        return xyzzy;
    })();
`

// Parse some JavaScript, yielding a *ast.Program and/or an ErrorList
program, err := parser.ParseFile(nil, filename, src, 0)

otto

You can run (Go) JavaScript from the commandline with: http://github.com/robertkrimen/otto/tree/master/otto

$ go get -v github.com/robertkrimen/otto/otto

Run JavaScript by entering some source on stdin or by giving otto a filename:

$ otto example.js

underscore

Optionally include the JavaScript utility-belt library, underscore, with this import:

import (
    "github.com/robertkrimen/otto"
    _ "github.com/robertkrimen/otto/underscore"
)

// Now every otto runtime will come loaded with underscore

For more information: http://github.com/robertkrimen/otto/tree/master/underscore

Caveat Emptor

The following are some limitations with otto:

* "use strict" will parse, but does nothing.
* The regular expression engine (re2/regexp) is not fully compatible with the ECMA5 specification.
* Otto targets ES5. ES6 features (eg: Typed Arrays) are not supported.

Regular Expression Incompatibility

Go translates JavaScript-style regular expressions into something that is "regexp" compatible via parser.TransformRegExp. Unfortunately, RegExp requires backtracking for some patterns, and backtracking is not supported by the standard Go engine: https://code.google.com/p/re2/wiki/Syntax

Therefore, the following syntax is incompatible:

(?=)  // Lookahead (positive), currently a parsing error
(?!)  // Lookahead (backhead), currently a parsing error
\1    // Backreference (\1, \2, \3, ...), currently a parsing error

A brief discussion of these limitations: "Regexp (?!re)" https://groups.google.com/forum/?fromgroups=#%21topic/golang-nuts/7qgSDWPIh_E

More information about re2: https://code.google.com/p/re2/

In addition to the above, re2 (Go) has a different definition for \s: [\t\n\f\r ]. The JavaScript definition, on the other hand, also includes \v, Unicode "Separator, Space", etc.

Halting Problem

If you want to stop long running executions (like third-party code), you can use the interrupt channel to do this:

package main

import (
    "errors"
    "fmt"
    "os"
    "time"

    "github.com/robertkrimen/otto"
)

var halt = errors.New("Stahp")

func main() {
    runUnsafe(`var abc = [];`)
    runUnsafe(`
    while (true) {
        // Loop forever
    }`)
}

func runUnsafe(unsafe string) {
    start := time.Now()
    defer func() {
        duration := time.Since(start)
        if caught := recover(); caught != nil {
            if caught == halt {
                fmt.Fprintf(os.Stderr, "Some code took to long! Stopping after: %v\n", duration)
                return
            }
            panic(caught) // Something else happened, repanic!
        }
        fmt.Fprintf(os.Stderr, "Ran code successfully: %v\n", duration)
    }()

    vm := otto.New()
    vm.Interrupt = make(chan func(), 1) // The buffer prevents blocking

    go func() {
        time.Sleep(2 * time.Second) // Stop after two seconds
        vm.Interrupt <- func() {
            panic(halt)
        }
    }()

    vm.Run(unsafe) // Here be dragons (risky code)
}

Where is setTimeout/setInterval?

These timing functions are not actually part of the ECMA-262 specification. Typically, they belong to the window object (in the browser). It would not be difficult to provide something like these via Go, but you probably want to wrap otto in an event loop in that case.

For an example of how this could be done in Go with otto, see natto:

http://github.com/robertkrimen/natto

Here is some more discussion of the issue:

Usage

var ErrVersion = errors.New("version mismatch")

type Error

type Error struct {
}

An Error represents a runtime error, e.g. a TypeError, a ReferenceError, etc.

func (Error) Error

func (err Error) Error() string

Error returns a description of the error

TypeError: 'def' is not a function

func (Error) String

func (err Error) String() string

String returns a description of the error and a trace of where the error occurred.

TypeError: 'def' is not a function
    at xyz (<anonymous>:3:9)
    at <anonymous>:7:1/

type FunctionCall

type FunctionCall struct {
	This         Value
	ArgumentList []Value
	Otto         *Otto
}

FunctionCall is an encapsulation of a JavaScript function call.

func (FunctionCall) Argument

func (self FunctionCall) Argument(index int) Value

Argument will return the value of the argument at the given index.

If no such argument exists, undefined is returned.

type Object

type Object struct {
}

Object is the representation of a JavaScript object.

func (Object) Call

func (self Object) Call(name string, argumentList ...interface{}) (Value, error)

Call a method on the object.

It is essentially equivalent to:

var method, _ := object.Get(name)
method.Call(object, argumentList...)

An undefined value and an error will result if:

1. There is an error during conversion of the argument list
2. The property is not actually a function
3. An (uncaught) exception is thrown

func (Object) Class

func (self Object) Class() string

Class will return the class string of the object.

The return value will (generally) be one of:

Object
Function
Array
String
Number
Boolean
Date
RegExp

func (Object) Get

func (self Object) Get(name string) (Value, error)

Get the value of the property with the given name.

func (Object) Keys

func (self Object) Keys() []string

Get the keys for the object

Equivalent to calling Object.keys on the object

func (Object) Set

func (self Object) Set(name string, value interface{}) error

Set the property of the given name to the given value.

An error will result if the setting the property triggers an exception (i.e. read-only), or there is an error during conversion of the given value.

func (Object) Value

func (self Object) Value() Value

Value will return self as a value.

type Otto

type Otto struct {
	// Interrupt is a channel for interrupting the runtime. You can use this to halt a long running execution, for example.
	// See "Halting Problem" for more information.
	Interrupt chan func()
}

Otto is the representation of the JavaScript runtime. Each instance of Otto has a self-contained namespace.

func New

func New() *Otto

New will allocate a new JavaScript runtime

func Run

func Run(src interface{}) (*Otto, Value, error)

Run will allocate a new JavaScript runtime, run the given source on the allocated runtime, and return the runtime, resulting value, and error (if any).

src may be a string, a byte slice, a bytes.Buffer, or an io.Reader, but it MUST always be in UTF-8.

src may also be a Script.

src may also be a Program, but if the AST has been modified, then runtime behavior is undefined.

func (Otto) Call

func (self Otto) Call(source string, this interface{}, argumentList ...interface{}) (Value, error)

Call the given JavaScript with a given this and arguments.

If this is nil, then some special handling takes place to determine the proper this value, falling back to a "standard" invocation if necessary (where this is undefined).

If source begins with "new " (A lowercase new followed by a space), then Call will invoke the function constructor rather than performing a function call. In this case, the this argument has no effect.

// value is a String object
value, _ := vm.Call("Object", nil, "Hello, World.")

// Likewise...
value, _ := vm.Call("new Object", nil, "Hello, World.")

// This will perform a concat on the given array and return the result
// value is [ 1, 2, 3, undefined, 4, 5, 6, 7, "abc" ]
value, _ := vm.Call(`[ 1, 2, 3, undefined, 4 ].concat`, nil, 5, 6, 7, "abc")

func (*Otto) Compile

func (self *Otto) Compile(filename string, src interface{}) (*Script, error)

Compile will parse the given source and return a Script value or nil and an error if there was a problem during compilation.

script, err := vm.Compile("", `var abc; if (!abc) abc = 0; abc += 2; abc;`)
vm.Run(script)

func (*Otto) Copy

func (in *Otto) Copy() *Otto

Copy will create a copy/clone of the runtime.

Copy is useful for saving some time when creating many similar runtimes.

This method works by walking the original runtime and cloning each object, scope, stash, etc. into a new runtime.

Be on the lookout for memory leaks or inadvertent sharing of resources.

func (Otto) Get

func (self Otto) Get(name string) (Value, error)

Get the value of the top-level binding of the given name.

If there is an error (like the binding does not exist), then the value will be undefined.

func (Otto) Object

func (self Otto) Object(source string) (*Object, error)

Object will run the given source and return the result as an object.

For example, accessing an existing object:

object, _ := vm.Object(`Number`)

Or, creating a new object:

object, _ := vm.Object(`({ xyzzy: "Nothing happens." })`)

Or, creating and assigning an object:

object, _ := vm.Object(`xyzzy = {}`)
object.Set("volume", 11)

If there is an error (like the source does not result in an object), then nil and an error is returned.

func (Otto) Run

func (self Otto) Run(src interface{}) (Value, error)

Run will run the given source (parsing it first if necessary), returning the resulting value and error (if any)

src may be a string, a byte slice, a bytes.Buffer, or an io.Reader, but it MUST always be in UTF-8.

If the runtime is unable to parse source, then this function will return undefined and the parse error (nothing will be evaluated in this case).

src may also be a Script.

src may also be a Program, but if the AST has been modified, then runtime behavior is undefined.

func (Otto) Set

func (self Otto) Set(name string, value interface{}) error

Set the top-level binding of the given name to the given value.

Set will automatically apply ToValue to the given value in order to convert it to a JavaScript value (type Value).

If there is an error (like the binding is read-only, or the ToValue conversion fails), then an error is returned.

If the top-level binding does not exist, it will be created.

func (Otto) ToValue

func (self Otto) ToValue(value interface{}) (Value, error)

ToValue will convert an interface{} value to a value digestible by otto/JavaScript.

type Script

type Script struct {
}

Script is a handle for some (reusable) JavaScript. Passing a Script value to a run method will evaluate the JavaScript.

func (*Script) String

func (self *Script) String() string

type Value

type Value struct {
}

Value is the representation of a JavaScript value.

func FalseValue

func FalseValue() Value

FalseValue will return a value representing false.

It is equivalent to:

ToValue(false)

func NaNValue

func NaNValue() Value

NaNValue will return a value representing NaN.

It is equivalent to:

ToValue(math.NaN())

func NullValue

func NullValue() Value

NullValue will return a Value representing null.

func ToValue

func ToValue(value interface{}) (Value, error)

ToValue will convert an interface{} value to a value digestible by otto/JavaScript

This function will not work for advanced types (struct, map, slice/array, etc.) and you should use Otto.ToValue instead.

func TrueValue

func TrueValue() Value

TrueValue will return a value representing true.

It is equivalent to:

ToValue(true)

func UndefinedValue

func UndefinedValue() Value

UndefinedValue will return a Value representing undefined.

func (Value) Call

func (value Value) Call(this Value, argumentList ...interface{}) (Value, error)

Call the value as a function with the given this value and argument list and return the result of invocation. It is essentially equivalent to:

value.apply(thisValue, argumentList)

An undefined value and an error will result if:

1. There is an error during conversion of the argument list
2. The value is not actually a function
3. An (uncaught) exception is thrown

func (Value) Class

func (value Value) Class() string

Class will return the class string of the value or the empty string if value is not an object.

The return value will (generally) be one of:

Object
Function
Array
String
Number
Boolean
Date
RegExp

func (Value) Export

func (self Value) Export() (interface{}, error)

Export will attempt to convert the value to a Go representation and return it via an interface{} kind.

Export returns an error, but it will always be nil. It is present for backwards compatibility.

If a reasonable conversion is not possible, then the original value is returned.

undefined   -> nil (FIXME?: Should be Value{})
null        -> nil
boolean     -> bool
number      -> A number type (int, float32, uint64, ...)
string      -> string
Array       -> []interface{}
Object      -> map[string]interface{}

func (Value) IsBoolean

func (value Value) IsBoolean() bool

IsBoolean will return true if value is a boolean (primitive).

func (Value) IsDefined

func (value Value) IsDefined() bool

IsDefined will return false if the value is undefined, and true otherwise.

func (Value) IsFunction

func (value Value) IsFunction() bool

IsFunction will return true if value is a function.

func (Value) IsNaN

func (value Value) IsNaN() bool

IsNaN will return true if value is NaN (or would convert to NaN).

func (Value) IsNull

func (value Value) IsNull() bool

IsNull will return true if the value is null, and false otherwise.

func (Value) IsNumber

func (value Value) IsNumber() bool

IsNumber will return true if value is a number (primitive).

func (Value) IsObject

func (value Value) IsObject() bool

IsObject will return true if value is an object.

func (Value) IsPrimitive

func (value Value) IsPrimitive() bool

IsPrimitive will return true if value is a primitive (any kind of primitive).

func (Value) IsString

func (value Value) IsString() bool

IsString will return true if value is a string (primitive).

func (Value) IsUndefined

func (value Value) IsUndefined() bool

IsUndefined will return true if the value is undefined, and false otherwise.

func (Value) Object

func (value Value) Object() *Object

Object will return the object of the value, or nil if value is not an object.

This method will not do any implicit conversion. For example, calling this method on a string primitive value will not return a String object.

func (Value) String

func (value Value) String() string

String will return the value as a string.

This method will make return the empty string if there is an error.

func (Value) ToBoolean

func (value Value) ToBoolean() (bool, error)

ToBoolean will convert the value to a boolean (bool).

ToValue(0).ToBoolean() => false
ToValue("").ToBoolean() => false
ToValue(true).ToBoolean() => true
ToValue(1).ToBoolean() => true
ToValue("Nothing happens").ToBoolean() => true

If there is an error during the conversion process (like an uncaught exception), then the result will be false and an error.

func (Value) ToFloat

func (value Value) ToFloat() (float64, error)

ToFloat will convert the value to a number (float64).

ToValue(0).ToFloat() => 0.
ToValue(1.1).ToFloat() => 1.1
ToValue("11").ToFloat() => 11.

If there is an error during the conversion process (like an uncaught exception), then the result will be 0 and an error.

func (Value) ToInteger

func (value Value) ToInteger() (int64, error)

ToInteger will convert the value to a number (int64).

ToValue(0).ToInteger() => 0
ToValue(1.1).ToInteger() => 1
ToValue("11").ToInteger() => 11

If there is an error during the conversion process (like an uncaught exception), then the result will be 0 and an error.

func (Value) ToString

func (value Value) ToString() (string, error)

ToString will convert the value to a string (string).

ToValue(0).ToString() => "0"
ToValue(false).ToString() => "false"
ToValue(1.1).ToString() => "1.1"
ToValue("11").ToString() => "11"
ToValue('Nothing happens.').ToString() => "Nothing happens."

If there is an error during the conversion process (like an uncaught exception), then the result will be the empty string ("") and an error.

-- godocdown http://github.com/robertkrimen/godocdown

Comments
  • Is there a way to install otto via go get? Error when running go get.

    Is there a way to install otto via go get? Error when running go get.

    I am new to golang and therefore to otto. I am having problems trying to install this package to use in my project. Is there a way to install it via go get or do I have to clone the project into my src folder?

    Sorry if this is a dumb question, but I am really struggling with this.

    opened by ericreis 35
  • Support for Interrupt VM without panic

    Support for Interrupt VM without panic

    Hi,

    In my project: https://github.com/prsolucoes/goci

    I have added support to stop plugin execution. Everything is working fine on CLI and JS plugin.

    The problem is when i stop the VM using Interrupt channel, i dont have another alternative of PANIC and it kill the host application and we need restart the server again and others execution is killed too.

    Have any alternative to this behaviour?

    Line: https://github.com/prsolucoes/goci/blob/master/models/domain/plugin_js.go#L284

    opened by paulocoutinhox 20
  • Project dead?

    Project dead?

    The author (Robert Krimen) hasn't updated the project since September (and, in fact, no real activity since July). I wrote him an email asking for info on otto's status, but didn't get any answer at all.

    opened by lstep 20
  • Improving call arguments conversion

    Improving call arguments conversion

    Passing nil to a 'non-native' go function results in "Call using zero Value argument". Also, passing custom types (for example passing uint32 to a function that expects type a uint32) results in a panic. This addresses both issues. Please consider merging.

    opened by dop251 14
  • unable to interpret react.js

    unable to interpret react.js

    I am a huge fan of react.js at the moment. Unfortunately, rendering the page on the client side has some disadvantages and clients that do not support JS (e.g. crawlers) will see nothing. I thought otto and react.js new renderComponentToString feature might be a good fit for rendering the page on the server side.

    Unfortunately, otto isn't able to interpret the react.js source at the moment. I'm creating this issue because I think it isn't related to the different regexp syntax.

    Example:

    package main
    
    import (
        "github.com/robertkrimen/otto"
        "io/ioutil"
        "log"
        "net/http"
    )
    
    func main() {
        resp, err := http.Get("http://fb.me/react-0.10.0.js")
        if err != nil {
            log.Fatalln(err)
        }
        body, err := ioutil.ReadAll(resp.Body)
        if err != nil {
            log.Fatalln(err)
        }
        vm := otto.New()
        _, err = vm.Run(string(body))
        if err != nil {
            log.Fatalln(err)
        }
    }
    

    Error:

    Cannot access member 'React' of undefined
    
    opened by tux21b 12
  • Switch over to a regular expression package that claims to be Perl 5 compatible

    Switch over to a regular expression package that claims to be Perl 5 compatible

    Regular expressions in ECMAScript 5 are modelled after the regular expression facility in the Perl 5 programming language (ECMA 5 spec).

    This pull requests switches over from the regexp package to P5R, which is compatible with Perl 5 regular expressions.

    More testing is needed in order to confirm for sure that Perl 5 regular expressions will be supported correctly for all cases, but it's a start.

    For some functions that are supported by regexp but not yet by P5R, the regular expression struct is converted to a regexp struct and the same method call as was used before is being used. This might have a small performance hit (since the regular expression string is recompiled), but from my initial testing it should not have too large of an impact.

    In the future, it will probably be better to use the functions from P5R instead, which takes different parameters (and often can return an error where regexp returns none). I have added comments in the code where I think this might be a good idea.

    Hopefully this pull request can bring Otto one step closer to becoming ECMAScript 5 compatible, which would be an advantage.

    opened by xyproto 11
  • GoCI - Trying to use otto js parser in my project

    GoCI - Trying to use otto js parser in my project

    Hi,

    I have a project called GoCI: https://github.com/prsolucoes/goci

    This project use Anko script parser in Go to make the CI builds. Users can create a script.ank file to execute every process need to build a task.

    My questions is about how i can do the same things using otto js parser. What i need understand in otto js parser:

    1 - Export Go functions to javascript, like make http request, exec command line, get environment vars ... everything here: https://github.com/prsolucoes/goci

    2 - I need export my own package called "goci". This custom package has some goci system functions, some variables, etc. There is a way to export it as object? Like "var job = goci.Job"!

    3 - If script crash/error, i can get this status without crash all the "goci" process ?

    Thanks for the help!

    opened by paulocoutinhox 11
  • Seed math/rand with UnixNano for truly random numbers.

    Seed math/rand with UnixNano for truly random numbers.

    While creating a random level generator for my game engine I noticed that each time I generated a level (this happens on startup) it was the same. This is a fix that removes this bug/issue. Perhaps this is desired behaviour, but I figure that this way otto will behave more like other javascript implementations, all of which have unpredictable random numbers.

    Good Day!

    opened by paked 11
  • Invalid Idx0

    Invalid Idx0

    Using this code:

    package main
    
    import (
       "fmt"
       "github.com/robertkrimen/otto/ast"
       "github.com/robertkrimen/otto/parser"
    )
    
    type visit struct{}
    
    func (visit) Exit(ast.Node) {}
    
    func (v visit) Enter(n ast.Node) ast.Visitor {
       fmt.Printf("%v %#v\n", n.Idx0(), n)
       return v
    }
    
    func main() {
       pro, err := parser.ParseFile(nil, "", "var x = [10,11];", 0)
       if err != nil {
          panic(err)
       }
       var vis visit
       ast.Walk(vis, pro)
    }
    

    I get this result:

    1 &ast.Program{Body:[]ast.Statement{(*ast.VariableStatement)(0xc00004c500)}, DeclarationList:[]ast.Declaration{(*ast.VariableDeclaration)(0xc00004c4e0)}, File:(*file.File)(0xc000076660), Comments:ast.CommentMap{}}
    1 &ast.VariableStatement{Var:1, List:[]ast.Expression{(*ast.VariableExpression)(0xc0000766c0)}}
    5 &ast.VariableExpression{Name:"x", Idx:5, Initializer:(*ast.ArrayLiteral)(0xc000076750)}
    9 &ast.ArrayLiteral{LeftBracket:9, RightBracket:15, Value:[]ast.Expression{(*ast.NumberLiteral)(0xc0000766f0), (*ast.NumberLiteral)(0xc000076720)}}
    10 &ast.NumberLiteral{Idx:10, Literal:"10", Value:10}
    13 &ast.NumberLiteral{Idx:13, Literal:"11", Value:11}
    

    The problem is, the index for the ArrayLiteral 9 is not valid. It should be 8.

    opened by 89z 10
  • Simple limitation of evaluation speed.

    Simple limitation of evaluation speed.

    A Limits struct in the Otto struct contains Burst and PerSecond fields used by evaluate.go (if PerSecond > 0) to limit the speed with which the runtime can evaluate nodes.

    opened by zond 10
  • panic with arrayStash

    panic with arrayStash

    We got a crash of sync_gateway with this backtrace today. I'll attempt to reproduce this on my workstation, and update if I get more info.

    15:15:33.451897 CRUD: Invoking sync on doc "3C531BA3-BD50-41C8-9CFF-68681560C695" rev 1-4d1c2076f2440c1911de07b8144ebbc6
    panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash [recovered]
        panic: interface conversion: otto._stash is *otto._goArrayStash, not *otto._arrayStash
    
    goroutine 8 [running]:
    github.com/robertkrimen/otto.func·009()
        /Projects/Go/src/github.com/robertkrimen/otto/error.go:120 +0x768
    github.com/robertkrimen/otto.func·102()
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:178 +0x113
    github.com/robertkrimen/otto.func·010()
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:34 +0x15c
    github.com/robertkrimen/otto.func·103()
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:219 +0x377
    github.com/robertkrimen/otto.func·010()
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:34 +0x15c
    github.com/robertkrimen/otto.func·104()
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:238 +0x13c
    github.com/robertkrimen/otto.func·010()
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:34 +0x15c
    github.com/robertkrimen/otto.func·102()
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:178 +0x113
    github.com/robertkrimen/otto.func·010()
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:34 +0x15c
    github.com/robertkrimen/otto.func·010()
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:34 +0x15c
    github.com/robertkrimen/otto.func·104()
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:238 +0x13c
    github.com/robertkrimen/otto.func·010()
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:34 +0x15c
    github.com/robertkrimen/otto.func·010()
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:34 +0x15c
    github.com/robertkrimen/otto.func·104()
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:238 +0x13c
    github.com/robertkrimen/otto.func·010()
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:34 +0x15c
    github.com/robertkrimen/otto.func·010()
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:34 +0x15c
    github.com/robertkrimen/otto.func·102()
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:178 +0x113
    github.com/robertkrimen/otto.builtinArray_concat(0xc200b2fc30, 0x6, 0x3d5ca0, 0xc2008a7af0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/builtin_array.go:44 +0x2b9
    github.com/robertkrimen/otto._nativeCallFunction.Dispatch(0x0, 0x0, 0xc200883c40, 0x12, 0x4a5b10, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/type_function.go:156 +0xcb
    github.com/robertkrimen/otto.(*_nativeCallFunction).Dispatch(0xc200884810, 0xc200886640, 0xc2017156c0, 0xc200b2fc30, 0x6, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/builtin.go:0 +0x10e
    github.com/robertkrimen/otto.(*_runtime).Call(0xc200b2fc30, 0xc200886640, 0x6, 0x3d5ca0, 0xc2008a7af0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:185 +0x17b
    github.com/robertkrimen/otto.(*_runtime).evaluateCall(0xc200b2fc30, 0xc200b80e80, 0xc200b80e80, 0xc200b80e80, 0xeab901, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_expression.go:521 +0x698
    github.com/robertkrimen/otto.(*_runtime).evaluate(0xc200b2fc30, 0xc200238840, 0xc200b80e80, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:88 +0x1198
    github.com/robertkrimen/otto.(*_runtime).evaluateVariableDeclaration(0xc200b2fc30, 0xc20092dc30, 0x8, 0xeabba8, 0xeabba0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:57 +0x104
    github.com/robertkrimen/otto.(*_runtime).evaluateVariableDeclarationList(0xc200b2fc30, 0xc200a74540, 0xc200a74540, 0xc200a74540, 0x1, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:48 +0x64
    github.com/robertkrimen/otto.(*_runtime).evaluate(0xc200b2fc30, 0xc20017ad40, 0xc200a74540, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:41 +0x35e
    github.com/robertkrimen/otto.(*_runtime).evaluateBody(0xc200b2fc30, 0xc20035e680, 0x8, 0x8, 0xc200d38240, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:10 +0xad
    github.com/robertkrimen/otto.func·019(0xc200d00101, 0xc200f9a930, 0x4)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:113 +0x36
    github.com/robertkrimen/otto.(*_runtime).breakEvaluate(0xc200b2fc30, 0xc200b806c0, 0x0, 0xeabe58, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:242 +0x80
    github.com/robertkrimen/otto.(*_runtime).evaluateBlock(0xc200b2fc30, 0xc200b80680, 0xc200b80680, 0xc200b80680, 0xeabe01, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:114 +0xa5
    github.com/robertkrimen/otto.(*_runtime).evaluate(0xc200b2fc30, 0xc20017ad00, 0xc200b80680, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:52 +0x102f
    github.com/robertkrimen/otto.(*_runtime).evaluateIf(0xc200b2fc30, 0xc20092d820, 0xc20092d820, 0xc20092d820, 0x1, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:87 +0x121
    github.com/robertkrimen/otto.(*_runtime).evaluate(0xc200b2fc30, 0xc200215b40, 0xc20092d820, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:79 +0x120e
    github.com/robertkrimen/otto.(*_runtime).evaluateBody(0xc200b2fc30, 0xc200a84b60, 0x2, 0x2, 0xc200d381c8, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:10 +0xad
    github.com/robertkrimen/otto.func·019(0xc200f9a800, 0x182, 0x1bc60e)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:113 +0x36
    github.com/robertkrimen/otto.(*_runtime).breakEvaluate(0xc200b2fc30, 0xc200b804c0, 0x0, 0xeac518, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:242 +0x80
    github.com/robertkrimen/otto.(*_runtime).evaluateBlock(0xc200b2fc30, 0xc200b80480, 0xc200b80480, 0xc200b80480, 0x1e2f01, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:114 +0xa5
    github.com/robertkrimen/otto.(*_runtime).evaluate(0xc200b2fc30, 0xc20017ad00, 0xc200b80480, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:52 +0x102f
    github.com/robertkrimen/otto.(*_runtime).evaluateIf(0xc200b2fc30, 0xc20092d6e0, 0xc20092d6e0, 0xc20092d6e0, 0x1, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:87 +0x121
    github.com/robertkrimen/otto.(*_runtime).evaluate(0xc200b2fc30, 0xc200215b40, 0xc20092d6e0, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:79 +0x120e
    github.com/robertkrimen/otto.(*_runtime).evaluateBody(0xc200b2fc30, 0xc200a606c0, 0x3, 0x4, 0x4, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:10 +0xad
    github.com/robertkrimen/otto.(*_runtime)._callNode(0xc200b2fc30, 0xc2008a7820, 0xc20179aed0, 0xc200bfee10, 0x2, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:158 +0x44d
    github.com/robertkrimen/otto._nodeCallFunction.Dispatch(0xc2003cb150, 0xc20179ad50, 0x0, 0x0, 0xc200bfee10, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/type_function.go:178 +0x94
    github.com/robertkrimen/otto.(*_nodeCallFunction).Dispatch(0xc20179ae40, 0xc2008a7820, 0xc20179aed0, 0xc200b2fc30, 0x2, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/builtin.go:0 +0x10e
    github.com/robertkrimen/otto.(*_runtime).Call(0xc200b2fc30, 0xc2008a7820, 0x2, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:185 +0x17b
    github.com/robertkrimen/otto.(*_runtime).evaluateCall(0xc200b2fc30, 0xc200a60780, 0xc200a60780, 0xc200a60780, 0x101, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_expression.go:521 +0x698
    github.com/robertkrimen/otto.(*_runtime).evaluate(0xc200b2fc30, 0xc200238840, 0xc200a60780, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:88 +0x1198
    github.com/robertkrimen/otto.(*_runtime).evaluateBody(0xc200b2fc30, 0xc20066d7e0, 0x1, 0x1, 0xc200d38100, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:10 +0xad
    github.com/robertkrimen/otto.func·019(0x1b3b09, 0xc200f9a7c0, 0x3f31b0)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:113 +0x36
    github.com/robertkrimen/otto.(*_runtime).breakEvaluate(0xc200b2fc30, 0xc200a60740, 0x0, 0xa902c8, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:242 +0x80
    github.com/robertkrimen/otto.(*_runtime).evaluateBlock(0xc200b2fc30, 0xc200a60700, 0xc200a60700, 0xc200a60700, 0x1, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:114 +0xa5
    github.com/robertkrimen/otto.(*_runtime).evaluate(0xc200b2fc30, 0xc20017ad00, 0xc200a60700, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:52 +0x102f
    github.com/robertkrimen/otto.func·015(0x4, 0x2dc8e0, 0xc200f9a7e0)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:5 +0x3e
    github.com/robertkrimen/otto.(*_runtime).tryCatchEvaluate(0xc200b2fc30, 0xa90548, 0x0, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:223 +0xb7
    github.com/robertkrimen/otto.(*_runtime).evaluateTryCatch(0xc200b2fc30, 0xc200a60800, 0x0, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate_statement.go:6 +0x95
    github.com/robertkrimen/otto.(*_runtime).evaluate(0xc200b2fc30, 0xc2002ac680, 0xc200a60800, 0x0, 0x0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:112 +0x3c8
    github.com/robertkrimen/otto.(*_runtime).evaluateBody(0xc200b2fc30, 0xc200b9c4e0, 0x2, 0x2, 0x1, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/evaluate.go:10 +0xad
    github.com/robertkrimen/otto.(*_runtime)._callNode(0xc200b2fc30, 0xc20089f780, 0xc20179ad50, 0xc200bfed80, 0x6, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:158 +0x44d
    github.com/robertkrimen/otto._nodeCallFunction.Dispatch(0xc200163e00, 0xc200be4840, 0x0, 0x0, 0xc200bfed80, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/type_function.go:178 +0x94
    github.com/robertkrimen/otto.(*_nodeCallFunction).Dispatch(0xc200a74ea0, 0xc20089f780, 0xc20179ad50, 0xc200b2fc30, 0x6, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/builtin.go:0 +0x10e
    github.com/robertkrimen/otto.(*_runtime).Call(0xc200b2fc30, 0xc20089f780, 0x6, 0x3d5ca0, 0xc20089f780, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/runtime.go:185 +0x17b
    github.com/robertkrimen/otto.(*_object).Call(0xc20089f780, 0x6, 0x3d5ca0, 0xc20089f780, 0xc20179acc0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/type_function.go:45 +0x226
    github.com/robertkrimen/otto.Value.call(0x6, 0x3d5ca0, 0xc20089f780, 0x6, 0x3d5ca0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/value.go:117 +0xdc
    github.com/robertkrimen/otto.func·110()
        /Projects/Go/src/github.com/robertkrimen/otto/value.go:109 +0x63
    github.com/robertkrimen/otto.catchPanic(0xa90cd0, 0x0, 0x0)
        /Projects/Go/src/github.com/robertkrimen/otto/error.go:123 +0x6b
    github.com/robertkrimen/otto.Value.Call(0x6, 0x3d5ca0, 0xc20089f780, 0x6, 0x3d5ca0, ...)
        /Projects/Go/src/github.com/robertkrimen/otto/value.go:110 +0xcc
    github.com/couchbaselabs/walrus.(*JSServer).DirectCall(0xc20092d4b0, 0xc20179ac90, 0x3, 0x3, 0x3, ...)
        /Projects/Go/src/github.com/couchbaselabs/walrus/js_server.go:157 +0x49f
    github.com/couchbaselabs/walrus.(*JSServer).serve(0xc20092d4b0)
        /Projects/Go/src/github.com/couchbaselabs/walrus/js_server.go:194 +0x102
    created by github.com/couchbaselabs/walrus.NewJSServer
        /Projects/Go/src/github.com/couchbaselabs/walrus/js_server.go:63 +0x15d
    
    opened by jchris 10
A BASIC interpreter written in golang.

05 PRINT "Index" 10 PRINT "GOBASIC!" 20 PRINT "Limitations" Arrays Line Numbers IF Statement DATA / READ Statements Builtin Functions Types 30 PRINT "

Steve Kemp 282 Aug 20, 2022
Scriptable interpreter written in golang

Anko Anko is a scriptable interpreter written in Go. (Picture licensed under CC BY-SA 3.0, photo by Ocdp) Usage Example - Embedded package main impor

mattn 1.3k Sep 25, 2022
A compiler from Go to JavaScript for running Go code in a browser

GopherJS - A compiler from Go to JavaScript GopherJS compiles Go code (golang.org) to pure JavaScript code. Its main purpose is to give you the opport

GopherJS 11.5k Sep 26, 2022
ECMAScript/JavaScript engine in pure Go

goja ECMAScript 5.1(+) implementation in Go. Goja is an implementation of ECMAScript 5.1 in pure Go with emphasis on standard compliance and performan

Dmitry Panov 3.2k Sep 21, 2022
gpython is a python interpreter written in go "batteries not included"

gpython gpython is a part re-implementation / part port of the Python 3.4 interpreter to the Go language, "batteries not included". It includes: runti

go-python 621 Sep 22, 2022
wagon, a WebAssembly-based Go interpreter, for Go.

wagon wagon is a WebAssembly-based interpreter in Go, for Go. As of 2020/05/11 Wagon is in read-only mode, and looking for a maintainer. You may want

Go Interpreter 900 Aug 6, 2022
Yaegi is Another Elegant Go Interpreter

Yaegi is Another Elegant Go Interpreter. It powers executable Go scripts and plugins, in embedded interpreters or interactive shells, on top of the Go

Traefik Labs 4.9k Sep 24, 2022
Lisp Interpreter

golisp Lisp Interpreter Usage $ golisp < foo.lisp Installation $ go get github.com/mattn/golisp/cmd/golisp Features Call Go functions. Print random in

mattn 121 Sep 20, 2022
A simple interpreter

类型: 基础类型: 整形,浮点,字符串,布尔,空值(nil) 符合类型: 数组,只读数组(元组),字典 支持语句: if, elif, else, for, foreach, break, continue, return 支持类型定义: class, func 语法格式: 赋值语句---> ```

null 19 Aug 10, 2022
Transpiling fortran code to golang code

f4go Example of use > # Install golang > # Compile f4go > go get -u github.com/Konstantin8105/f4go > cd $GOPATH/src/github.com/Konstantin8105/f4go > g

Konstantin 33 Sep 18, 2022
PHP bindings for the Go programming language (Golang)

PHP bindings for Go This package implements support for executing PHP scripts, exporting Go variables for use in PHP contexts, attaching Go method rec

Alex Palaistras 868 Sep 8, 2022
High-performance PHP-to-Golang IPC bridge

High-performance PHP-to-Golang IPC bridge Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/r

Spiral Scout 1.1k Sep 22, 2022
High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 6.7k Sep 25, 2022
Expression evaluation in golang

Gval Gval (Go eVALuate) provides support for evaluating arbitrary expressions, in particular Go-like expressions. Evaluate Gval can evaluate expressio

null 532 Sep 27, 2022
golang AST matcher

goastch (GO AST matCH) Introduction Inspired by ast matcher. There are four different basic categories of matchers: Node Matchers: Matchers that match

Helloyi He 14 Apr 19, 2022
Arbitrary expression evaluation for golang

govaluate Provides support for evaluating arbitrary C-like artithmetic/string expressions. Why can't you just write these expressions in code? Sometim

George Lester 2.7k Sep 26, 2022
hotbuild - a cross platform hot compilation tool for golang

hotbuild A cross platform hot compilation tool By monitoring the modification of the project directory file, the recompilation and running are automat

wander 190 Sep 19, 2022
The golang tool of the zig compiler automatically compiles different targets according to the GOOS GOARCH environment variable. You need to install zig.

The golang tool of the zig compiler automatically compiles different targets according to the GOOS GOARCH environment variable. You need to install zig.

dosgo 28 Sep 18, 2022
Tgo - Test Helpers for Standard Golang Packages

Test Helpers for Standard Golang Packages see example_test.go go test --- FAIL:

krhubert 1 Apr 26, 2022