quickjs

package module
v0.4.12 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 8 Imported by: 1

README

quickjs-go

English | 简体中文

Fork from https://github.com/buke/quickjs-go, fixed performance bug for function callback

Test codecov Go Report Card GoDoc FOSSA Status

Go bindings to QuickJS: a fast, small, and embeddable ES2020 JavaScript interpreter.

Platform Support

we prebuilt quickjs static library for the following platforms:

Platform Arch Static Library
Linux x64 libquickjs.a
Linux arm64 libquickjs.a
Windows x64 libquickjs.a
Windows x86 libquickjs.a
MacOS x64 libquickjs.a
MacOS arm64 libquickjs.a

* The windows static library is compiled based on mingw32 12.2.0. Please confirm go version > 1.20.0

Version Notes

quickjs-go QuickJS
v0.1.x v2021-03-27
v0.2.x v2023-12-09
v0.3.x v2024-01-13
v0.4.x v2024-02-14

Features

  • Evaluate script
  • Compile script into bytecode and Eval from bytecode
  • Operate JavaScript values and objects in Go
  • Bind Go function to JavaScript async/sync function
  • Simple exception throwing and catching

Guidelines

  1. Free quickjs.Runtime and quickjs.Context once you are done using them.
  2. Free quickjs.Value's returned by Eval() and EvalFile(). All other values do not need to be freed, as they get garbage-collected.
  3. Use ctx.Loop() wait for promise/job result after you using promise/job
  4. You may access the stacktrace of an error returned by Eval() or EvalFile() by casting it to a *quickjs.Error.
  5. Make new copies of arguments should you want to return them in functions you created.

Usage

import "apigo.cc/apigo/quickjs-go"
Run a script
package main

import (
	"fmt"
    
	"apigo.cc/apigo/quickjs-go"
)

func main() {
    // Create a new runtime
	rt := quickjs.NewRuntime(
		quickjs.WithExecuteTimeout(30),
		quickjs.WithMemoryLimit(128*1024),
		quickjs.WithGCThreshold(256*1024),
		quickjs.WithMaxStackSize(65534),
		quickjs.WithCanBlock(true),
	)
    defer rt.Close()

    // Create a new context
    ctx := rt.NewContext()
    defer ctx.Close()

    ret, err := ctx.Eval("'Hello ' + 'QuickJS!'")
    if err != nil {
        println(err.Error())
    }
    fmt.Println(ret.String())
}
Get/Set Javascript Object
package main

import (
	"fmt"
    
	"apigo.cc/apigo/quickjs-go"
)

func main() {
    // Create a new runtime
    rt := quickjs.NewRuntime()
    defer rt.Close()

    // Create a new context
    ctx := rt.NewContext()
    defer ctx.Close()

    test := ctx.Object()
    test.Set("A", ctx.String("String A"))
    test.Set("B", ctx.String("String B"))
    test.Set("C", ctx.String("String C"))
    ctx.Globals().Set("test", test)

    ret, _ := ctx.Eval(`Object.keys(test).map(key => test[key]).join(" ")`)
    defer ret.Free()
    fmt.Println(ret.String())
}

Bind Go Funtion to Javascript async/sync function
package main
import "apigo.cc/apigo/quickjs-go"

