README

goja

ECMAScript 5.1(+) implementation in Go.

GoDoc

Goja is an implementation of ECMAScript 5.1 in pure Go with emphasis on standard compliance and performance.

This project was largely inspired by otto.

Minimum required Go version is 1.14.

Features

Known incompatibilities and caveats

WeakMap

WeakMap is implemented by embedding references to the values into the keys. This means that as long as the key is reachable all values associated with it in any weak maps also remain reachable and therefore cannot be garbage collected even if they are not otherwise referenced, even after the WeakMap is gone. The reference to the value is dropped either when the key is explicitly removed from the WeakMap or when the key becomes unreachable.

To illustrate this:

var m = new WeakMap();
var key = {};
var value = {/* a very large object */};
m.set(key, value);
value = undefined;
m = undefined; // The value does NOT become garbage-collectable at this point
key = undefined; // Now it does
// m.delete(key); // This would work too

The reason for it is the limitation of the Go runtime. At the time of writing (version 1.15) having a finalizer set on an object which is part of a reference cycle makes the whole cycle non-garbage-collectable. The solution above is the only reasonable way I can think of without involving finalizers. This is the third attempt (see https://github.com/dop251/goja/issues/250 and https://github.com/dop251/goja/issues/199 for more details).

Note, this does not have any effect on the application logic, but may cause a higher-than-expected memory usage.

FAQ

How fast is it?

Although it's faster than many scripting language implementations in Go I have seen (for example it's 6-7 times faster than otto on average) it is not a replacement for V8 or SpiderMonkey or any other general-purpose JavaScript engine. You can find some benchmarks here.

Why would I want to use it over a V8 wrapper?

It greatly depends on your usage scenario. If most of the work is done in javascript (for example crypto or any other heavy calculations) you are definitely better off with V8.

If you need a scripting language that drives an engine written in Go so that you need to make frequent calls between Go and javascript passing complex data structures then the cgo overhead may outweigh the benefits of having a faster javascript engine.

Because it's written in pure Go there are no cgo dependencies, it's very easy to build and it should run on any platform supported by Go.

It gives you a much better control over execution environment so can be useful for research.

Is it goroutine-safe?

No. An instance of goja.Runtime can only be used by a single goroutine at a time. You can create as many instances of Runtime as you like but it's not possible to pass object values between runtimes.

Where is setTimeout()?

setTimeout() assumes concurrent execution of code which requires an execution environment, for example an event loop similar to nodejs or a browser. There is a separate project aimed at providing some NodeJS functionality, and it includes an event loop.

Can you implement (feature X from ES6 or higher)?

Some ES6 functionality has been implemented. So far this is mostly built-ins, not syntax enhancements. See https://github.com/dop251/goja/milestone/1 for more details.

The ongoing work is done in the es6 branch which is merged into master when appropriate. Every commit in this branch represents a relatively stable state (i.e. it compiles and passes all enabled tc39 tests), however because the version of tc39 tests I use is quite old, it may be not as well tested as the ES5.1 functionality. Because ES6 is a superset of ES5.1 it should not break your existing code.

I will be adding features in their dependency order and as quickly as my time allows. Please do not ask for ETAs. Features that are open in the milestone are either in progress or will be worked on next.

How do I contribute?

Before submitting a pull request please make sure that:

  • You followed ECMA standard as close as possible. If adding a new feature make sure you've read the specification, do not just base it on a couple of examples that work fine.
  • Your change does not have a significant negative impact on performance (unless it's a bugfix and it's unavoidable)
  • It passes all relevant tc39 tests.

Current Status

  • There should be no breaking changes in the API, however it may be extended.
  • Some of the AnnexB functionality is missing.

Basic Example

Run JavaScript and get the result value.

vm := goja.New()
v, err := vm.RunString("2 + 2")
if err != nil {
    panic(err)
}
if num := v.Export().(int64); num != 4 {
    panic(num)
}

Passing Values to JS

Any Go value can be passed to JS using Runtime.ToValue() method. See the method's documentation for more details.

Exporting Values from JS

A JS value can be exported into its default Go representation using Value.Export() method.

Alternatively it can be exported into a specific Go variable using Runtime.ExportTo() method.

Within a single export operation the same Object will be represented by the same Go value (either the same map, slice or a pointer to the same struct). This includes circular objects and makes it possible to export them.

Calling JS functions from Go

There are 2 approaches:

vm := New()
_, err := vm.RunString(`
function sum(a, b) {
    return a+b;
}
`)
if err != nil {
    panic(err)
}
sum, ok := AssertFunction(vm.Get("sum"))
if !ok {
    panic("Not a function")
}

res, err := sum(Undefined(), vm.ToValue(40), vm.ToValue(2))
if err != nil {
    panic(err)
}
fmt.Println(res)
// Output: 42
const SCRIPT = `
function f(param) {
    return +param + 2;
}
`

vm := New()
_, err := vm.RunString(SCRIPT)
if err != nil {
    panic(err)
}

var fn func(string) string
err = vm.ExportTo(vm.Get("f"), &fn)
if err != nil {
    panic(err)
}

fmt.Println(fn("40")) // note, _this_ value in the function will be undefined.
// Output: 42

The first one is more low level and allows specifying this value, whereas the second one makes the function look like a normal Go function.

Mapping struct field and method names

By default, the names are passed through as is which means they are capitalised. This does not match the standard JavaScript naming convention, so if you need to make your JS code look more natural or if you are dealing with a 3rd party library, you can use a FieldNameMapper:

vm := New()
vm.SetFieldNameMapper(TagFieldNameMapper("json", true))
type S struct {
    Field int `json:"field"`
}
vm.Set("s", S{Field: 42})
res, _ := vm.RunString(`s.field`) // without the mapper it would have been s.Field
fmt.Println(res.Export())
// Output: 42

There are two standard mappers: TagFieldNameMapper and UncapFieldNameMapper, or you can use your own implementation.

Native Constructors

In order to implement a constructor function in Go use func (goja.ConstructorCall) *goja.Object. See Runtime.ToValue() documentation for more details.

Regular Expressions

Goja uses the embedded Go regexp library where possible, otherwise it falls back to regexp2.

Exceptions

Any exception thrown in JavaScript is returned as an error of type *Exception. It is possible to extract the value thrown by using the Value() method:

vm := New()
_, err := vm.RunString(`

throw("Test");

`)

if jserr, ok := err.(*Exception); ok {
    if jserr.Value().Export() != "Test" {
        panic("wrong value")
    }
} else {
    panic("wrong type")
}

