jscore

package module
v0.0.0-...-0b43f62 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: LGPL-2.1 Imports: 7 Imported by: 0

README

jscore

A Go wrapper around JavaScriptCore

Documentation

Overview

Jscore is a Go wrapper around JavaScriptCore. Cgo is used a lot throughout the code. It uses reflection to expose Go objects in JS code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckScriptSyntax

func CheckScriptSyntax(ctx Context, script string) bool

CheckScriptSyntax checks the syntax of the script.

Types

type Context

type Context interface {

	// GlobalObject returns the global object associated with the context.
	GlobalObject() Object
	// contains filtered or unexported methods
}

Context is a JS context.

type GlobalContext

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

GlobalContext is a global JS context.

func NewGlobalContext

func NewGlobalContext() GlobalContext

NewGlobalContext creates a new global JS context.

func (GlobalContext) GlobalObject

func (c GlobalContext) GlobalObject() Object

GlobalObject returns the global object associated with the context.

func (GlobalContext) Release

func (c GlobalContext) Release()

Release releases the context.

type Object

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

Object is a JS object.

func NewArray

func NewArray(ctx Context, values ...Value) Object

NewArray creates a JS array.

func NewGoObject

func NewGoObject(ctx Context, data interface{}) Object

NewGoObject creates a new JS object that wraps a Go object.

func NewObject

func NewObject(ctx Context) Object

NewObject creates a new JS object.

func (Object) At

func (o Object) At(ctx Context, index int) Value

At returns the property at the given index.

func (Object) Get

func (o Object) Get(ctx Context, propertyName string) Value

Get returns the property with the given name.

func (Object) Has

func (o Object) Has(ctx Context, propertyName string) bool

Has checks whether the object has a property with the given name.

func (Object) Set

func (o Object) Set(ctx Context, propertyName string, value Value)

Set sets the property with the given name.

func (Object) Slice

func (o Object) Slice(ctx Context) []interface{}

Array returns the JS object as a slice.

func (Object) Value

func (o Object) Value() Value

Value returns the object as a JS value.

type Type

type Type int

Type is a JS type.

const (
	Undefined Type = iota
	Null
	Boolean
	Number
	String
	JSObject
	Symbol
)

func (Type) String

func (t Type) String() string

String returns the textual representation of the type.

type Value

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

Value is a JS value.

func EvaluateScript

func EvaluateScript(ctx Context, script string) Value

EvaluateScript evaluates the provided script.

func NewBoolean

func NewBoolean(ctx Context, b bool) Value

NewBoolean creates a new JS boolean.

func NewNull

func NewNull(ctx Context) Value

NewNull creates a new null JS value.

func NewNumber

func NewNumber(ctx Context, x float64) Value

NewNumber creates a new JS number.

func NewString

func NewString(ctx Context, str string) Value

NewString creates a new JS string.

func NewSymbol

func NewSymbol(ctx Context, str string) Value

NewSymbol creates a new JS symbol.

func NewValue

func NewValue(ctx Context, v interface{}) Value

NewValue creates a new JS value.

func (Value) Boolean

func (v Value) Boolean(ctx Context) bool

Boolean returns the JS value as a boolean.

func (Value) Interface

func (v Value) Interface(ctx Context) interface{}

Interface returns the JS value as an interface{}. If the value is a wrapped Go object, then the wrapped object is returned. For other JS objects, a map of type map[string]interface{} is returned.

func (Value) Number

func (v Value) Number(ctx Context) float64

Number returns the JS value as a number.

func (Value) Object

func (v Value) Object(ctx Context) Object

Object returns the JS value as an object.

func (Value) Protect

func (v Value) Protect(ctx Context)

Protect protects the JS value from being garbage collected.

func (Value) String

func (v Value) String(ctx Context) string

String returns the textual representation of the JS value.

func (Value) Type

func (v Value) Type(ctx Context) Type

Type returns the type of the JS value.

func (Value) Unprotect

func (v Value) Unprotect(ctx Context)

Unprotect unprotects the JS value from being garbage collected.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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