func main() {
    // Create a new runtime
	rt := quickjs.NewRuntime()
	defer rt.Close()

	// Create a new context
	ctx := rt.NewContext()
	defer ctx.Close()

	// Create a new object
	test := ctx.Object()
	defer test.Free()
	// bind properties to the object
	test.Set("A", test.Context().String("String A"))
	test.Set("B", ctx.Int32(0))
	test.Set("C", ctx.Bool(false))
	// bind go function to js object
	test.Set("hello", ctx.Function(func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {
		return ctx.String("Hello " + args[0].String())
	}))

	// bind "test" object to global object
	ctx.Globals().Set("test", test)

	// call js function by js
	js_ret, _ := ctx.Eval(`test.hello("Javascript!")`)
	fmt.Println(js_ret.String())

	// call js function by go
	go_ret := ctx.Globals().Get("test").Call("hello", ctx.String("Golang!"))
	fmt.Println(go_ret.String())

	//bind go function to Javascript async function
	ctx.Globals().Set("testAsync", ctx.AsyncFunction(func(ctx *quickjs.Context, this quickjs.Value, promise quickjs.Value, args []quickjs.Value) {
		promise.Call("resolve", ctx.String("Hello Async Function!"))
	}))

	ret, _ := ctx.Eval(`
			var ret;
			testAsync().then(v => ret = v)
		`)
	defer ret.Free()

	// wait for promise resolve
	ctx.Loop()

    //get promise result
	asyncRet, _ := ctx.Eval("ret")
	defer asyncRet.Free()

	fmt.Println(asyncRet.String())

	// Output:
	// Hello Javascript!
	// Hello Golang!
	// Hello Async Function!
}
Error Handling
package main

import (
	"fmt"
    
	"apigo.cc/apigo/quickjs-go"
)

func main() {
    // Create a new runtime
    rt := quickjs.NewRuntime()
    defer rt.Close()

    // Create a new context
    ctx := rt.NewContext()
    defer ctx.Close()

    ctx.Globals().SetFunction("A", func(ctx *Context, this Value, args []Value) Value {
        // raise error
        return ctx.ThrowError(expected)
    })

    _, actual := ctx.Eval("A()")
    fmt.Println(actual.Error())
}
Bytecode Compiler

package main

import (
	"fmt"
    
	"apigo.cc/apigo/quickjs-go"
)

func main() {
    // Create a new runtime
    rt := quickjs.NewRuntime()
    defer rt.Close()
    // Create a new context
    ctx := rt.NewContext()
    defer ctx.Close()

    jsStr := `
    function fib(n)
    {
        if (n <= 0)
            return 0;
        else if (n == 1)
            return 1;
        else
            return fib(n - 1) + fib(n - 2);
    }
    fib(10)
    `
    // Compile the script to bytecode
    buf, _ := ctx.Compile(jsStr)

    // Create a new runtime 
    rt2 := quickjs.NewRuntime()
    defer rt2.Close()

    // Create a new context
    ctx2 := rt2.NewContext()
    defer ctx2.Close()

    //Eval bytecode
    result, _ := ctx2.EvalBytecode(buf)
    fmt.Println(result.Int32())
}
Runtime Options: memory, stack, GC, ...
package main

import (
	"fmt"
    
	"apigo.cc/apigo/quickjs-go"
)

func main() {
    // Create a new runtime
    rt := quickjs.NewRuntime()
    defer rt.Close()

    // set runtime options
    rt.SetExecuteTimeout(30) // Set execute timeout to 30 seconds
    rt.SetMemoryLimit(256 * 1024) // Set memory limit to 256KB
    rt.SetMaxStackSize(65534) // Set max stack size to 65534
    rt.SetGCThreshold(256 * 1024) // Set GC threshold to 256KB
    rt.SetCanBlock(true) // Set can block to true

    // Create a new context
    ctx := rt.NewContext()
    defer ctx.Close()

    result, err := ctx.Eval(`var array = []; while (true) { array.push(null) }`)
    defer result.Free()
}
ES6 Module Support

package main

import (
	"fmt"
    
	"apigo.cc/apigo/quickjs-go"
)

func main() {
// enable module import
	rt := quickjs.NewRuntime(quickjs.WithModuleImport(true))
	defer rt.Close()

	ctx := rt.NewContext()
	defer ctx.Close()

	// eval module
	r1, err := ctx.EvalFile("./test/hello_module.js")
	defer r1.Free()
	require.NoError(t, err)
	require.EqualValues(t, 55, ctx.Globals().Get("result").Int32())

	// load module
	r2, err := ctx.LoadModuleFile("./test/fib_module.js", "fib_foo")
	defer r2.Free()
	require.NoError(t, err)

	// call module
	r3, err := ctx.Eval(`
	import {fib} from 'fib_foo';
	globalThis.result = fib(9);
	`)
	defer r3.Free()
	require.NoError(t, err)

	require.EqualValues(t, 34, ctx.Globals().Get("result").Int32())
}

