Documentation ¶
Index ¶
- Constants
- func AppendJSON(dst []byte, value *Value) []byte
- func GetVersion() string
- func SetArrayBufferAllocator(ac ArrayBufferAllocateCallback, fc ArrayBufferFreeCallback)
- func SetCaptureStackTraceForUncaughtExceptions(capture bool, frameLimit int)
- func SetFlagsFromString(cmd string)
- func ToJSON(value *Value) []byte
- type AccessControl
- type AccessorCallbackInfo
- type AccessorGetterCallback
- type AccessorSetterCallback
- type Array
- type ArrayBufferAllocateCallback
- type ArrayBufferAllocator
- type ArrayBufferFreeCallback
- type Context
- type ContextScope
- func (cs ContextScope) AddMessageListener(simple bool, callback MessageCallback, data interface{})
- func (cs ContextScope) Eval(code string) *Value
- func (cs ContextScope) GetEngine() *Engine
- func (cs ContextScope) GetPrivateData() interface{}
- func (cs ContextScope) Global() *Object
- func (cs ContextScope) NewArray(length int) *Array
- func (cs ContextScope) NewBoolean(value bool) *Value
- func (cs ContextScope) NewInteger(value int64) *Value
- func (cs ContextScope) NewNumber(value float64) *Value
- func (cs *ContextScope) NewObject() *Value
- func (cs ContextScope) NewRegExp(pattern string, flags RegExpFlags) *Value
- func (cs ContextScope) NewString(value string) *Value
- func (cs ContextScope) ParseJSON(json string) *Value
- func (cs ContextScope) SetPrivateData(data interface{})
- func (cs ContextScope) ThrowException(err string)
- func (cs ContextScope) TryCatch(simple bool, callback func()) string
- type Engine
- func (e *Engine) Compile(code []byte, origin *ScriptOrigin, data *ScriptData) *Script
- func (e *Engine) False() *Value
- func (this Engine) GetPrivateData() interface{}
- func (e *Engine) NewContext(globalTemplate *ObjectTemplate) *Context
- func (e *Engine) NewFunctionTemplate(callback FunctionCallback, data interface{}) *FunctionTemplate
- func (e *Engine) NewObjectTemplate() *ObjectTemplate
- func (e *Engine) NewScriptOrigin(name string, lineOffset, columnOffset int) *ScriptOrigin
- func (e *Engine) Null() *Value
- func (e *Engine) PreCompile(code []byte) *ScriptData
- func (this *Engine) SetPrivateData(data interface{})
- func (e *Engine) True() *Value
- func (e *Engine) Undefined() *Value
- type Function
- type FunctionCallback
- type FunctionCallbackInfo
- func (fc FunctionCallbackInfo) Callee() *Function
- func (fc FunctionCallbackInfo) CurrentScope() ContextScope
- func (fc FunctionCallbackInfo) Data() interface{}
- func (fc FunctionCallbackInfo) Get(i int) *Value
- func (fc FunctionCallbackInfo) Holder() *Object
- func (fc FunctionCallbackInfo) Length() int
- func (fc *FunctionCallbackInfo) ReturnValue() ReturnValue
- func (fc FunctionCallbackInfo) This() *Object
- type FunctionTemplate
- type IndexedPropertyDeleterCallback
- type IndexedPropertyEnumeratorCallback
- type IndexedPropertyGetterCallback
- type IndexedPropertyQueryCallback
- type IndexedPropertySetterCallback
- type MessageCallback
- type NamedPropertyDeleterCallback
- type NamedPropertyEnumeratorCallback
- type NamedPropertyGetterCallback
- type NamedPropertyQueryCallback
- type NamedPropertySetterCallback
- type Object
- func (o *Object) DeleteElement(index int) bool
- func (o *Object) DeleteProperty(key string) bool
- func (o *Object) ForceDeleteProperty(key string) bool
- func (o *Object) ForceSetProperty(key string, value *Value, attribs PropertyAttribute) bool
- func (o *Object) GetElement(index int) *Value
- func (o *Object) GetInternalField(index int) interface{}
- func (o *Object) GetOwnPropertyNames() *Array
- func (o *Object) GetProperty(key string) *Value
- func (o *Object) GetPropertyAttributes(key string) PropertyAttribute
- func (o *Object) GetPropertyNames() *Array
- func (o *Object) GetPrototype() *Object
- func (o *Object) HasElement(index int) bool
- func (o *Object) HasProperty(key string) bool
- func (o *Object) InternalFieldCount() int
- func (o *Object) SetElement(index int, value *Value) bool
- func (o *Object) SetInternalField(index int, value interface{})
- func (o *Object) SetProperty(key string, value *Value, attribs PropertyAttribute) bool
- func (o *Object) SetPrototype(proto *Object) bool
- type ObjectTemplate
- func (ot *ObjectTemplate) Dispose()
- func (ot *ObjectTemplate) InternalFieldCount() int
- func (ot *ObjectTemplate) NewObject() *Value
- func (ot *ObjectTemplate) SetAccessor(key string, getter AccessorGetterCallback, setter AccessorSetterCallback, ...)
- func (ot *ObjectTemplate) SetIndexedPropertyHandler(getter IndexedPropertyGetterCallback, setter IndexedPropertySetterCallback, ...)
- func (ot *ObjectTemplate) SetInternalFieldCount(count int)
- func (ot *ObjectTemplate) SetNamedPropertyHandler(getter NamedPropertyGetterCallback, setter NamedPropertySetterCallback, ...)
- func (ot *ObjectTemplate) SetProperty(key string, value *Value, attribs PropertyAttribute)
- func (ot *ObjectTemplate) WrapObject(value *Value)
- type PropertyAttribute
- type PropertyCallbackInfo
- type RegExp
- type RegExpFlags
- type ReturnValue
- func (rv ReturnValue) Set(value *Value)
- func (rv ReturnValue) SetBoolean(value bool)
- func (rv ReturnValue) SetInt32(value int32)
- func (rv ReturnValue) SetNull()
- func (rv ReturnValue) SetNumber(value float64)
- func (rv ReturnValue) SetString(value string)
- func (rv ReturnValue) SetUint32(value uint32)
- func (rv ReturnValue) SetUndefined()
- type Script
- type ScriptData
- type ScriptOrigin
- type Value
- func (v *Value) IsArray() bool
- func (v *Value) IsBoolean() bool
- func (v *Value) IsBooleanObject() bool
- func (v *Value) IsDate() bool
- func (v *Value) IsExternal() bool
- func (v *Value) IsFalse() bool
- func (v *Value) IsFunction() bool
- func (v *Value) IsInt32() bool
- func (v *Value) IsNativeError() bool
- func (v *Value) IsNull() bool
- func (v *Value) IsNumber() bool
- func (v *Value) IsNumberObject() bool
- func (v *Value) IsObject() bool
- func (v *Value) IsRegExp() bool
- func (v *Value) IsString() bool
- func (v *Value) IsStringObject() bool
- func (v *Value) IsTrue() bool
- func (v *Value) IsUint32() bool
- func (v *Value) IsUndefined() bool
- func (v *Value) ToArray() *Array
- func (v *Value) ToBoolean() bool
- func (v *Value) ToFunction() *Function
- func (v *Value) ToInt32() int32
- func (v *Value) ToInteger() int64
- func (v *Value) ToNumber() float64
- func (v *Value) ToObject() *Object
- func (v *Value) ToRegExp() *RegExp
- func (v *Value) ToString() string
- func (v *Value) ToUint32() uint32
Constants ¶
const ( PA_None PropertyAttribute = 0 PA_ReadOnly = 1 << 0 PA_DontEnum = 1 << 1 PA_DontDelete = 1 << 2 )
const ( RF_None RegExpFlags = 0 RF_Global = 1 RF_IgnoreCase = 2 RF_Multiline = 4 )
Regular expression flag bits. They can be or'ed to enable a set of flags.
const ( AC_DEFAULT AccessControl = 0 AC_ALL_CAN_READ = 1 AC_ALL_CAN_WRITE = 1 << 1 AC_PROHIBITS_OVERWRITING = 1 << 2 )
Access control specifications.
Some accessors should be accessible across contexts. These accessors have an explicit access control parameter which specifies the kind of cross-context access that should be allowed.
Additionally, for security, accessors can prohibit overwriting by accessors defined in JavaScript. For objects that have such accessors either locally or in their prototype chain it is not possible to overwrite the accessor by using __defineGetter__ or __defineSetter__ from JavaScript code.
Variables ¶
This section is empty.
Functions ¶
func AppendJSON ¶
func GetVersion ¶
func GetVersion() string
func SetArrayBufferAllocator ¶
func SetArrayBufferAllocator( ac ArrayBufferAllocateCallback, fc ArrayBufferFreeCallback)
Call SetArrayBufferAllocator first if you want use any of ArrayBuffer, ArrayBufferView, Int8Array... Please be sure to call this function once and keep allocator Please set ac and fc to nil if you don't want a custom one
func SetFlagsFromString ¶
func SetFlagsFromString(cmd string)
Types ¶
type AccessControl ¶
type AccessControl int
type AccessorCallbackInfo ¶
type AccessorCallbackInfo struct {
// contains filtered or unexported fields
}
Property getter callback info
func (AccessorCallbackInfo) CurrentScope ¶
func (ac AccessorCallbackInfo) CurrentScope() ContextScope
func (AccessorCallbackInfo) Data ¶
func (ac AccessorCallbackInfo) Data() interface{}
func (AccessorCallbackInfo) Holder ¶
func (ac AccessorCallbackInfo) Holder() *Object
func (*AccessorCallbackInfo) ReturnValue ¶
func (ac *AccessorCallbackInfo) ReturnValue() ReturnValue
func (AccessorCallbackInfo) This ¶
func (ac AccessorCallbackInfo) This() *Object
type AccessorGetterCallback ¶
type AccessorGetterCallback func(name string, info AccessorCallbackInfo)
type AccessorSetterCallback ¶
type AccessorSetterCallback func(name string, value *Value, info AccessorCallbackInfo)
type Array ¶
type Array struct {
*Object
}
An instance of the built-in array constructor (ECMA-262, 15.4.2).
type ArrayBufferAllocator ¶
type ArrayBufferAllocator struct {
// contains filtered or unexported fields
}
type ArrayBufferFreeCallback ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
A sandboxed execution context with its own set of built-in objects and functions.
func (Context) GetPrivateData ¶
func (this Context) GetPrivateData() interface{}
func (*Context) Scope ¶
func (c *Context) Scope(callback func(ContextScope))
func (*Context) SetPrivateData ¶
func (this *Context) SetPrivateData(data interface{})
type ContextScope ¶
type ContextScope struct {
// contains filtered or unexported fields
}
func (ContextScope) AddMessageListener ¶
func (cs ContextScope) AddMessageListener(simple bool, callback MessageCallback, data interface{})
func (ContextScope) Eval ¶
func (cs ContextScope) Eval(code string) *Value
func (ContextScope) GetEngine ¶
func (cs ContextScope) GetEngine() *Engine
func (ContextScope) GetPrivateData ¶
func (cs ContextScope) GetPrivateData() interface{}
func (ContextScope) Global ¶
func (cs ContextScope) Global() *Object
func (ContextScope) NewArray ¶
func (cs ContextScope) NewArray(length int) *Array
func (ContextScope) NewBoolean ¶
func (cs ContextScope) NewBoolean(value bool) *Value
func (ContextScope) NewInteger ¶
func (cs ContextScope) NewInteger(value int64) *Value
func (ContextScope) NewNumber ¶
func (cs ContextScope) NewNumber(value float64) *Value
func (*ContextScope) NewObject ¶
func (cs *ContextScope) NewObject() *Value
func (ContextScope) NewRegExp ¶
func (cs ContextScope) NewRegExp(pattern string, flags RegExpFlags) *Value
Creates a regular expression from the given pattern string and the flags bit field. May throw a JavaScript exception as described in ECMA-262, 15.10.4.1.
For example,
NewRegExp("foo", RF_Global | RF_Multiline)
is equivalent to evaluating "/foo/gm".
func (ContextScope) NewString ¶
func (cs ContextScope) NewString(value string) *Value
func (ContextScope) ParseJSON ¶
func (cs ContextScope) ParseJSON(json string) *Value
func (ContextScope) SetPrivateData ¶
func (cs ContextScope) SetPrivateData(data interface{})
func (ContextScope) ThrowException ¶
func (cs ContextScope) ThrowException(err string)
func (ContextScope) TryCatch ¶
func (cs ContextScope) TryCatch(simple bool, callback func()) string
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Represents an isolated instance of the V8 engine. Objects from one engine must not be used in other engine.
func (*Engine) Compile ¶
func (e *Engine) Compile(code []byte, origin *ScriptOrigin, data *ScriptData) *Script
Compiles the specified script (context-independent). 'data' is the Pre-parsing data, as obtained by PreCompile() using pre_data speeds compilation if it's done multiple times.
func (Engine) GetPrivateData ¶
func (this Engine) GetPrivateData() interface{}
func (*Engine) NewContext ¶
func (e *Engine) NewContext(globalTemplate *ObjectTemplate) *Context
func (*Engine) NewFunctionTemplate ¶
func (e *Engine) NewFunctionTemplate(callback FunctionCallback, data interface{}) *FunctionTemplate
func (*Engine) NewObjectTemplate ¶
func (e *Engine) NewObjectTemplate() *ObjectTemplate
func (*Engine) NewScriptOrigin ¶
func (e *Engine) NewScriptOrigin(name string, lineOffset, columnOffset int) *ScriptOrigin
func (*Engine) PreCompile ¶
func (e *Engine) PreCompile(code []byte) *ScriptData
Pre-compiles the specified script (context-independent).
func (*Engine) SetPrivateData ¶
func (this *Engine) SetPrivateData(data interface{})
type FunctionCallback ¶
type FunctionCallback func(FunctionCallbackInfo)
type FunctionCallbackInfo ¶
type FunctionCallbackInfo struct {
// contains filtered or unexported fields
}
Function callback info
func (FunctionCallbackInfo) Callee ¶
func (fc FunctionCallbackInfo) Callee() *Function
func (FunctionCallbackInfo) CurrentScope ¶
func (fc FunctionCallbackInfo) CurrentScope() ContextScope
func (FunctionCallbackInfo) Data ¶
func (fc FunctionCallbackInfo) Data() interface{}
func (FunctionCallbackInfo) Get ¶
func (fc FunctionCallbackInfo) Get(i int) *Value
func (FunctionCallbackInfo) Holder ¶
func (fc FunctionCallbackInfo) Holder() *Object
func (FunctionCallbackInfo) Length ¶
func (fc FunctionCallbackInfo) Length() int
func (*FunctionCallbackInfo) ReturnValue ¶
func (fc *FunctionCallbackInfo) ReturnValue() ReturnValue
func (FunctionCallbackInfo) This ¶
func (fc FunctionCallbackInfo) This() *Object
type FunctionTemplate ¶
func (*FunctionTemplate) Dispose ¶
func (ft *FunctionTemplate) Dispose()
func (*FunctionTemplate) InstanceTemplate ¶
func (ft *FunctionTemplate) InstanceTemplate() *ObjectTemplate
func (*FunctionTemplate) NewFunction ¶
func (ft *FunctionTemplate) NewFunction() *Value
func (*FunctionTemplate) SetClassName ¶
func (ft *FunctionTemplate) SetClassName(name string)
type IndexedPropertyDeleterCallback ¶
type IndexedPropertyDeleterCallback func(uint32, PropertyCallbackInfo)
type IndexedPropertyEnumeratorCallback ¶
type IndexedPropertyEnumeratorCallback func(PropertyCallbackInfo)
type IndexedPropertyGetterCallback ¶
type IndexedPropertyGetterCallback func(uint32, PropertyCallbackInfo)
type IndexedPropertyQueryCallback ¶
type IndexedPropertyQueryCallback func(uint32, PropertyCallbackInfo)
type IndexedPropertySetterCallback ¶
type IndexedPropertySetterCallback func(uint32, *Value, PropertyCallbackInfo)
type MessageCallback ¶
type MessageCallback func(message string, data interface{})
type NamedPropertyDeleterCallback ¶
type NamedPropertyDeleterCallback func(string, PropertyCallbackInfo)
type NamedPropertyEnumeratorCallback ¶
type NamedPropertyEnumeratorCallback func(PropertyCallbackInfo)
type NamedPropertyGetterCallback ¶
type NamedPropertyGetterCallback func(string, PropertyCallbackInfo)
type NamedPropertyQueryCallback ¶
type NamedPropertyQueryCallback func(string, PropertyCallbackInfo)
type NamedPropertySetterCallback ¶
type NamedPropertySetterCallback func(string, *Value, PropertyCallbackInfo)
type Object ¶
type Object struct {
*Value
}
A JavaScript object (ECMA-262, 4.3.3)
func (*Object) DeleteElement ¶
func (*Object) DeleteProperty ¶
func (*Object) ForceDeleteProperty ¶
Delete a property on this object bypassing interceptors and ignoring dont-delete attributes.
func (*Object) ForceSetProperty ¶
func (o *Object) ForceSetProperty(key string, value *Value, attribs PropertyAttribute) bool
Sets a local property on this object bypassing interceptors and overriding accessors or read-only properties.
Note that if the object has an interceptor the property will be set locally, but since the interceptor takes precedence the local property will only be returned if the interceptor doesn't return a value.
Note also that this only works for named properties.
func (*Object) GetElement ¶
func (*Object) GetInternalField ¶
func (*Object) GetOwnPropertyNames ¶
This function has the same functionality as GetPropertyNames but the returned array doesn't contain the names of properties from prototype objects.
func (*Object) GetProperty ¶
func (*Object) GetPropertyAttributes ¶
func (o *Object) GetPropertyAttributes(key string) PropertyAttribute
func (*Object) GetPropertyNames ¶
Returns an array containing the names of the enumerable properties of this object, including properties from prototype objects. The array returned by this method contains the same values as would be enumerated by a for-in statement over this object.
func (*Object) GetPrototype ¶
Get the prototype object. This does not skip objects marked to be skipped by __proto__ and it does not consult the security handler.
func (*Object) HasElement ¶
func (*Object) HasProperty ¶
func (*Object) InternalFieldCount ¶
func (*Object) SetInternalField ¶
func (*Object) SetProperty ¶
func (o *Object) SetProperty(key string, value *Value, attribs PropertyAttribute) bool
func (*Object) SetPrototype ¶
Set the prototype object. This does not skip objects marked to be skipped by __proto__ and it does not consult the security handler.
type ObjectTemplate ¶
func (*ObjectTemplate) Dispose ¶
func (ot *ObjectTemplate) Dispose()
func (*ObjectTemplate) InternalFieldCount ¶
func (ot *ObjectTemplate) InternalFieldCount() int
func (*ObjectTemplate) NewObject ¶
func (ot *ObjectTemplate) NewObject() *Value
func (*ObjectTemplate) SetAccessor ¶
func (ot *ObjectTemplate) SetAccessor( key string, getter AccessorGetterCallback, setter AccessorSetterCallback, data interface{}, attribs PropertyAttribute, )
func (*ObjectTemplate) SetIndexedPropertyHandler ¶
func (ot *ObjectTemplate) SetIndexedPropertyHandler( getter IndexedPropertyGetterCallback, setter IndexedPropertySetterCallback, query IndexedPropertyQueryCallback, deleter IndexedPropertyDeleterCallback, enumerator IndexedPropertyEnumeratorCallback, data interface{}, )
func (*ObjectTemplate) SetInternalFieldCount ¶
func (ot *ObjectTemplate) SetInternalFieldCount(count int)
func (*ObjectTemplate) SetNamedPropertyHandler ¶
func (ot *ObjectTemplate) SetNamedPropertyHandler( getter NamedPropertyGetterCallback, setter NamedPropertySetterCallback, query NamedPropertyQueryCallback, deleter NamedPropertyDeleterCallback, enumerator NamedPropertyEnumeratorCallback, data interface{}, )
func (*ObjectTemplate) SetProperty ¶
func (ot *ObjectTemplate) SetProperty(key string, value *Value, attribs PropertyAttribute)
func (*ObjectTemplate) WrapObject ¶
func (ot *ObjectTemplate) WrapObject(value *Value)
type PropertyAttribute ¶
type PropertyAttribute int
type PropertyCallbackInfo ¶
type PropertyCallbackInfo struct {
// contains filtered or unexported fields
}
func (PropertyCallbackInfo) CurrentScope ¶
func (p PropertyCallbackInfo) CurrentScope() ContextScope
func (PropertyCallbackInfo) Data ¶
func (p PropertyCallbackInfo) Data() interface{}
func (PropertyCallbackInfo) Holder ¶
func (p PropertyCallbackInfo) Holder() *Object
func (PropertyCallbackInfo) ReturnValue ¶
func (p PropertyCallbackInfo) ReturnValue() ReturnValue
func (PropertyCallbackInfo) This ¶
func (p PropertyCallbackInfo) This() *Object
type RegExpFlags ¶
type RegExpFlags int
type ReturnValue ¶
type ReturnValue struct {
// contains filtered or unexported fields
}
Function and property return value
func (ReturnValue) Set ¶
func (rv ReturnValue) Set(value *Value)
func (ReturnValue) SetBoolean ¶
func (rv ReturnValue) SetBoolean(value bool)
func (ReturnValue) SetInt32 ¶
func (rv ReturnValue) SetInt32(value int32)
func (ReturnValue) SetNull ¶
func (rv ReturnValue) SetNull()
func (ReturnValue) SetNumber ¶
func (rv ReturnValue) SetNumber(value float64)
func (ReturnValue) SetString ¶
func (rv ReturnValue) SetString(value string)
func (ReturnValue) SetUint32 ¶
func (rv ReturnValue) SetUint32(value uint32)
func (ReturnValue) SetUndefined ¶
func (rv ReturnValue) SetUndefined()
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
A compiled JavaScript script.
type ScriptData ¶
type ScriptData struct {
// contains filtered or unexported fields
}
Pre-compilation data that can be associated with a script. This data can be calculated for a script in advance of actually compiling it, and can be stored between compilations. When script data is given to the compile method compilation will be faster.
func NewScriptData ¶
func NewScriptData(data []byte) *ScriptData
Load previous pre-compilation data.
func (*ScriptData) Data ¶
func (sd *ScriptData) Data() []byte
Returns a serialized representation of this ScriptData that can later be passed to New(). NOTE: Serialized data is platform-dependent.
func (*ScriptData) HasError ¶
func (sd *ScriptData) HasError() bool
Returns true if the source code could not be parsed.
type ScriptOrigin ¶
type ScriptOrigin struct { Name string LineOffset int ColumnOffset int // contains filtered or unexported fields }
The origin, within a file, of a script.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
The superclass of all JavaScript values and objects.