If a native Go function panics with a Value, it is thrown as a Javascript exception (and therefore can be caught):

var vm *Runtime

func Test() {
    panic(vm.ToValue("Error"))
}

vm = New()
vm.Set("Test", Test)
_, err := vm.RunString(`

try {
    Test();
} catch(e) {
    if (e !== "Error") {
        throw e;
    }
}

`)

if err != nil {
    panic(err)
}

Interrupting

func TestInterrupt(t *testing.T) {
    const SCRIPT = `
    var i = 0;
    for (;;) {
        i++;
    }
    `

    vm := New()
    time.AfterFunc(200 * time.Millisecond, func() {
        vm.Interrupt("halt")
    })

    _, err := vm.RunString(SCRIPT)
    if err == nil {
        t.Fatal("Err is nil")
    }
    // err is of type *InterruptError and its Value() method returns whatever has been passed to vm.Interrupt()
}

NodeJS Compatibility

There is a separate project aimed at providing some of the NodeJS functionality.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	SymHasInstance        = newSymbol(asciiString("Symbol.hasInstance"))
	SymIsConcatSpreadable = newSymbol(asciiString("Symbol.isConcatSpreadable"))
	SymIterator           = newSymbol(asciiString("Symbol.iterator"))
	SymMatch              = newSymbol(asciiString("Symbol.match"))
	SymMatchAll           = newSymbol(asciiString("Symbol.matchAll"))
	SymReplace            = newSymbol(asciiString("Symbol.replace"))
	SymSearch             = newSymbol(asciiString("Symbol.search"))
	SymSpecies            = newSymbol(asciiString("Symbol.species"))
	SymSplit              = newSymbol(asciiString("Symbol.split"))
	SymToPrimitive        = newSymbol(asciiString("Symbol.toPrimitive"))
	SymToStringTag        = newSymbol(asciiString("Symbol.toStringTag"))
	SymUnscopables        = newSymbol(asciiString("Symbol.unscopables"))
)
View Source
var (
	InvalidRuneError = errors.New("invalid rune")
)

Functions

func IsInfinity