Documentation

Go Reference & more examples: https://pkg.go.dev/apigo.cc/apigo/quickjs-go

License

MIT

FOSSA Status

Documentation

Overview

Package quickjs Go bindings to QuickJS: a fast, small, and embeddable ES2020 JavaScript interpreter

Example
// Create a new runtime
rt := quickjs.NewRuntime(
	quickjs.WithExecuteTimeout(30),
	quickjs.WithMemoryLimit(128*1024),
	quickjs.WithGCThreshold(256*1024),
	quickjs.WithMaxStackSize(65534),
	quickjs.WithCanBlock(true),
)
defer rt.Close()

// Create a new context
ctx := rt.NewContext()
defer ctx.Close()

// Create a new object
test := ctx.Object()
defer test.Free()
// bind properties to the object
test.Set("A", test.Context().String("String A"))
test.Set("B", ctx.Int32(0))
test.Set("C", ctx.Bool(false))
// bind go function to js object
test.Set("hello", ctx.Function(func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {
	return ctx.String("Hello " + args[0].String())
}))

// bind "test" object to global object
ctx.Globals().Set("test", test)

// call js function by js
js_ret, _ := ctx.Eval(`test.hello("Javascript!")`)
fmt.Println(js_ret.String())

// call js function by go
go_ret := ctx.Globals().Get("test").Call("hello", ctx.String("Golang!"))
fmt.Println(go_ret.String())

//bind go function to Javascript async function
ctx.Globals().Set("testAsync", ctx.AsyncFunction(func(ctx *quickjs.Context, this quickjs.Value, promise quickjs.Value, args []quickjs.Value) quickjs.Value {
	return promise.Call("resolve", ctx.String("Hello Async Function!"))
}))

ret, _ := ctx.Eval(`
			var ret;
			testAsync().then(v => ret = v)
		`)
defer ret.Free()

// wait for promise resolve
ctx.Loop()

asyncRet, _ := ctx.Eval("ret")
defer asyncRet.Free()

fmt.Println(asyncRet.String())
Output:

Hello Javascript!
Hello Golang!
Hello Async Function!

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

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

func NewQjsArray

func NewQjsArray(value Value, ctx *Context) *Array

func (Array) Delete

func (a Array) Delete(index int64) (bool, error)

func (Array) Free

func (a Array) Free()

func (Array) Get

func (a Array) Get(index int64) (Value, error)

Get

@Description: get the specific value by subscript
@receiver a :
@param index :
@return Value

func (Array) HasIdx

func (a Array) HasIdx(i int64) bool

HasIdx

@Description: Determine whether there is data at the current subscript position
@receiver a :
@param i :
@return bool

func (Array) Len

func (a Array) Len() int64

Len

@Description: get the length of the array
@receiver a :
@return int64

func (Array) Push

func (a Array) Push(elements ...Value) int64

Push

@Description: add one or more elements after the array,returns the new array length
@receiver a :
@param elements :
@return int64

func (Array) Set

func (a Array) Set(index int64, value Value) error

Set

@Description:
@receiver a :
@param index :
@param value :
@return error

func (Array) ToValue

func (a Array) ToValue() Value

ToValue

@Description: get the value object of qjs
@receiver a :
@return Value

type Atom

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

Object property names and some strings are stored as Atoms (unique strings) to save memory and allow fast comparison. Atoms are represented as a 32 bit integer. Half of the atom range is reserved for immediate integer literals from 0 to 2^{31}-1.

func (Atom) Free

func (a Atom) Free()

Free the value.

func (Atom) String

func (a Atom) String() string

String returns the string representation of the value.

func (Atom) Value

func (a Atom) Value() Value

Value returns the value of the Atom object.

type Context

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

Context represents a Javascript context (or Realm). Each JSContext has its own global objects and system objects. There can be several JSContexts per JSRuntime and they can share objects, similar to frames of the same origin sharing Javascript objects in a web browser.

func (*Context) Array

func (ctx *Context) Array() *Array

