Documentation ¶
Overview ¶
Package v8go provides an API to execute JavaScript.
Index ¶
- Variables
- func JSONStringify(ctx *Context, val Valuer) (string, error)
- func SetFlags(flags ...string)
- func Version() string
- type CPUProfile
- type CPUProfileNode
- func (c *CPUProfileNode) GetBailoutReason() string
- func (c *CPUProfileNode) GetChild(index int) *CPUProfileNode
- func (c *CPUProfileNode) GetChildrenCount() int
- func (c *CPUProfileNode) GetColumnNumber() int
- func (c *CPUProfileNode) GetFunctionName() string
- func (c *CPUProfileNode) GetHitCount() int
- func (c *CPUProfileNode) GetLineNumber() int
- func (c *CPUProfileNode) GetNodeId() int
- func (c *CPUProfileNode) GetParent() *CPUProfileNode
- func (c *CPUProfileNode) GetScriptId() int
- func (c *CPUProfileNode) GetScriptResourceName() string
- type CPUProfiler
- type CompileMode
- type CompileOptions
- type CompilerCachedData
- type Context
- type ContextOption
- type Function
- type FunctionCallback
- type FunctionCallbackInfo
- type FunctionTemplate
- type HeapStatistics
- type Isolate
- func (i *Isolate) Close()deprecated
- func (i *Isolate) CompileUnboundScript(source, origin string, opts CompileOptions) (*UnboundScript, error)
- func (i *Isolate) Dispose()
- func (i *Isolate) GetHeapStatistics() HeapStatistics
- func (i *Isolate) IsExecutionTerminating() bool
- func (i *Isolate) TerminateExecution()
- func (i *Isolate) ThrowException(value *Value) *Value
- type JSError
- type Object
- func (o *Object) Delete(key string) bool
- func (o *Object) DeleteIdx(idx uint32) bool
- func (o *Object) Get(key string) (*Value, error)
- func (o *Object) GetIdx(idx uint32) (*Value, error)
- func (o *Object) GetInternalField(idx uint32) *Value
- func (o *Object) Has(key string) bool
- func (o *Object) HasIdx(idx uint32) bool
- func (o *Object) InternalFieldCount() uint32
- func (o *Object) MethodCall(methodName string, args ...Valuer) (*Value, error)
- func (o *Object) Set(key string, val interface{}) error
- func (o *Object) SetIdx(idx uint32, val interface{}) error
- func (o *Object) SetInternalField(idx uint32, val interface{}) error
- type ObjectTemplate
- type Promise
- type PromiseResolver
- type PromiseState
- type PropertyAttribute
- type UnboundScript
- type Value
- func (v *Value) ArrayIndex() (idx uint32, ok bool)
- func (v *Value) AsFunction() (*Function, error)
- func (v *Value) AsObject() (*Object, error)
- func (v *Value) AsPromise() (*Promise, error)
- func (v *Value) BigInt() *big.Int
- func (v *Value) Boolean() bool
- func (v *Value) DetailString() string
- func (v *Value) Format(s fmt.State, verb rune)
- func (v *Value) Int32() int32
- func (v *Value) Integer() int64
- func (v *Value) IsArgumentsObject() bool
- func (v *Value) IsArray() bool
- func (v *Value) IsArrayBuffer() bool
- func (v *Value) IsArrayBufferView() bool
- func (v *Value) IsAsyncFunction() bool
- func (v *Value) IsBigInt() bool
- func (v *Value) IsBigInt64Array() bool
- func (v *Value) IsBigIntObject() bool
- func (v *Value) IsBigUint64Array() bool
- func (v *Value) IsBoolean() bool
- func (v *Value) IsDataView() bool
- func (v *Value) IsDate() bool
- func (v *Value) IsExternal() bool
- func (v *Value) IsFalse() bool
- func (v *Value) IsFloat32Array() bool
- func (v *Value) IsFloat64Array() bool
- func (v *Value) IsFunction() bool
- func (v *Value) IsGeneratorFunction() bool
- func (v *Value) IsGeneratorObject() bool
- func (v *Value) IsInt16Array() bool
- func (v *Value) IsInt32() bool
- func (v *Value) IsInt32Array() bool
- func (v *Value) IsInt8Array() bool
- func (v *Value) IsMap() bool
- func (v *Value) IsMapIterator() bool
- func (v *Value) IsModuleNamespaceObject() bool
- func (v *Value) IsName() bool
- func (v *Value) IsNativeError() bool
- func (v *Value) IsNull() bool
- func (v *Value) IsNullOrUndefined() bool
- func (v *Value) IsNumber() bool
- func (v *Value) IsNumberObject() bool
- func (v *Value) IsObject() bool
- func (v *Value) IsPromise() bool
- func (v *Value) IsProxy() bool
- func (v *Value) IsRegExp() bool
- func (v *Value) IsSet() bool
- func (v *Value) IsSetIterator() bool
- func (v *Value) IsSharedArrayBuffer() bool
- func (v *Value) IsString() bool
- func (v *Value) IsStringObject() bool
- func (v *Value) IsSymbol() bool
- func (v *Value) IsSymbolObject() bool
- func (v *Value) IsTrue() bool
- func (v *Value) IsTypedArray() bool
- func (v *Value) IsUint16Array() bool
- func (v *Value) IsUint32() bool
- func (v *Value) IsUint32Array() bool
- func (v *Value) IsUint8Array() bool
- func (v *Value) IsUint8ClampedArray() bool
- func (v *Value) IsUndefined() bool
- func (v *Value) IsWasmModuleObject() bool
- func (v *Value) IsWeakMap() bool
- func (v *Value) IsWeakSet() bool
- func (v *Value) MarshalJSON() ([]byte, error)
- func (v *Value) Number() float64
- func (v *Value) Object() *Object
- func (v *Value) Release()
- func (v *Value) SameValue(other *Value) bool
- func (v *Value) SharedArrayBufferGetContents() ([]byte, func(), error)
- func (v *Value) String() string
- func (v *Value) Uint32() uint32
- type Valuer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( CompileModeDefault = CompileMode(C.ScriptCompilerNoCompileOptions) CompileModeEager = CompileMode(C.ScriptCompilerEagerCompile) )
Functions ¶
func JSONStringify ¶
JSONStringify tries to stringify the JSON-serializable object value and returns it as string.
Example ¶
package main import ( "fmt" v8 "github.com/BloomrIO/v8go" ) func main() { ctx := v8.NewContext() defer ctx.Isolate().Dispose() defer ctx.Close() val, _ := v8.JSONParse(ctx, `{ "a": 1, "b": "foo" }`) jsonStr, _ := v8.JSONStringify(ctx, val) fmt.Println(jsonStr) }
Output: {"a":1,"b":"foo"}
func SetFlags ¶
func SetFlags(flags ...string)
SetFlags sets flags for V8. For possible flags: https://github.com/v8/v8/blob/master/src/flags/flag-definitions.h Flags are expected to be prefixed with `--`, for example: `--harmony`. Flags can be reverted using the `--no` prefix equivalent, for example: `--use_strict` vs `--nouse_strict`. Flags will affect all Isolates created, even after creation.
Types ¶
type CPUProfile ¶
type CPUProfile struct {
// contains filtered or unexported fields
}
func (*CPUProfile) Delete ¶
func (c *CPUProfile) Delete()
Deletes the profile and removes it from CpuProfiler's list. All pointers to nodes previously returned become invalid.
func (*CPUProfile) GetDuration ¶
func (c *CPUProfile) GetDuration() time.Duration
Returns the duration of the profile.
func (*CPUProfile) GetTopDownRoot ¶
func (c *CPUProfile) GetTopDownRoot() *CPUProfileNode
Returns the root node of the top down call tree.
type CPUProfileNode ¶
type CPUProfileNode struct {
// contains filtered or unexported fields
}
func (*CPUProfileNode) GetBailoutReason ¶
func (c *CPUProfileNode) GetBailoutReason() string
Returns the bailout reason for the function if the optimization was disabled for it.
func (*CPUProfileNode) GetChild ¶
func (c *CPUProfileNode) GetChild(index int) *CPUProfileNode
Retrieves a child node by index.
func (*CPUProfileNode) GetChildrenCount ¶
func (c *CPUProfileNode) GetChildrenCount() int
func (*CPUProfileNode) GetColumnNumber ¶
func (c *CPUProfileNode) GetColumnNumber() int
Returns number of the column where the function originates.
func (*CPUProfileNode) GetFunctionName ¶
func (c *CPUProfileNode) GetFunctionName() string
Returns function name (empty string for anonymous functions.)
func (*CPUProfileNode) GetHitCount ¶
func (c *CPUProfileNode) GetHitCount() int
Returns count of samples where the function was currently executing.
func (*CPUProfileNode) GetLineNumber ¶
func (c *CPUProfileNode) GetLineNumber() int
Returns number of the line where the function originates.
func (*CPUProfileNode) GetParent ¶
func (c *CPUProfileNode) GetParent() *CPUProfileNode
Retrieves the ancestor node, or nil if the root.
func (*CPUProfileNode) GetScriptId ¶
func (c *CPUProfileNode) GetScriptId() int
Returns id for script from where the function originates.
func (*CPUProfileNode) GetScriptResourceName ¶
func (c *CPUProfileNode) GetScriptResourceName() string
Returns resource name for script from where the function originates.
type CPUProfiler ¶
type CPUProfiler struct {
// contains filtered or unexported fields
}
func NewCPUProfiler ¶
func NewCPUProfiler(iso *Isolate) *CPUProfiler
CPUProfiler is used to control CPU profiling.
func (*CPUProfiler) StartProfiling ¶
func (c *CPUProfiler) StartProfiling(title string)
StartProfiling starts collecting a CPU profile. Title may be an empty string. Several profiles may be collected at once. Attempts to start collecting several profiles with the same title are silently ignored.
func (*CPUProfiler) StopProfiling ¶
func (c *CPUProfiler) StopProfiling(title string) *CPUProfile
Stops collecting CPU profile with a given title and returns it. If the title given is empty, finishes the last profile started.
type CompileMode ¶
type CompileOptions ¶
type CompileOptions struct { CachedData *CompilerCachedData Mode CompileMode }
type CompilerCachedData ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a global root execution environment that allows separate, unrelated, JavaScript applications to run in a single instance of V8.
Example ¶
package main import ( "fmt" v8 "github.com/BloomrIO/v8go" ) func main() { ctx := v8.NewContext() defer ctx.Isolate().Dispose() defer ctx.Close() ctx.RunScript("const add = (a, b) => a + b", "math.js") ctx.RunScript("const result = add(3, 4)", "main.js") val, _ := ctx.RunScript("result", "value.js") fmt.Println(val) }
Output: 7
Example (GlobalTemplate) ¶
package main import ( "fmt" v8 "github.com/BloomrIO/v8go" ) func main() { iso := v8.NewIsolate() defer iso.Dispose() obj := v8.NewObjectTemplate(iso) obj.Set("version", "v1.0.0") ctx := v8.NewContext(iso, obj) defer ctx.Close() val, _ := ctx.RunScript("version", "main.js") fmt.Println(val) }
Output: v1.0.0
Example (Isolate) ¶
package main import ( "fmt" v8 "github.com/BloomrIO/v8go" ) func main() { iso := v8.NewIsolate() defer iso.Dispose() ctx1 := v8.NewContext(iso) defer ctx1.Close() ctx1.RunScript("const foo = 'bar'", "context_one.js") val, _ := ctx1.RunScript("foo", "foo.js") fmt.Println(val) ctx2 := v8.NewContext(iso) defer ctx2.Close() _, err := ctx2.RunScript("foo", "context_two.js") fmt.Println(err) }
Output: bar ReferenceError: foo is not defined
func NewContext ¶
func NewContext(opt ...ContextOption) *Context
NewContext creates a new JavaScript context; if no Isolate is passed as a ContextOption than a new Isolate will be created.
func (*Context) Close ¶
func (c *Context) Close()
Close will dispose the context and free the memory. Access to any values associated with the context after calling Close may panic.
func (*Context) Global ¶
Global returns the global proxy object. Global proxy object is a thin wrapper whose prototype points to actual context's global object with the properties like Object, etc. This is done that way for security reasons. Please note that changes to global proxy object prototype most probably would break the VM — V8 expects only global object as a prototype of global proxy object.
func (*Context) PerformMicrotaskCheckpoint ¶
func (c *Context) PerformMicrotaskCheckpoint()
PerformMicrotaskCheckpoint runs the default MicrotaskQueue until empty. This is used to make progress on Promises.
func (*Context) RetainedValueCount ¶
type ContextOption ¶
type ContextOption interface {
// contains filtered or unexported methods
}
ContextOption sets options such as Isolate and Global Template to the NewContext
type Function ¶
type Function struct {
*Value
}
Function is a JavaScript function.
func (*Function) NewInstance ¶
Invoke a constructor function to create an object instance.
func (*Function) SourceMapUrl ¶
Return the source map url for a function.
type FunctionCallback ¶
type FunctionCallback func(info *FunctionCallbackInfo) *Value
FunctionCallback is a callback that is executed in Go when a function is executed in JS.
type FunctionCallbackInfo ¶
type FunctionCallbackInfo struct {
// contains filtered or unexported fields
}
FunctionCallbackInfo is the argument that is passed to a FunctionCallback.
func (*FunctionCallbackInfo) Args ¶
func (i *FunctionCallbackInfo) Args() []*Value
Args returns a slice of the value arguments that are passed to the JS function.
func (*FunctionCallbackInfo) Context ¶
func (i *FunctionCallbackInfo) Context() *Context
Context is the current context that the callback is being executed in.
func (*FunctionCallbackInfo) Release ¶
func (i *FunctionCallbackInfo) Release()
func (*FunctionCallbackInfo) This ¶
func (i *FunctionCallbackInfo) This() *Object
This returns the receiver object "this".
type FunctionTemplate ¶
type FunctionTemplate struct {
// contains filtered or unexported fields
}
FunctionTemplate is used to create functions at runtime. There can only be one function created from a FunctionTemplate in a context. The lifetime of the created function is equal to the lifetime of the context.
Example ¶
package main import ( "fmt" v8 "github.com/BloomrIO/v8go" ) func main() { iso := v8.NewIsolate() defer iso.Dispose() global := v8.NewObjectTemplate(iso) printfn := v8.NewFunctionTemplate(iso, func(info *v8.FunctionCallbackInfo) *v8.Value { fmt.Printf("%+v\n", info.Args()) return nil }) global.Set("print", printfn, v8.ReadOnly) ctx := v8.NewContext(iso, global) defer ctx.Close() ctx.RunScript("print('foo', 'bar', 0, 1)", "") }
Output: [foo bar 0 1]
Example (Fetch) ¶
package main import ( "fmt" "io/ioutil" "net/http" "strings" v8 "github.com/BloomrIO/v8go" ) func main() { iso := v8.NewIsolate() defer iso.Dispose() global := v8.NewObjectTemplate(iso) fetchfn := v8.NewFunctionTemplate(iso, func(info *v8.FunctionCallbackInfo) *v8.Value { args := info.Args() url := args[0].String() resolver, _ := v8.NewPromiseResolver(info.Context()) go func() { res, _ := http.Get(url) body, _ := ioutil.ReadAll(res.Body) val, _ := v8.NewValue(iso, string(body)) resolver.Resolve(val) }() return resolver.GetPromise().Value }) global.Set("fetch", fetchfn, v8.ReadOnly) ctx := v8.NewContext(iso, global) defer ctx.Close() val, _ := ctx.RunScript("fetch('https://github.com/BloomrIO/v8go')", "") prom, _ := val.AsPromise() // wait for the promise to resolve for prom.State() == v8.Pending { continue } fmt.Printf("%s\n", strings.Split(prom.Result().String(), "\n")[0]) }
Output: <!DOCTYPE html>
func NewFunctionTemplate ¶
func NewFunctionTemplate(iso *Isolate, callback FunctionCallback) *FunctionTemplate
NewFunctionTemplate creates a FunctionTemplate for a given callback.
func (*FunctionTemplate) GetFunction ¶
func (tmpl *FunctionTemplate) GetFunction(ctx *Context) *Function
GetFunction returns an instance of this function template bound to the given context.
func (FunctionTemplate) Set ¶
func (t FunctionTemplate) Set(name string, val interface{}, attributes ...PropertyAttribute) error
Set adds a property to each instance created by this template. The property must be defined either as a primitive value, or a template. If the value passed is a Go supported primitive (string, int32, uint32, int64, uint64, float64, big.Int) then a value will be created and set as the value property.
type HeapStatistics ¶
type HeapStatistics struct { TotalHeapSize uint64 TotalHeapSizeExecutable uint64 TotalPhysicalSize uint64 TotalAvailableSize uint64 UsedHeapSize uint64 HeapSizeLimit uint64 MallocedMemory uint64 ExternalMemory uint64 PeakMallocedMemory uint64 NumberOfNativeContexts uint64 NumberOfDetachedContexts uint64 }
HeapStatistics represents V8 isolate heap statistics
type Isolate ¶
type Isolate struct {
// contains filtered or unexported fields
}
Isolate is a JavaScript VM instance with its own heap and garbage collector. Most applications will create one isolate with many V8 contexts for execution.
func NewIsolate ¶
func NewIsolate() *Isolate
NewIsolate creates a new V8 isolate. Only one thread may access a given isolate at a time, but different threads may access different isolates simultaneously. When an isolate is no longer used its resources should be freed by calling iso.Dispose(). An *Isolate can be used as a v8go.ContextOption to create a new Context, rather than creating a new default Isolate.
func (*Isolate) CompileUnboundScript ¶
func (i *Isolate) CompileUnboundScript(source, origin string, opts CompileOptions) (*UnboundScript, error)
CompileUnboundScript will create an UnboundScript (i.e. context-indepdent) using the provided source JavaScript, origin (a.k.a. filename), and options. If options contain a non-null CachedData, compilation of the script will use that code cache. error will be of type `JSError` if not nil.
func (*Isolate) Dispose ¶
func (i *Isolate) Dispose()
Dispose will dispose the Isolate VM; subsequent calls will panic.
func (*Isolate) GetHeapStatistics ¶
func (i *Isolate) GetHeapStatistics() HeapStatistics
GetHeapStatistics returns heap statistics for an isolate.
func (*Isolate) IsExecutionTerminating ¶
IsExecutionTerminating returns whether V8 is currently terminating Javascript execution. If true, there are still JavaScript frames on the stack and the termination exception is still active.
func (*Isolate) TerminateExecution ¶
func (i *Isolate) TerminateExecution()
TerminateExecution terminates forcefully the current thread of JavaScript execution in the given isolate.
func (*Isolate) ThrowException ¶
ThrowException schedules an exception to be thrown when returning to JavaScript. When an exception has been scheduled it is illegal to invoke any JavaScript operation; the caller must return immediately and only after the exception has been handled does it become legal to invoke JavaScript operations.
type JSError ¶
JSError is an error that is returned if there is are any JavaScript exceptions handled in the context. When used with the fmt verb `%+v`, will output the JavaScript stack trace, if available.
type Object ¶
type Object struct {
*Value
}
Object is a JavaScript object (ECMA-262, 4.3.3)
Example (Global) ¶
package main import ( "fmt" v8 "github.com/BloomrIO/v8go" ) func main() { iso := v8.NewIsolate() defer iso.Dispose() ctx := v8.NewContext(iso) defer ctx.Close() global := ctx.Global() console := v8.NewObjectTemplate(iso) logfn := v8.NewFunctionTemplate(iso, func(info *v8.FunctionCallbackInfo) *v8.Value { fmt.Println(info.Args()[0]) return nil }) console.Set("log", logfn) consoleObj, _ := console.NewInstance(ctx) global.Set("console", consoleObj) ctx.RunScript("console.log('foo')", "") }
Output: foo
func (*Object) Delete ¶
Delete returns true if successful in deleting a named property on the object.
func (*Object) DeleteIdx ¶
DeleteIdx returns true if successful in deleting a value at a given index of the object.
func (*Object) GetInternalField ¶
GetInternalField gets the Value set by SetInternalField for the given index or the JS undefined value if the index hadn't been set. Panics if given an out of range index.
func (*Object) Has ¶
Has calls the abstract operation HasProperty(O, P) described in ECMA-262, 7.3.10. Returns true, if the object has the property, either own or on the prototype chain.
func (*Object) InternalFieldCount ¶
InternalFieldCount returns the number of internal fields this Object has.
func (*Object) MethodCall ¶
func (*Object) Set ¶
Set will set a property on the Object to a given value. Supports all value types, eg: Object, Array, Date, Set, Map etc If the value passed is a Go supported primitive (string, int32, uint32, int64, uint64, float64, big.Int) then a *Value will be created and set as the value property.
func (*Object) SetIdx ¶
Set will set a given index on the Object to a given value. Supports all value types, eg: Object, Array, Date, Set, Map etc If the value passed is a Go supported primitive (string, int32, uint32, int64, uint64, float64, big.Int) then a *Value will be created and set as the value property.
func (*Object) SetInternalField ¶
SetInternalField sets the value of an internal field for an ObjectTemplate instance. Panics if the index isn't in the range set by (*ObjectTemplate).SetInternalFieldCount.
type ObjectTemplate ¶
type ObjectTemplate struct {
// contains filtered or unexported fields
}
ObjectTemplate is used to create objects at runtime. Properties added to an ObjectTemplate are added to each object created from the ObjectTemplate.
func NewObjectTemplate ¶
func NewObjectTemplate(iso *Isolate) *ObjectTemplate
NewObjectTemplate creates a new ObjectTemplate. The *ObjectTemplate can be used as a v8go.ContextOption to create a global object in a Context.
func (*ObjectTemplate) InternalFieldCount ¶
func (o *ObjectTemplate) InternalFieldCount() uint32
InternalFieldCount returns the number of internal fields that instances of this template will have.
func (*ObjectTemplate) NewInstance ¶
func (o *ObjectTemplate) NewInstance(ctx *Context) (*Object, error)
NewInstance creates a new Object based on the template.
func (ObjectTemplate) Set ¶
func (t ObjectTemplate) Set(name string, val interface{}, attributes ...PropertyAttribute) error
Set adds a property to each instance created by this template. The property must be defined either as a primitive value, or a template. If the value passed is a Go supported primitive (string, int32, uint32, int64, uint64, float64, big.Int) then a value will be created and set as the value property.
func (*ObjectTemplate) SetInternalFieldCount ¶
func (o *ObjectTemplate) SetInternalFieldCount(fieldCount uint32)
SetInternalFieldCount sets the number of internal fields that instances of this template will have.
type Promise ¶
type Promise struct {
*Object
}
Promise is the JavaScript promise object defined in ES6
func (*Promise) Catch ¶
func (p *Promise) Catch(cb FunctionCallback) *Promise
Catch invokes the given function if the promise is rejected. See Then for other details.
func (*Promise) Result ¶
Result is the value result of the Promise. The Promise must NOT be in a Pending state, otherwise may panic. Call promise.State() to validate state before calling for the result.
func (*Promise) State ¶
func (p *Promise) State() PromiseState
State returns the current state of the Promise.
func (*Promise) Then ¶
func (p *Promise) Then(cbs ...FunctionCallback) *Promise
Then accepts 1 or 2 callbacks. The first is invoked when the promise has been fulfilled. The second is invoked when the promise has been rejected. The returned Promise resolves after the callback finishes execution.
V8 only invokes the callback when processing "microtasks". The default MicrotaskPolicy processes them when the call depth decreases to 0. Call (*Context).PerformMicrotaskCheckpoint to trigger it manually.
type PromiseResolver ¶
type PromiseResolver struct { *Object // contains filtered or unexported fields }
PromiseResolver is the resolver object for the promise. Most cases will create a new PromiseResolver and return the associated Promise from the resolver.
func NewPromiseResolver ¶
func NewPromiseResolver(ctx *Context) (*PromiseResolver, error)
NewPromiseResolver creates a new Promise resolver for the given context. The associated Promise will be in a Pending state.
func (*PromiseResolver) GetPromise ¶
func (r *PromiseResolver) GetPromise() *Promise
GetPromise returns the associated Promise object for this resolver. The Promise object is unique to the resolver and returns the same object on multiple calls.
func (*PromiseResolver) Reject ¶
func (r *PromiseResolver) Reject(err *Value) bool
Reject invokes the Promise reject state with the given value. The Promise state will transition from Pending to Rejected.
func (*PromiseResolver) Resolve ¶
func (r *PromiseResolver) Resolve(val Valuer) bool
Resolve invokes the Promise resolve state with the given value. The Promise state will transition from Pending to Fulfilled.
type PromiseState ¶
type PromiseState int
PromiseState is the state of the Promise.
const ( Pending PromiseState = iota Fulfilled Rejected )
type PropertyAttribute ¶
type PropertyAttribute uint8
PropertyAttribute are the attribute flags for a property on an Object. Typical usage when setting an Object or TemplateObject property, and can also be validated when accessing a property.
const ( // None. None PropertyAttribute = 0 // ReadOnly, ie. not writable. ReadOnly PropertyAttribute = 1 << iota // DontEnum, ie. not enumerable. DontEnum // DontDelete, ie. not configurable. DontDelete )
type UnboundScript ¶
type UnboundScript struct {
// contains filtered or unexported fields
}
func (*UnboundScript) CreateCodeCache ¶
func (u *UnboundScript) CreateCodeCache() *CompilerCachedData
Create a code cache from the unbound script.
func (*UnboundScript) Run ¶
func (u *UnboundScript) Run(ctx *Context) (*Value, error)
Run will bind the unbound script to the provided context and run it. If the context provided does not belong to the same isolate that the script was compiled in, Run will panic. If an error occurs, it will be of type `JSError`.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents all Javascript values and objects
func JSONParse ¶
JSONParse tries to parse the string and returns it as *Value if successful. Any JS errors will be returned as `JSError`.
Example ¶
package main import ( "fmt" v8 "github.com/BloomrIO/v8go" ) func main() { ctx := v8.NewContext() defer ctx.Isolate().Dispose() defer ctx.Close() val, _ := v8.JSONParse(ctx, `{"foo": "bar"}`) fmt.Println(val) }
Output: [object Object]
func NewValue ¶
NewValue will create a primitive value. Supported values types to create are:
string -> V8::String int32 -> V8::Integer uint32 -> V8::Integer int64 -> V8::BigInt uint64 -> V8::BigInt bool -> V8::Boolean *big.Int -> V8::BigInt
func (*Value) ArrayIndex ¶
ArrayIndex attempts to converts a string to an array index. Returns ok false if conversion fails.
func (*Value) AsFunction ¶
func (*Value) AsObject ¶
AsObject will cast the value to the Object type. If the value is not an Object then an error is returned. Use `value.Object()` to do the JS equivalent of `Object(value)`.
func (*Value) Boolean ¶
Boolean perform the equivalent of `Boolean(value)` in JS. This can never fail.
func (*Value) DetailString ¶
DetailString provide a string representation of this value usable for debugging.
func (*Value) Format ¶
Format implements the fmt.Formatter interface to provide a custom formatter primarily to output the detail string (for debugging) with `%+v` verb.
func (*Value) Int32 ¶
Int32 perform the equivalent of `Number(value)` in JS and convert the result to a signed 32-bit integer by performing the steps in https://tc39.es/ecma262/#sec-toint32.
func (*Value) Integer ¶
Integer perform the equivalent of `Number(value)` in JS and convert the result to an integer. Negative values are rounded up, positive values are rounded down. NaN is converted to 0. Infinite values yield undefined results.
func (*Value) IsArgumentsObject ¶
IsArgumentsObject returns true if this value is an Arguments object.
func (*Value) IsArray ¶
IsArray returns true if this value is an array. Note that it will return false for a `Proxy` of an array.
func (*Value) IsArrayBuffer ¶
IsArrayBuffer returns true if this value is an `ArrayBuffer`.
func (*Value) IsArrayBufferView ¶
IsArrayBufferView returns true if this value is an `ArrayBufferView`.
func (*Value) IsAsyncFunction ¶
IsAsyncFunc returns true if this value is an async function.
func (*Value) IsBigInt ¶
IsBigInt returns true if this value is a bigint. This is equivalent to `typeof value === 'bigint'` in JS.
func (*Value) IsBigInt64Array ¶
IsBigInt64Array returns true if this value is a `BigInt64Array`.
func (*Value) IsBigIntObject ¶
IsBigIntObject returns true if this value is a BigInt object.
func (*Value) IsBigUint64Array ¶
IsBigUint64Array returns true if this value is a BigUint64Array`.
func (*Value) IsBoolean ¶
IsBoolean returns true if this value is boolean. This is equivalent to `typeof value === 'boolean'` in JS.
func (*Value) IsDataView ¶
IsDataView returns true if this value is a `DataView`.
func (*Value) IsExternal ¶
IsExternal returns true if this value is an `External` object.
func (*Value) IsFalse ¶
IsFalse returns true if this value is false. This is not the same as `!BooleanValue()`. The latter performs a conversion to boolean, i.e. the result of `!Boolean(value)` in JS, whereas this checks `value === false`.
func (*Value) IsFloat32Array ¶
IsFloat32Array returns true if this value is a `Float32Array`.
func (*Value) IsFloat64Array ¶
IsFloat64Array returns true if this value is a `Float64Array`.
func (*Value) IsFunction ¶
IsFunction returns true if this value is a function. This is equivalent to `typeof value === 'function'` in JS.
func (*Value) IsGeneratorFunction ¶
Is IsGeneratorFunc returns true if this value is a Generator function.
func (*Value) IsGeneratorObject ¶
IsGeneratorObject returns true if this value is a Generator object (iterator).
func (*Value) IsInt16Array ¶
IsInt16Array returns true if this value is an `Int16Array`.
func (*Value) IsInt32Array ¶
IsInt32Array returns true if this value is an `Int32Array`.
func (*Value) IsInt8Array ¶
IsInt8Array returns true if this value is an `Int8Array`.
func (*Value) IsMapIterator ¶
IsMapIterator returns true if this value is a `Map` Iterator.
func (*Value) IsModuleNamespaceObject ¶
IsModuleNamespaceObject returns true if the value is a `Module` Namespace `Object`.
func (*Value) IsName ¶
IsName returns true if this value is a symbol or a string. This is equivalent to `typeof value === 'string' || typeof value === 'symbol'` in JS.
func (*Value) IsNativeError ¶
IsNativeError returns true if this value is a NativeError.
func (*Value) IsNullOrUndefined ¶
IsNullOrUndefined returns true if this value is either the null or the undefined value. See ECMA-262 4.3.11. and 4.3.12 This is equivalent to `value == null` in JS.
func (*Value) IsNumber ¶
IsNumber returns true if this value is a number. This is equivalent to `typeof value === 'number'` in JS.
func (*Value) IsNumberObject ¶
IsNumberObject returns true if this value is a `Number` object.
func (*Value) IsSetIterator ¶
IsSetIterator returns true if this value is a `Set` Iterator.
func (*Value) IsSharedArrayBuffer ¶
IsSharedArrayBuffer returns true if this value is a `SharedArrayBuffer`.
func (*Value) IsString ¶
IsString returns true if this value is an instance of the String type. See ECMA-262 8.4. This is equivalent to `typeof value === 'string'` in JS.
func (*Value) IsStringObject ¶
IsStringObject returns true if this value is a `String` object.
func (*Value) IsSymbol ¶
IsSymbol returns true if this value is a symbol. This is equivalent to `typeof value === 'symbol'` in JS.
func (*Value) IsSymbolObject ¶
IsSymbolObject returns true if this value is a `Symbol` object.
func (*Value) IsTrue ¶
IsTrue returns true if this value is true. This is not the same as `BooleanValue()`. The latter performs a conversion to boolean, i.e. the result of `Boolean(value)` in JS, whereas this checks `value === true`.
func (*Value) IsTypedArray ¶
IsTypedArray returns true if this value is one of TypedArrays.
func (*Value) IsUint16Array ¶
IsUint16Array returns true if this value is an `Uint16Array`.
func (*Value) IsUint32Array ¶
IsUint32Array returns true if this value is an `Uint32Array`.
func (*Value) IsUint8Array ¶
IsUint8Array returns true if this value is an `Uint8Array`.
func (*Value) IsUint8ClampedArray ¶
IsUint8ClampedArray returns true if this value is an `Uint8ClampedArray`.
func (*Value) IsUndefined ¶
IsUndefined returns true if this value is the undefined value. See ECMA-262 4.3.10.
func (*Value) IsWasmModuleObject ¶
IsWasmModuleObject returns true if this value is a `WasmModuleObject`.
func (*Value) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Value) Object ¶
Object perform the equivalent of Object(value) in JS. To just cast this value as an Object use AsObject() instead.
func (*Value) Release ¶
func (v *Value) Release()
Release this value. Using the value after calling this function will result in undefined behavior.
func (*Value) SameValue ¶
SameValue returns true if the other value is the same value. This is equivalent to `Object.is(v, other)` in JS.
func (*Value) SharedArrayBufferGetContents ¶
func (*Value) String ¶
String perform the equivalent of `String(value)` in JS. Primitive values are returned as-is, objects will return `[object Object]` and functions will print their definition.
func (*Value) Uint32 ¶
Uint32 perform the equivalent of `Number(value)` in JS and convert the result to an unsigned 32-bit integer by performing the steps in https://tc39.es/ecma262/#sec-touint32.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
deps
|
|
darwin_arm64
Package darwin_arm64 is required to provide support for vendoring modules DO NOT REMOVE
|
Package darwin_arm64 is required to provide support for vendoring modules DO NOT REMOVE |
darwin_x86_64
Package darwin_x86_64 is required to provide support for vendoring modules DO NOT REMOVE
|
Package darwin_x86_64 is required to provide support for vendoring modules DO NOT REMOVE |
include
Generated by deps/upgrade_v8.py, DO NOT REMOVE/EDIT MANUALLY.
|
Generated by deps/upgrade_v8.py, DO NOT REMOVE/EDIT MANUALLY. |
include/cppgc
Generated by deps/upgrade_v8.py, DO NOT REMOVE/EDIT MANUALLY.
|
Generated by deps/upgrade_v8.py, DO NOT REMOVE/EDIT MANUALLY. |
include/libplatform
Generated by deps/upgrade_v8.py, DO NOT REMOVE/EDIT MANUALLY.
|
Generated by deps/upgrade_v8.py, DO NOT REMOVE/EDIT MANUALLY. |
linux_arm64
Package linux_arm64 is required to provide support for vendoring modules DO NOT REMOVE
|
Package linux_arm64 is required to provide support for vendoring modules DO NOT REMOVE |
linux_x86_64
Package linux_x86_64 is required to provide support for vendoring modules DO NOT REMOVE
|
Package linux_x86_64 is required to provide support for vendoring modules DO NOT REMOVE |