func IsInfinity(v Value) bool

    IsInfinity returns true if the supplied is (+/-)Infinity

    func IsNaN

    func IsNaN(v Value) bool

      IsNaN returns true if the supplied value is NaN.

      func IsNull

      func IsNull(v Value) bool

        IsNull returns true if the supplied Value is null.

        func IsUndefined

        func IsUndefined(v Value) bool

          IsUndefined returns true if the supplied Value is undefined. Note, it checks against the real undefined, not against the global object's 'undefined' property.

          func Parse

          func Parse(name, src string, options ...parser.Option) (prg *js_ast.Program, err error)

            Parse takes a source string and produces a parsed AST. Use this function if you want to pass options to the parser, e.g.:

            p, err := Parse("test.js", "var a = true", parser.WithDisableSourceMaps)
            if err != nil { /* ... */ }
            prg, err := CompileAST(p, true)
            // ...
            

            Otherwise use Compile which combines both steps.

            Types

            type ArrayBuffer

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

              ArrayBuffer is a Go wrapper around ECMAScript ArrayBuffer. Calling Runtime.ToValue() on it returns the underlying ArrayBuffer. Calling Export() on an ECMAScript ArrayBuffer returns a wrapper. Use Runtime.NewArrayBuffer([]byte) to create one.

              func (ArrayBuffer) Bytes

              func (a ArrayBuffer) Bytes() []byte

                Bytes returns the underlying []byte for this ArrayBuffer. For detached ArrayBuffers returns nil.

                func (ArrayBuffer) Detach

                func (a ArrayBuffer) Detach() bool

                  Detach the ArrayBuffer. After this, the underlying []byte becomes unreferenced and any attempt to use this ArrayBuffer results in a TypeError. Returns false if it was already detached, true otherwise. Note, this method may only be called from the goroutine that 'owns' the Runtime, it may not be called concurrently.

                  func (ArrayBuffer) Detached

                  func (a ArrayBuffer) Detached() bool

                    Detached returns true if the ArrayBuffer is detached.

                    type Callable

                    type Callable func(this Value, args ...Value) (Value, error)

                      Callable represents a JavaScript function that can be called from Go.

                      func AssertFunction

                      func AssertFunction(v Value) (Callable, bool)

                        AssertFunction checks if the Value is a function and returns a Callable.

                        Example
                        Output:
                        
                        42
                        

                        type CompilerError

                        type CompilerError struct {
                        	Message string
                        	File    *file.File
                        	Offset  int
                        }

                        type CompilerReferenceError

                        type CompilerReferenceError struct {
                        	CompilerError
                        }

                        func (*CompilerReferenceError) Error

                        func (e *CompilerReferenceError) Error() string

                        type CompilerSyntaxError

                        type CompilerSyntaxError struct {
                        	CompilerError
                        }

                        func (*CompilerSyntaxError) Error

                        func (e *CompilerSyntaxError) Error() string

                        type ConstructorCall

                        type ConstructorCall struct {
                        	This      *Object
                        	Arguments []Value
                        	NewTarget *Object
                        }

                        func (ConstructorCall) Argument

                        func (f ConstructorCall) Argument(idx int) Value

                        type DynamicArray

                        type DynamicArray interface {
                        	// Len returns the current array length.
                        	Len() int
                        	// Get an item at index idx. Note that idx may be any integer, negative or beyond the current length.
                        	Get(idx int) Value
                        	// Set an item at index idx. Note that idx may be any integer, negative or beyond the current length.
                        	// The expected behaviour when it's beyond length is that the array's length is increased to accommodate
                        	// the item. All elements in the 'new' section of the array should be zeroed.
                        	Set(idx int, val Value) bool
                        	// SetLen is called when the array's 'length' property is changed. If the length is increased all elements in the
                        	// 'new' section of the array should be zeroed.
                        	SetLen(int) bool
                        }

                          DynamicArray is an interface representing a handler for a dynamic array Object. Such an object can be created using the Runtime.NewDynamicArray() method.

                          Any integer property key or a string property key that can be parsed into an int value (including negative ones) is treated as an index and passed to the trap methods of the DynamicArray. Note this is different from the regular ECMAScript arrays which only support positive indexes up to 2^32-1.

                          DynamicArray cannot be sparse, i.e. hasOwnProperty(num) will return true for num >= 0 && num < Len(). Deleting such a property is equivalent to setting it to undefined. Note that this creates a slight peculiarity because hasOwnProperty() will still return true, even after deletion.

                          Note that Runtime.ToValue() does not have any special treatment for DynamicArray. The only way to create a dynamic array is by using the Runtime.NewDynamicArray() method. This is done deliberately to avoid silent code breaks when this interface changes.

                          type DynamicObject

                          type DynamicObject interface {
                          	// Get a property value for the key. May return nil if the property does not exist.
                          	Get(key string) Value
                          	// Set a property value for the key. Return true if success, false otherwise.
                          	Set(key string, val Value) bool
                          	// Has should return true if and only if the property exists.
                          	Has(key string) bool
                          	// Delete the property for the key. Returns true on success (note, that includes missing property).
                          	Delete(key string) bool
                          	// Keys returns a list of all existing property keys. There are no checks for duplicates or to make sure
                          	// that the order conforms to https://262.ecma-international.org/#sec-ordinaryownpropertykeys
                          	Keys() []string
                          }

                            DynamicObject is an interface representing a handler for a dynamic Object. Such an object can be created using the Runtime.NewDynamicObject() method.

                            Note that Runtime.ToValue() does not have any special treatment for DynamicObject. The only way to create a dynamic object is by using the Runtime.NewDynamicObject() method. This is done deliberately to avoid silent code breaks when this interface changes.

                            type Exception

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

                            func (*Exception) Error

                            func (e *Exception) Error() string

                            func (*Exception) String

                            func (e *Exception) String() string

                            func (*Exception) Value

                            func (e *Exception) Value() Value

                            type FieldNameMapper

                            type FieldNameMapper interface {
                            	// FieldName returns a JavaScript name for the given struct field in the given type.
                            	// If this method returns "" the field becomes hidden.
                            	FieldName(t reflect.Type, f reflect.StructField) string
                            
                            	// MethodName returns a JavaScript name for the given method in the given type.
                            	// If this method returns "" the method becomes hidden.
                            	MethodName(t reflect.Type, m reflect.Method) string
                            }

                              FieldNameMapper provides custom mapping between Go and JavaScript property names.

                              func TagFieldNameMapper

                              func TagFieldNameMapper(tagName string, uncapMethods bool) FieldNameMapper

                                TagFieldNameMapper returns a FieldNameMapper that uses the given tagName for struct fields and optionally uncapitalises (making the first letter lower case) method names. The common tag value syntax is supported (name[,options]), however options are ignored. Setting name to anything other than a valid ECMAScript identifier makes the field hidden.

                                Example
                                Output:
                                
                                42
                                

                                func UncapFieldNameMapper

                                func UncapFieldNameMapper() FieldNameMapper

                                  UncapFieldNameMapper returns a FieldNameMapper that uncapitalises struct field and method names making the first letter lower case.

                                  Example
                                  Output:
                                  
                                  passed and passed too
                                  

                                  type Flag

                                  type Flag int
                                  const (
                                  	FLAG_NOT_SET Flag = iota
                                  	FLAG_FALSE
                                  	FLAG_TRUE
                                  )

                                  func ToFlag

                                  func ToFlag(b bool) Flag

                                  func (Flag) Bool

                                  func (f Flag) Bool() bool

                                  type FunctionCall

                                  type FunctionCall struct {
                                  	This      Value
                                  	Arguments []Value
                                  }

                                  func (FunctionCall) Argument

                                  func (f FunctionCall) Argument(idx int) Value

                                  type InterruptedError

                                  type InterruptedError struct {
                                  	Exception
                                  	// contains filtered or unexported fields
                                  }

                                  func (*InterruptedError) Error

                                  func (e *InterruptedError) Error() string

                                  func (*InterruptedError) String

                                  func (e *InterruptedError) String() string

                                  func (*InterruptedError) Value

                                  func (e *InterruptedError) Value() interface{}

                                  type JsonEncodable

                                  type JsonEncodable interface {
                                  	JsonEncodable() interface{}
                                  }

                                    JsonEncodable allows custom JSON encoding by JSON.stringify() Note that if the returned value itself also implements JsonEncodable, it won't have any effect.

                                    type Now

                                    type Now func() time.Time

                                    type Object

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

                                    func (*Object) ClassName

                                    func (o *Object) ClassName() string

                                      ClassName returns the class name

                                      func (*Object) DefineAccessorProperty

                                      func (o *Object) DefineAccessorProperty(name string, getter, setter Value, configurable, enumerable Flag) error

                                        DefineAccessorProperty is a Go equivalent of Object.defineProperty(o, name, {get: getter, set: setter, configurable: configurable, enumerable: enumerable})

                                        func (*Object) DefineAccessorPropertySymbol

                                        func (o *Object) DefineAccessorPropertySymbol(name *Symbol, getter, setter Value, configurable, enumerable Flag) error

                                          DefineAccessorPropertySymbol is a Go equivalent of Object.defineProperty(o, name, {get: getter, set: setter, configurable: configurable, enumerable: enumerable})

                                          func (*Object) DefineDataProperty

                                          func (o *Object) DefineDataProperty(name string, value Value, writable, configurable, enumerable Flag) error

                                            DefineDataProperty is a Go equivalent of Object.defineProperty(o, name, {value: value, writable: writable, configurable: configurable, enumerable: enumerable})

                                            func (*Object) DefineDataPropertySymbol

                                            func (o *Object) DefineDataPropertySymbol(name *Symbol, value Value, writable, configurable, enumerable Flag) error

                                              DefineDataPropertySymbol is a Go equivalent of Object.defineProperty(o, name, {value: value, writable: writable, configurable: configurable, enumerable: enumerable})

                                              func (*Object) Delete

                                              func (o *Object) Delete(name string) error
                                              Example
                                              Output:
                                              
                                              before: true, after: <nil>
                                              

                                              func (*Object) DeleteSymbol

                                              func (o *Object) DeleteSymbol(name *Symbol) error

                                              func (*Object) Equals

                                              func (o *Object) Equals(other Value) bool

                                              func (*Object) Export

                                              func (o *Object) Export() (ret interface{})

                                                Export the Object to a plain Go type. The returned value will be map[string]interface{} unless the Object is a wrapped Go value (created using ToValue()). This method will panic with an *Exception if a JavaScript exception is thrown in the process.

                                                func (*Object) ExportType

                                                func (o *Object) ExportType() reflect.Type

                                                func (*Object) Get

                                                func (o *Object) Get(name string) Value

                                                  Get an object's property by name. This method will panic with an *Exception if a JavaScript exception is thrown in the process.

                                                  func (*Object) GetSymbol

                                                  func (o *Object) GetSymbol(sym *Symbol) Value

                                                    GetSymbol returns the value of a symbol property. Use one of the Sym* values for well-known symbols (such as SymIterator, SymToStringTag, etc...). This method will panic with an *Exception if a JavaScript exception is thrown in the process.

                                                    func (*Object) Keys

                                                    func (o *Object) Keys() (keys []string)

                                                      Keys returns a list of Object's enumerable keys. This method will panic with an *Exception if a JavaScript exception is thrown in the process.

                                                      func (*Object) MarshalJSON

                                                      func (o *Object) MarshalJSON() ([]byte, error)

                                                        MarshalJSON returns JSON representation of the Object. It is equivalent to JSON.stringify(o). Note, this implements json.Marshaler so that json.Marshal() can be used without the need to Export().

                                                        func (*Object) Prototype

                                                        func (o *Object) Prototype() *Object

                                                          Prototype returns the Object's prototype, same as Object.getPrototypeOf(). If the prototype is null returns nil.

                                                          func (*Object) SameAs

                                                          func (o *Object) SameAs(other Value) bool

                                                          func (*Object) Set

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

                                                          func (*Object) SetPrototype

                                                          func (o *Object) SetPrototype(proto *Object) error

                                                            SetPrototype sets the Object's prototype, same as Object.setPrototypeOf(). Setting proto to nil is an equivalent of Object.setPrototypeOf(null).

                                                            func (*Object) SetSymbol

                                                            func (o *Object) SetSymbol(name *Symbol, value interface{}) error
                                                            Example
                                                            Output:
                                                            
                                                            1 2 3 4 5 6 7 8 9 10
                                                            

                                                            func (*Object) StrictEquals

                                                            func (o *Object) StrictEquals(other Value) bool

                                                            func (*Object) String

                                                            func (o *Object) String() string

                                                            func (*Object) Symbols

                                                            func (o *Object) Symbols() []*Symbol

                                                              Symbols returns a list of Object's enumerable symbol properties. This method will panic with an *Exception if a JavaScript exception is thrown in the process.

                                                              func (*Object) ToBoolean

                                                              func (o *Object) ToBoolean() bool

                                                              func (*Object) ToFloat

                                                              func (o *Object) ToFloat() float64

                                                              func (*Object) ToInteger

                                                              func (o *Object) ToInteger() int64

                                                              func (*Object) ToNumber

                                                              func (o *Object) ToNumber() Value

                                                              func (*Object) ToObject

                                                              func (o *Object) ToObject(*Runtime) *Object

                                                              func (*Object) ToString

                                                              func (o *Object) ToString() Value

                                                              type Program

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

                                                              func Compile

                                                              func Compile(name, src string, strict bool) (*Program, error)

                                                                Compile creates an internal representation of the JavaScript code that can be later run using the Runtime.RunProgram() method. This representation is not linked to a runtime in any way and can be run in multiple runtimes (possibly at the same time).

                                                                func CompileAST

                                                                func CompileAST(prg *js_ast.Program, strict bool) (*Program, error)

                                                                  CompileAST creates an internal representation of the JavaScript code that can be later run using the Runtime.RunProgram() method. This representation is not linked to a runtime in any way and can be run in multiple runtimes (possibly at the same time).

                                                                  func MustCompile

                                                                  func MustCompile(name, src string, strict bool) *Program

                                                                    MustCompile is like Compile but panics if the code cannot be compiled. It simplifies safe initialization of global variables holding compiled JavaScript code.

                                                                    type PropertyDescriptor

                                                                    type PropertyDescriptor struct {
                                                                    	Value Value
                                                                    
                                                                    	Writable, Configurable, Enumerable Flag
                                                                    
                                                                    	Getter, Setter Value
                                                                    	// contains filtered or unexported fields
                                                                    }

                                                                    func (*PropertyDescriptor) Empty

                                                                    func (p *PropertyDescriptor) Empty() bool

                                                                    type Proxy

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

                                                                      Proxy is a Go wrapper around ECMAScript Proxy. Calling Runtime.ToValue() on it returns the underlying Proxy. Calling Export() on an ECMAScript Proxy returns a wrapper. Use Runtime.NewProxy() to create one.

                                                                      func (Proxy) Handler

                                                                      func (p Proxy) Handler() *Object

                                                                      func (Proxy) Revoke

                                                                      func (p Proxy) Revoke()

                                                                      func (Proxy) Target

                                                                      func (p Proxy) Target() *Object

                                                                      type ProxyTrapConfig

                                                                      type ProxyTrapConfig struct {
                                                                      	// A trap for Object.getPrototypeOf, Reflect.getPrototypeOf, __proto__, Object.prototype.isPrototypeOf, instanceof
                                                                      	GetPrototypeOf func(target *Object) (prototype *Object)
                                                                      
                                                                      	// A trap for Object.setPrototypeOf, Reflect.setPrototypeOf
                                                                      	SetPrototypeOf func(target *Object, prototype *Object) (success bool)
                                                                      
                                                                      	// A trap for Object.isExtensible, Reflect.isExtensible
                                                                      	IsExtensible func(target *Object) (success bool)
                                                                      
                                                                      	// A trap for Object.preventExtensions, Reflect.preventExtensions
                                                                      	PreventExtensions func(target *Object) (success bool)
                                                                      
                                                                      	// A trap for Object.getOwnPropertyDescriptor, Reflect.getOwnPropertyDescriptor (string properties)
                                                                      	GetOwnPropertyDescriptor func(target *Object, prop string) (propertyDescriptor PropertyDescriptor)
                                                                      
                                                                      	// A trap for Object.getOwnPropertyDescriptor, Reflect.getOwnPropertyDescriptor (integer properties)
                                                                      	GetOwnPropertyDescriptorIdx func(target *Object, prop int) (propertyDescriptor PropertyDescriptor)
                                                                      
                                                                      	// A trap for Object.getOwnPropertyDescriptor, Reflect.getOwnPropertyDescriptor (Symbol properties)
                                                                      	GetOwnPropertyDescriptorSym func(target *Object, prop *Symbol) (propertyDescriptor PropertyDescriptor)
                                                                      
                                                                      	// A trap for Object.defineProperty, Reflect.defineProperty (string properties)
                                                                      	DefineProperty func(target *Object, key string, propertyDescriptor PropertyDescriptor) (success bool)
                                                                      
                                                                      	// A trap for Object.defineProperty, Reflect.defineProperty (integer properties)
                                                                      	DefinePropertyIdx func(target *Object, key int, propertyDescriptor PropertyDescriptor) (success bool)
                                                                      
                                                                      	// A trap for Object.defineProperty, Reflect.defineProperty (Symbol properties)
                                                                      	DefinePropertySym func(target *Object, key *Symbol, propertyDescriptor PropertyDescriptor) (success bool)
                                                                      
                                                                      	// A trap for the in operator, with operator, Reflect.has (string properties)
                                                                      	Has func(target *Object, property string) (available bool)
                                                                      
                                                                      	// A trap for the in operator, with operator, Reflect.has (integer properties)
                                                                      	HasIdx func(target *Object, property int) (available bool)
                                                                      
                                                                      	// A trap for the in operator, with operator, Reflect.has (Symbol properties)
                                                                      	HasSym func(target *Object, property *Symbol) (available bool)
                                                                      
                                                                      	// A trap for getting property values, Reflect.get (string properties)
                                                                      	Get func(target *Object, property string, receiver Value) (value Value)
                                                                      
                                                                      	// A trap for getting property values, Reflect.get (integer properties)
                                                                      	GetIdx func(target *Object, property int, receiver Value) (value Value)
                                                                      
                                                                      	// A trap for getting property values, Reflect.get (Symbol properties)
                                                                      	GetSym func(target *Object, property *Symbol, receiver Value) (value Value)
                                                                      
                                                                      	// A trap for setting property values, Reflect.set (string properties)
                                                                      	Set func(target *Object, property string, value Value, receiver Value) (success bool)
                                                                      
                                                                      	// A trap for setting property values, Reflect.set (integer properties)
                                                                      	SetIdx func(target *Object, property int, value Value, receiver Value) (success bool)
                                                                      
                                                                      	// A trap for setting property values, Reflect.set (Symbol properties)
                                                                      	SetSym func(target *Object, property *Symbol, value Value, receiver Value) (success bool)
                                                                      
                                                                      	// A trap for the delete operator, Reflect.deleteProperty (string properties)
                                                                      	DeleteProperty func(target *Object, property string) (success bool)
                                                                      
                                                                      	// A trap for the delete operator, Reflect.deleteProperty (integer properties)
                                                                      	DeletePropertyIdx func(target *Object, property int) (success bool)
                                                                      
                                                                      	// A trap for the delete operator, Reflect.deleteProperty (Symbol properties)
                                                                      	DeletePropertySym func(target *Object, property *Symbol) (success bool)
                                                                      
                                                                      	// A trap for Object.getOwnPropertyNames, Object.getOwnPropertySymbols, Object.keys, Reflect.ownKeys
                                                                      	OwnKeys func(target *Object) (object *Object)
                                                                      
                                                                      	// A trap for a function call, Function.prototype.apply, Function.prototype.call, Reflect.apply
                                                                      	Apply func(target *Object, this Value, argumentsList []Value) (value Value)
                                                                      
                                                                      	// A trap for the new operator, Reflect.construct
                                                                      	Construct func(target *Object, argumentsList []Value, newTarget *Object) (value *Object)
                                                                      }

                                                                        ProxyTrapConfig provides a simplified Go-friendly API for implementing Proxy traps. If an *Idx trap is defined it gets called for integer property keys, including negative ones. Note that this also includes string property keys that can be parsed into an integer. This allows more efficient array operations. If an *Idx trap is not set, the corresponding string one is used.

                                                                        type RandSource

                                                                        type RandSource func() float64

                                                                        type Runtime

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

                                                                        func New

                                                                        func New() *Runtime

                                                                          New creates an instance of a Javascript runtime that can be used to run code. Multiple instances may be created and used simultaneously, however it is not possible to pass JS values across runtimes.

                                                                          func (*Runtime) CaptureCallStack

                                                                          func (r *Runtime) CaptureCallStack(depth int, stack []StackFrame) []StackFrame

                                                                            CaptureCallStack appends the current call stack frames to the stack slice (which may be nil) up to the specified depth. The most recent frame will be the first one. If depth <= 0 or more than the number of available frames, returns the entire stack. This method is not safe for concurrent use and should only be called by a Go function that is called from a running script.

                                                                            func (*Runtime) ClearInterrupt

                                                                            func (r *Runtime) ClearInterrupt()

                                                                              ClearInterrupt resets the interrupt flag. Typically this needs to be called before the runtime is made available for re-use if there is a chance it could have been interrupted with Interrupt(). Otherwise if Interrupt() was called when runtime was not running (e.g. if it had already finished) so that Interrupt() didn't actually trigger, an attempt to use the runtime will immediately cause an interruption. It is up to the user to ensure proper synchronisation so that ClearInterrupt() is only called when the runtime has finished and there is no chance of a concurrent Interrupt() call.

                                                                              func (*Runtime) CreateObject

                                                                              func (r *Runtime) CreateObject(proto *Object) *Object

                                                                                CreateObject creates an object with given prototype. Equivalent of Object.create(proto).

                                                                                func (*Runtime) ExportTo

                                                                                func (r *Runtime) ExportTo(v Value, target interface{}) error

                                                                                  ExportTo converts a JavaScript value into the specified Go value. The second parameter must be a non-nil pointer. Exporting to an interface{} results in a value of the same type as Export() would produce. Exporting to numeric types uses the standard ECMAScript conversion operations, same as used when assigning values to non-clamped typed array items, e.g. https://262.ecma-international.org/#sec-toint32 Returns error if conversion is not possible.

                                                                                  Example (Func)
                                                                                  Output:
                                                                                  
                                                                                  42
                                                                                  
                                                                                  Example (FuncThrow)
                                                                                  Output:
                                                                                  
                                                                                  Error: testing at f (<eval>:3:9(4))
                                                                                  
                                                                                  Example (FuncVariadic)
                                                                                  Output:
                                                                                  
                                                                                  a,b,42
                                                                                  

                                                                                  func (*Runtime) Get

                                                                                  func (r *Runtime) Get(name string) (ret Value)

                                                                                    Get the specified variable in the global context. Equivalent to dereferencing a variable by name in non-strict mode. If variable is not defined returns nil. Note, this is not the same as GlobalObject().Get(name), because if a global lexical binding (let or const) exists, it is used instead. This method will panic with an *Exception if a JavaScript exception is thrown in the process.

                                                                                    func (*Runtime) GlobalObject

                                                                                    func (r *Runtime) GlobalObject() *Object

                                                                                      GlobalObject returns the global object.

                                                                                      func (*Runtime) Interrupt

                                                                                      func (r *Runtime) Interrupt(v interface{})

                                                                                        Interrupt a running JavaScript. The corresponding Go call will return an *InterruptedError containing v. Note, it only works while in JavaScript code, it does not interrupt native Go functions (which includes all built-ins). If the runtime is currently not running, it will be immediately interrupted on the next Run*() call. To avoid that use ClearInterrupt()

                                                                                        func (*Runtime) New

                                                                                        func (r *Runtime) New(construct Value, args ...Value) (o *Object, err error)

                                                                                          New is an equivalent of the 'new' operator allowing to call it directly from Go.

                                                                                          func (*Runtime) NewArray

                                                                                          func (r *Runtime) NewArray(items ...interface{}) *Object
                                                                                          Example
                                                                                          Output:
                                                                                          
                                                                                          1 2 true
                                                                                          

                                                                                          func (*Runtime) NewArrayBuffer

                                                                                          func (r *Runtime) NewArrayBuffer(data []byte) ArrayBuffer

                                                                                          func (*Runtime) NewDynamicArray

                                                                                          func (r *Runtime) NewDynamicArray(a DynamicArray) *Object

                                                                                            NewDynamicArray creates an array Object backed by the provided DynamicArray handler. It is similar to NewDynamicObject, the differences are:

                                                                                            - the Object is an array (i.e. Array.isArray() will return true and it will have the length property).

                                                                                            - the prototype will be initially set to Array.prototype.

                                                                                            - the Object cannot have any own string properties except for the 'length'.

                                                                                            func (*Runtime) NewDynamicObject

                                                                                            func (r *Runtime) NewDynamicObject(d DynamicObject) *Object

                                                                                              NewDynamicObject creates an Object backed by the provided DynamicObject handler.

                                                                                              All properties of this Object are Writable, Enumerable and Configurable data properties. Any attempt to define a property that does not conform to this will fail.

                                                                                              The Object is always extensible and cannot be made non-extensible. Object.preventExtensions() will fail.

                                                                                              The Object's prototype is initially set to Object.prototype, but can be changed using regular mechanisms (Object.SetPrototype() in Go or Object.setPrototypeOf() in JS).

                                                                                              The Object cannot have own Symbol properties, however its prototype can. If you need an iterator support for example, you could create a regular object, set Symbol.iterator on that object and then use it as a prototype. See TestDynamicObjectCustomProto for more details.

                                                                                              Export() returns the original DynamicObject.

                                                                                              This mechanism is similar to ECMAScript Proxy, however because all properties are enumerable and the object is always extensible there is no need for invariant checks which removes the need to have a target object and makes it a lot more efficient.

                                                                                              func (*Runtime) NewGoError

                                                                                              func (r *Runtime) NewGoError(err error) *Object

                                                                                              func (*Runtime) NewObject

                                                                                              func (r *Runtime) NewObject() (v *Object)

                                                                                              func (*Runtime) NewProxy

                                                                                              func (r *Runtime) NewProxy(target *Object, nativeHandler *ProxyTrapConfig) Proxy

                                                                                              func (*Runtime) NewTypeError

                                                                                              func (r *Runtime) NewTypeError(args ...interface{}) *Object

                                                                                              func (*Runtime) RunProgram

                                                                                              func (r *Runtime) RunProgram(p *Program) (result Value, err error)

                                                                                                RunProgram executes a pre-compiled (see Compile()) code in the global context.

                                                                                                func (*Runtime) RunScript

                                                                                                func (r *Runtime) RunScript(name, src string) (Value, error)

                                                                                                  RunScript executes the given string in the global context.

                                                                                                  func (*Runtime) RunString

                                                                                                  func (r *Runtime) RunString(str string) (Value, error)

                                                                                                    RunString executes the given string in the global context.

                                                                                                    func (*Runtime) Set

                                                                                                    func (r *Runtime) Set(name string, value interface{}) error

                                                                                                      Set the specified variable in the global context. Equivalent to running "name = value" in non-strict mode. The value is first converted using ToValue(). Note, this is not the same as GlobalObject().Set(name, value), because if a global lexical binding (let or const) exists, it is set instead.

                                                                                                      Example (Lexical)
                                                                                                      Output:
                                                                                                      
                                                                                                      1 <nil>
                                                                                                      

                                                                                                      func (*Runtime) SetFieldNameMapper

                                                                                                      func (r *Runtime) SetFieldNameMapper(mapper FieldNameMapper)

                                                                                                        SetFieldNameMapper sets a custom field name mapper for Go types. It can be called at any time, however the mapping for any given value is fixed at the point of creation. Setting this to nil restores the default behaviour which is all exported fields and methods are mapped to their original unchanged names.

                                                                                                        func (*Runtime) SetMaxCallStackSize

                                                                                                        func (r *Runtime) SetMaxCallStackSize(size int)

                                                                                                          SetMaxCallStackSize sets the maximum function call depth. When exceeded, a *StackOverflowError is thrown and returned by RunProgram or by a Callable call. This is useful to prevent memory exhaustion caused by an infinite recursion. The default value is math.MaxInt32. This method (as the rest of the Set* methods) is not safe for concurrent use and may only be called from the vm goroutine or when the vm is not running.

                                                                                                          func (*Runtime) SetParserOptions

                                                                                                          func (r *Runtime) SetParserOptions(opts ...parser.Option)

                                                                                                            SetParserOptions sets parser options to be used by RunString, RunScript and eval() within the code.

                                                                                                            Example
                                                                                                            Output:
                                                                                                            
                                                                                                            I did not hang!
                                                                                                            

                                                                                                            func (*Runtime) SetRandSource

                                                                                                            func (r *Runtime) SetRandSource(source RandSource)

                                                                                                              SetRandSource sets random source for this Runtime. If not called, the default math/rand is used.

                                                                                                              func (*Runtime) SetTimeSource

                                                                                                              func (r *Runtime) SetTimeSource(now Now)

                                                                                                                SetTimeSource sets the current time source for this Runtime. If not called, the default time.Now() is used.

                                                                                                                func (*Runtime) ToValue

                                                                                                                func (r *Runtime) ToValue(i interface{}) Value

                                                                                                                ToValue converts a Go value into a JavaScript value of a most appropriate type. Structural types (such as structs, maps and slices) are wrapped so that changes are reflected on the original value which can be retrieved using Value.Export().

                                                                                                                WARNING! There are two very important caveats to bear in mind when modifying wrapped Go structs, maps and slices.

                                                                                                                1. If a slice is passed by value (not as a pointer), resizing the slice does not reflect on the original value. Moreover, extending the slice may result in the underlying array being re-allocated and copied. For example:

                                                                                                                a := []interface{}{1}
                                                                                                                vm.Set("a", a)
                                                                                                                vm.RunString(`a.push(2); a[0] = 0;`)
                                                                                                                fmt.Println(a[0]) // prints "1"
                                                                                                                

                                                                                                                2. If a regular JavaScript Object is assigned as an element of a wrapped Go struct, map or array, it is Export()'ed and therefore copied. This may result in an unexpected behaviour in JavaScript:

                                                                                                                m := map[string]interface{}{}
                                                                                                                vm.Set("m", m)
                                                                                                                vm.RunString(`
                                                                                                                var obj = {test: false};
                                                                                                                m.obj = obj; // obj gets Export()'ed, i.e. copied to a new map[string]interface{} and then this map is set as m["obj"]
                                                                                                                obj.test = true; // note, m.obj.test is still false
                                                                                                                `)
                                                                                                                fmt.Println(m["obj"].(map[string]interface{})["test"]) // prints "false"
                                                                                                                

                                                                                                                Notes on individual types:

                                                                                                                Primitive types

                                                                                                                Primitive types (numbers, string, bool) are converted to the corresponding JavaScript primitives.

                                                                                                                Strings

                                                                                                                Because of the difference in internal string representation between ECMAScript (which uses UTF-16) and Go (which uses UTF-8) conversion from JS to Go may be lossy. In particular, code points that can be part of UTF-16 surrogate pairs (0xD800-0xDFFF) cannot be represented in UTF-8 unless they form a valid surrogate pair and are replaced with utf8.RuneError.

                                                                                                                Nil

                                                                                                                Nil is converted to null.

                                                                                                                Functions

                                                                                                                func(FunctionCall) Value is treated as a native JavaScript function. This increases performance because there are no automatic argument and return value type conversions (which involves reflect). Attempting to use the function as a constructor will result in a TypeError.

                                                                                                                func(FunctionCall, *Runtime) Value is treated as above, except the *Runtime is also passed as a parameter.

                                                                                                                func(ConstructorCall) *Object is treated as a native constructor, allowing to use it with the new operator:

                                                                                                                func MyObject(call goja.ConstructorCall) *goja.Object {
                                                                                                                   // call.This contains the newly created object as per http://www.ecma-international.org/ecma-262/5.1/index.html#sec-13.2.2
                                                                                                                   // call.Arguments contain arguments passed to the function
                                                                                                                
                                                                                                                   call.This.Set("method", method)
                                                                                                                
                                                                                                                   //...
                                                                                                                
                                                                                                                   // If return value is a non-nil *Object, it will be used instead of call.This
                                                                                                                   // This way it is possible to return a Go struct or a map converted
                                                                                                                   // into goja.Value using ToValue(), however in this case
                                                                                                                   // instanceof will not work as expected.
                                                                                                                   return nil
                                                                                                                }
                                                                                                                
                                                                                                                runtime.Set("MyObject", MyObject)
                                                                                                                

                                                                                                                Then it can be used in JS as follows:

                                                                                                                var o = new MyObject(arg);
                                                                                                                var o1 = MyObject(arg); // same thing
                                                                                                                o instanceof MyObject && o1 instanceof MyObject; // true
                                                                                                                

                                                                                                                When a native constructor is called directly (without the new operator) its behavior depends on this value: if it's an Object, it is passed through, otherwise a new one is created exactly as if it was called with the new operator. In either case call.NewTarget will be nil.

                                                                                                                func(ConstructorCall, *Runtime) *Object is treated as above, except the *Runtime is also passed as a parameter.

                                                                                                                Any other Go function is wrapped so that the arguments are automatically converted into the required Go types and the return value is converted to a JavaScript value (using this method). If conversion is not possible, a TypeError is thrown.

                                                                                                                Functions with multiple return values return an Array. If the last return value is an `error` it is not returned but converted into a JS exception. If the error is *Exception, it is thrown as is, otherwise it's wrapped in a GoEerror. Note that if there are exactly two return values and the last is an `error`, the function returns the first value as is, not an Array.

                                                                                                                Structs

                                                                                                                Structs are converted to Object-like values. Fields and methods are available as properties, their values are results of this method (ToValue()) applied to the corresponding Go value.

                                                                                                                Field properties are writable (if the struct is addressable) and non-configurable. Method properties are non-writable and non-configurable.

                                                                                                                Attempt to define a new property or delete an existing property will fail (throw in strict mode) unless it's a Symbol property. Symbol properties only exist in the wrapper and do not affect the underlying Go value. Note that because a wrapper is created every time a property is accessed it may lead to unexpected results such as this:

                                                                                                                 type Field struct{
                                                                                                                 }
                                                                                                                 type S struct {
                                                                                                                	Field *Field
                                                                                                                 }
                                                                                                                 var s = S{
                                                                                                                	Field: &Field{},
                                                                                                                 }
                                                                                                                 vm := New()
                                                                                                                 vm.Set("s", &s)
                                                                                                                 res, err := vm.RunString(`
                                                                                                                 var sym = Symbol(66);
                                                                                                                 var field1 = s.Field;
                                                                                                                 field1[sym] = true;
                                                                                                                 var field2 = s.Field;
                                                                                                                 field1 === field2; // true, because the equality operation compares the wrapped values, not the wrappers
                                                                                                                 field1[sym] === true; // true
                                                                                                                 field2[sym] === undefined; // also true
                                                                                                                 `)
                                                                                                                

                                                                                                                The same applies to values from maps and slices as well.

                                                                                                                Handling of time.Time

                                                                                                                time.Time does not get special treatment and therefore is converted just like any other `struct` providing access to all its methods. This is done deliberately instead of converting it to a `Date` because these two types are not fully compatible: `time.Time` includes zone, whereas JS `Date` doesn't. Doing the conversion implicitly therefore would result in a loss of information.

                                                                                                                If you need to convert it to a `Date`, it can be done either in JS:

                                                                                                                var d = new Date(goval.UnixNano()/1e6);
                                                                                                                

                                                                                                                ... or in Go:

                                                                                                                 now := time.Now()
                                                                                                                 vm := New()
                                                                                                                 val, err := vm.New(vm.Get("Date").ToObject(vm), vm.ToValue(now.UnixNano()/1e6))
                                                                                                                 if err != nil {
                                                                                                                	...
                                                                                                                 }
                                                                                                                 vm.Set("d", val)
                                                                                                                

                                                                                                                Note that Value.Export() for a `Date` value returns time.Time in local timezone.

                                                                                                                Maps

                                                                                                                Maps with string or integer key type are converted into host objects that largely behave like a JavaScript Object.

                                                                                                                Maps with methods

                                                                                                                If a map type has at least one method defined, the properties of the resulting Object represent methods, not map keys. This is because in JavaScript there is no distinction between 'object.key` and `object[key]`, unlike Go. If access to the map values is required, it can be achieved by defining another method or, if it's not possible, by defining an external getter function.

                                                                                                                Slices

                                                                                                                Slices are converted into host objects that behave largely like JavaScript Array. It has the appropriate prototype and all the usual methods should work. There is, however, a caveat: converted Arrays may not contain holes (because Go slices cannot). This means that hasOwnProperty(n) always returns `true` if n < length. Deleting an item with an index < length will set it to a zero value (but the property will remain). Nil slice elements are be converted to `null`. Accessing an element beyond `length` returns `undefined`. Also see the warning above about passing slices as values (as opposed to pointers).

                                                                                                                Any other type is converted to a generic reflect based host object. Depending on the underlying type it behaves similar to a Number, String, Boolean or Object.

                                                                                                                Note that the underlying type is not lost, calling Export() returns the original Go value. This applies to all reflect based types.

                                                                                                                type StackFrame

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

                                                                                                                func (*StackFrame) FuncName

                                                                                                                func (f *StackFrame) FuncName() string

                                                                                                                func (*StackFrame) Position

                                                                                                                func (f *StackFrame) Position() file.Position

                                                                                                                func (*StackFrame) SrcName

                                                                                                                func (f *StackFrame) SrcName() string

                                                                                                                func (*StackFrame) Write

                                                                                                                func (f *StackFrame) Write(b *bytes.Buffer)

                                                                                                                type StackOverflowError

                                                                                                                type StackOverflowError struct {
                                                                                                                	Exception
                                                                                                                }

                                                                                                                type Symbol

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

                                                                                                                  *Symbol is a Value containing ECMAScript Symbol primitive. Symbols must only be created using NewSymbol(). Zero values and copying of values (i.e. *s1 = *s2) are not permitted. Well-known Symbols can be accessed using Sym* package variables (SymIterator, etc...) Symbols can be shared by multiple Runtimes.

                                                                                                                  func NewSymbol

                                                                                                                  func NewSymbol(s string) *Symbol
                                                                                                                  Example
                                                                                                                  Output:
                                                                                                                  
                                                                                                                  66 66 false
                                                                                                                  

                                                                                                                  func (*Symbol) Equals

                                                                                                                  func (s *Symbol) Equals(o Value) bool

                                                                                                                  func (*Symbol) Export

                                                                                                                  func (s *Symbol) Export() interface{}

                                                                                                                  func (*Symbol) ExportType

                                                                                                                  func (s *Symbol) ExportType() reflect.Type

                                                                                                                  func (*Symbol) SameAs

                                                                                                                  func (s *Symbol) SameAs(other Value) bool

                                                                                                                  func (*Symbol) StrictEquals

                                                                                                                  func (s *Symbol) StrictEquals(o Value) bool

                                                                                                                  func (*Symbol) String

                                                                                                                  func (s *Symbol) String() string

                                                                                                                  func (*Symbol) ToBoolean

                                                                                                                  func (s *Symbol) ToBoolean() bool

                                                                                                                  func (*Symbol) ToFloat

                                                                                                                  func (s *Symbol) ToFloat() float64

                                                                                                                  func (*Symbol) ToInteger

                                                                                                                  func (s *Symbol) ToInteger() int64

                                                                                                                  func (*Symbol) ToNumber

                                                                                                                  func (s *Symbol) ToNumber() Value

                                                                                                                  func (*Symbol) ToObject

                                                                                                                  func (s *Symbol) ToObject(r *Runtime) *Object

                                                                                                                  func (*Symbol) ToString

                                                                                                                  func (s *Symbol) ToString() Value

                                                                                                                  type Value

                                                                                                                  type Value interface {
                                                                                                                  	ToInteger() int64
                                                                                                                  
                                                                                                                  	ToString() Value
                                                                                                                  	String() string
                                                                                                                  	ToFloat() float64
                                                                                                                  	ToNumber() Value
                                                                                                                  	ToBoolean() bool
                                                                                                                  	ToObject(*Runtime) *Object
                                                                                                                  	SameAs(Value) bool
                                                                                                                  	Equals(Value) bool
                                                                                                                  	StrictEquals(Value) bool
                                                                                                                  	Export() interface{}
                                                                                                                  	ExportType() reflect.Type
                                                                                                                  	// contains filtered or unexported methods
                                                                                                                  }

                                                                                                                  func NaN

                                                                                                                  func NaN() Value

                                                                                                                    NaN returns a JS NaN value.

                                                                                                                    func NegativeInf

                                                                                                                    func NegativeInf() Value

                                                                                                                      NegativeInf returns a JS -Inf value.

                                                                                                                      func Null

                                                                                                                      func Null() Value

                                                                                                                        Null returns JS null value.

                                                                                                                        func PositiveInf

                                                                                                                        func PositiveInf() Value

                                                                                                                          PositiveInf returns a JS +Inf value.

                                                                                                                          func Undefined

                                                                                                                          func Undefined() Value

                                                                                                                            Undefined returns JS undefined value. Note if global 'undefined' property is changed this still returns the original value.

                                                                                                                            Directories

                                                                                                                            Path Synopsis
                                                                                                                            Package ast declares types representing a JavaScript AST.
                                                                                                                            Package ast declares types representing a JavaScript AST.
                                                                                                                            Package file encapsulates the file abstractions used by the ast & parser.
                                                                                                                            Package file encapsulates the file abstractions used by the ast & parser.
                                                                                                                            Package ftoa provides ECMAScript-compliant floating point number conversion to string.
                                                                                                                            Package ftoa provides ECMAScript-compliant floating point number conversion to string.
                                                                                                                            Package parser implements a parser for JavaScript.
                                                                                                                            Package parser implements a parser for JavaScript.
                                                                                                                            Package token defines constants representing the lexical tokens of JavaScript (ECMA5).
                                                                                                                            Package token defines constants representing the lexical tokens of JavaScript (ECMA5).
                                                                                                                            Package unistring contains an implementation of a hybrid ASCII/UTF-16 string.
                                                                                                                            Package unistring contains an implementation of a hybrid ASCII/UTF-16 string.