Array returns a new array value.

func (*Context) ArrayBuffer

func (ctx *Context) ArrayBuffer(binaryData []byte) Value

ArrayBuffer returns a string value with given binary data.

func (*Context) AsyncFunction

func (ctx *Context) AsyncFunction(asyncFn func(ctx *Context, this Value, promise Value, args []Value) Value) Value

AsyncFunction returns a js async function value with given function template.

func (*Context) Atom

func (ctx *Context) Atom(v string) Atom

Atom returns a new Atom value with given string.

func (*Context) AtomIdx

func (ctx *Context) AtomIdx(idx int64) Atom

Atom returns a new Atom value with given idx.

func (*Context) Await

func (ctx *Context) Await(v Value) (Value, error)

Wait for a promise and execute pending jobs while waiting for it. Return the promise result or JS_EXCEPTION in case of promise rejection.

func (*Context) BigInt64

func (ctx *Context) BigInt64(v int64) Value

BigInt64 returns a int64 value with given uint64.

func (*Context) BigUint64

func (ctx *Context) BigUint64(v uint64) Value

BigUint64 returns a uint64 value with given uint64.

func (*Context) Bool

func (ctx *Context) Bool(b bool) Value

Bool returns a bool value with given bool.

func (*Context) Close

func (ctx *Context) Close()

Free will free context and all associated objects.

func (*Context) Compile

func (ctx *Context) Compile(code string, opts ...EvalOption) ([]byte, error)

Compile returns a compiled bytecode with given code.

func (*Context) CompileFile

func (ctx *Context) CompileFile(filePath string, opts ...EvalOption) ([]byte, error)

Compile returns a compiled bytecode with given filename.

func (*Context) Error

func (ctx *Context) Error(err error) Value

Error returns a new exception value with given message.

func (*Context) Eval

func (ctx *Context) Eval(code string, opts ...EvalOption) (Value, error)

Eval returns a js value with given code. Need call Free() `quickjs.Value`'s returned by `Eval()` and `EvalFile()` and `EvalBytecode()`. func (ctx *Context) Eval(code string) (Value, error) { return ctx.EvalFile(code, "code") }

func (*Context) EvalBytecode

func (ctx *Context) EvalBytecode(buf []byte) (Value, error)

EvalBytecode returns a js value with given bytecode. Need call Free() `quickjs.Value`'s returned by `Eval()` and `EvalFile()` and `EvalBytecode()`.

func (*Context) EvalFile

func (ctx *Context) EvalFile(filePath string, opts ...EvalOption) (Value, error)

EvalFile returns a js value with given code and filename. Need call Free() `quickjs.Value`'s returned by `Eval()` and `EvalFile()` and `EvalBytecode()`.

func (*Context) Exception

func (ctx *Context) Exception() error

Exception returns a context's exception value.

func (*Context) Float64

func (ctx *Context) Float64(v float64) Value

Float64 returns a float64 value with given float64.

func (*Context) Function

func (ctx *Context) Function(fn func(ctx *Context, this Value, args []Value) Value) Value

Function returns a js function value with given function template.

func (*Context) Globals

func (ctx *Context) Globals() Value

Global returns a context's global object.

func (*Context) Int32

func (ctx *Context) Int32(v int32) Value

Int32 returns a int32 value with given int32.

func (*Context) Int64

func (ctx *Context) Int64(v int64) Value

Int64 returns a int64 value with given int64.

func (*Context) Invoke

func (ctx *Context) Invoke(fn Value, this Value, args ...Value) Value

Invoke invokes a function with given this value and arguments.

func (*Context) LoadModule

func (ctx *Context) LoadModule(code string, moduleName string) (Value, error)

LoadModule returns a js value with given code and module name.

func (*Context) LoadModuleBytecode

func (ctx *Context) LoadModuleBytecode(buf []byte, moduleName string) (Value, error)

LoadModuleByteCode returns a js value with given bytecode and module name.

func (*Context) LoadModuleFile

func (ctx *Context) LoadModuleFile(filePath string, moduleName string) (Value, error)

LoadModuleFile returns a js value with given file path and module name.

func (*Context) Loop

func (ctx *Context) Loop()

Loop runs the context's event loop.

func (*Context) Map

func (ctx *Context) Map() *Map

func (*Context) Null

func (ctx *Context) Null() Value

Null return a null value.

func (*Context) Object

func (ctx *Context) Object() Value

Object returns a new object value.

func (*Context) ParseJSON

func (ctx *Context) ParseJSON(v string) Value

ParseJson parses given json string and returns a object value.

func (*Context) Runtime

func (ctx *Context) Runtime() *Runtime

Runtime returns the runtime of the context.

func (*Context) Set

func (ctx *Context) Set() *Set

func (*Context) SetInterruptHandler

func (ctx *Context) SetInterruptHandler(handler InterruptHandler)

SetInterruptHandler sets a interrupt handler.

func (*Context) String

func (ctx *Context) String(v string) Value

String returns a string value with given string.

func (*Context) Throw

func (ctx *Context) Throw(v Value) Value

Throw returns a context's exception value.

func (*Context) ThrowError

func (ctx *Context) ThrowError(err error) Value

ThrowError returns a context's exception value with given error message.

func (*Context) ThrowInternalError

func (ctx *Context) ThrowInternalError(format string, args ...interface{}) Value

ThrowInternalError returns a context's exception value with given error message.

func (*Context) ThrowRangeError

func (ctx *Context) ThrowRangeError(format string, args ...interface{}) Value

ThrowRangeError returns a context's exception value with given error message.

func (*Context) ThrowReferenceError

func (ctx *Context) ThrowReferenceError(format string, args ...interface{}) Value

ThrowReferenceError returns a context's exception value with given error message.

func (*Context) ThrowSyntaxError

func (ctx *Context) ThrowSyntaxError(format string, args ...interface{}) Value

ThrowSyntaxError returns a context's exception value with given error message.

func (*Context) ThrowTypeError

func (ctx *Context) ThrowTypeError(format string, args ...interface{}) Value

ThrowTypeError returns a context's exception value with given error message.

func (*Context) Uint32

func (ctx *Context) Uint32(v uint32) Value

Uint32 returns a uint32 value with given uint32.

func (*Context) Undefined

func (ctx *Context) Undefined() Value

Undefined return a undefined value.

func (*Context) Uninitialized

func (ctx *Context) Uninitialized() Value

Uninitialized returns a uninitialized value.

type Error

type Error struct {
	Cause string
	Stack string
}

func (Error) Error

func (err Error) Error() string

type EvalOption

type EvalOption func(*EvalOptions)

func EvalAwait

func EvalAwait(await bool) EvalOption

func EvalFileName

func EvalFileName(filename string) EvalOption

func EvalFlagCompileOnly

func EvalFlagCompileOnly(compileOnly bool) EvalOption

func EvalFlagGlobal

func EvalFlagGlobal(global bool) EvalOption

func EvalFlagModule

func EvalFlagModule(module bool) EvalOption

func EvalFlagStrict

func EvalFlagStrict(strict bool) EvalOption

func EvalFlagStrip

func EvalFlagStrip(strip bool) EvalOption

type EvalOptions

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

type InterruptHandler

type InterruptHandler func() int

InterruptHandler is a function type for interrupt handler.

return != 0 if the JS code needs to be interrupted

type Map

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

func NewQjsMap

func NewQjsMap(value Value, ctx *Context) *Map

func (Map) Call

func (m Map) Call(funcName string, values []Value) Value

Call

@Description: call some internal methods of js
@receiver a :
@param funcName :
@param values :
@return Value

func (Map) Delete

func (m Map) Delete(key Value)

Delete

@Description:delete the value of an element by key
@receiver m :
@param key :

func (Map) ForEach

func (m Map) ForEach(forFn func(key Value, value Value))

ForEach

@Description: iterate map
@receiver m :

func (Map) Free

func (m Map) Free()

func (Map) Get

func (m Map) Get(key Value) Value

Get

@Description: get the value by key
@receiver m :
@param key :
@return Value

func (Map) Has

func (m Map) Has(key Value) bool

Has

@Description:determine whether an element exists
@receiver m :
@param key :

func (Map) Put

func (m Map) Put(key Value, value Value)

Put

@Description:
@receiver m :
@param key :
@param value :

func (Map) ToValue

func (m Map) ToValue() Value

type Option

type Option func(*Options)

func WithCanBlock

func WithCanBlock(canBlock bool) Option

WithCanBlock will set the runtime's can block; default is true

func WithExecuteTimeout

func WithExecuteTimeout(timeout uint64) Option

WithExecuteTimeout will set the runtime's execute timeout; default is 0

func WithGCThreshold

func WithGCThreshold(gcThreshold uint64) Option

WithGCThreshold will set the runtime's GC threshold; use -1 to disable automatic GC.

func WithMaxStackSize

func WithMaxStackSize(maxStackSize uint64) Option

WithMaxStackSize will set max runtime's stack size; default is 255

func WithMemoryLimit

func WithMemoryLimit(memoryLimit uint64) Option

WithMemoryLimit will set the runtime memory limit; if not set, it will be unlimit.

func WithModuleImport

func WithModuleImport(moduleImport bool) Option

type Options

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

type Runtime

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

Runtime represents a Javascript runtime corresponding to an object heap. Several runtimes can exist at the same time but they cannot exchange objects. Inside a given runtime, no multi-threading is supported.

func NewRuntime

func NewRuntime(opts ...Option) Runtime

NewRuntime creates a new quickjs runtime.

func (Runtime) Close

func (r Runtime) Close()

Close will free the runtime pointer.

func (Runtime) NewContext

func (r Runtime) NewContext() *Context

NewContext creates a new JavaScript context. enable BigFloat/BigDecimal support and enable . enable operator overloading.

func (Runtime) RunGC

func (r Runtime) RunGC()

RunGC will call quickjs's garbage collector.

func (Runtime) SetCanBlock

func (r Runtime) SetCanBlock(canBlock bool)

SetCanBlock will set the runtime's can block; default is true

func (Runtime) SetExecuteTimeout

func (r Runtime) SetExecuteTimeout(timeout uint64)

SetExecuteTimeout will set the runtime's execute timeout; default is 0

func (Runtime) SetGCThreshold

func (r Runtime) SetGCThreshold(threshold uint64)

SetGCThreshold the runtime's GC threshold; use -1 to disable automatic GC.

func (Runtime) SetMaxStackSize

func (r Runtime) SetMaxStackSize(stack_size uint64)

SetMaxStackSize will set max runtime's stack size; default is 255

func (Runtime) SetMemoryLimit

func (r Runtime) SetMemoryLimit(limit uint64)

SetMemoryLimit the runtime memory limit; if not set, it will be unlimit.

type Set

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

func NewQjsSet

func NewQjsSet(value Value, ctx *Context) *Set

func (Set) Add

func (s Set) Add(value Value)

Add

@Description: add element
@receiver s :
@param value :

func (Set) Delete

func (s Set) Delete(value Value)

Delete

@Description: add element
@receiver s :
@param value :

func (Set) ForEach

func (s Set) ForEach(forFn func(value Value))

ForEach

@Description: iterate set
@receiver m :

func (Set) Free

func (s Set) Free()

func (Set) Has

func (s Set) Has(value Value) bool

Has

@Description: determine whether an element exists in the set
@receiver s :
@param value :
@return bool

func (Set) ToValue

func (s Set) ToValue() Value

type Value

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

JSValue represents a Javascript value which can be a primitive type or an object. Reference counting is used, so it is important to explicitly duplicate (JS_DupValue(), increment the reference count) or free (JS_FreeValue(), decrement the reference count) JSValues.

func (Value) BigFloat

func (v Value) BigFloat() *big.Float

BigFloat returns the big.Float value of the value.

func (Value) BigInt

func (v Value) BigInt() *big.Int

BigInt returns the big.Int value of the value.

func (Value) Bool

func (v Value) Bool() bool

Bool returns the boolean value of the value.

func (Value) ByteLen

func (v Value) ByteLen() int64

ByteLen returns the length of the ArrayBuffer.

func (Value) Call

func (v Value) Call(fname string, args ...Value) Value

Call calls the function with the given arguments.

func (Value) Context

func (v Value) Context() *Context

Context represents a Javascript context.

func (Value) Delete

func (v Value) Delete(name string) bool

Delete deletes the property with the given name.

func (Value) DeleteIdx

func (v Value) DeleteIdx(idx int64) bool

DeleteIdx deletes the property with the given index.

func (Value) Error

func (v Value) Error() error

Error returns the error value of the value.

func (Value) Float64

func (v Value) Float64() float64

Float64 returns the float64 value of the value.

func (Value) Free

func (v Value) Free()

Free the value.

func (Value) Get

func (v Value) Get(name string) Value

Get returns the value of the property with the given name.

func (Value) GetIdx

func (v Value) GetIdx(idx int64) Value

GetIdx returns the value of the property with the given index.

func (Value) Has

func (v Value) Has(name string) bool

Has returns true if the value has the property with the given name.

func (Value) HasIdx

func (v Value) HasIdx(idx int64) bool

HasIdx returns true if the value has the property with the given index.

func (Value) Int32

func (v Value) Int32() int32

Int32 returns the int32 value of the value.

func (Value) Int64

func (v Value) Int64() int64

Int64 returns the int64 value of the value.

func (Value) IsArray

func (v Value) IsArray() bool

func (Value) IsBigDecimal

func (v Value) IsBigDecimal() bool

func (Value) IsBigFloat

func (v Value) IsBigFloat() bool

func (Value) IsBigInt

func (v Value) IsBigInt() bool

func (Value) IsBool

func (v Value) IsBool() bool

func (Value) IsByteArray

func (v Value) IsByteArray() bool

IsByteArray return true if the value is array buffer

func (Value) IsError

func (v Value) IsError() bool

func (Value) IsException

func (v Value) IsException() bool

func (Value) IsFunction

func (v Value) IsFunction() bool

func (Value) IsMap

func (v Value) IsMap() bool

IsMap return true if the value is a map

func (Value) IsNull

func (v Value) IsNull() bool

func (Value) IsNumber

func (v Value) IsNumber() bool

func (Value) IsObject

func (v Value) IsObject() bool

func (Value) IsPromise

func (v Value) IsPromise() bool

func (Value) IsSet

func (v Value) IsSet() bool

IsSet return true if the value is a set

func (Value) IsString

func (v Value) IsString() bool

func (Value) IsSymbol

func (v Value) IsSymbol() bool

func (Value) IsUndefined

func (v Value) IsUndefined() bool

func (Value) IsUninitialized

func (v Value) IsUninitialized() bool

func (Value) JSONStringify

func (v Value) JSONStringify() string

JSONString returns the JSON string representation of the value.

func (Value) Len

func (v Value) Len() int64

Len returns the length of the array.

func (Value) PropertyNames

func (v Value) PropertyNames() ([]string, error)

PropertyNames returns the names of the properties of the value.

func (Value) Set

func (v Value) Set(name string, val Value)

Set sets the value of the property with the given name.

func (Value) SetIdx

func (v Value) SetIdx(idx int64, val Value)

SetIdx sets the value of the property with the given index.

func (Value) String

func (v Value) String() string

String returns the string representation of the value.

func (Value) ToArray

func (v Value) ToArray() *Array

ToArray

@Description: return array object
@receiver v :
@return *Array

func (Value) ToByteArray

func (v Value) ToByteArray(size uint) ([]byte, error)

func (Value) ToMap

func (v Value) ToMap() *Map

ToMap

@Description: return map object
@receiver v :
@return *Map

func (Value) ToSet

func (v Value) ToSet() *Set

ToSet

@Description: return set object
@receiver v :
@return *Set

func (Value) Uint32

func (v Value) Uint32() uint32

Uint32 returns the uint32 value of the value.

Jump to

Keyboard shortcuts

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