本文整理匯總了Golang中github.com/robertkrimen/otto.Object類的典型用法代碼示例。如果您正苦於以下問題:Golang Object類的具體用法?Golang Object怎麽用?Golang Object使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Object類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setFunc
// pipelines in javascript are chainable, you take in a pipeline, and you return a pipeline
// we just generalize some of that logic here
func (js *JavascriptBuilder) setFunc(obj *otto.Object, token string, fn func(string, Node, otto.FunctionCall) (Node, error)) error {
return obj.Set(token, func(call otto.FunctionCall) otto.Value {
this, _ := call.This.Export()
node, err := CreateNode(this)
if err != nil {
js.err = err
return otto.NullValue()
}
node, err = fn(token, node, call)
if err != nil {
js.err = err
return otto.NullValue()
}
o, err := node.Object()
if err != nil {
js.err = err
return otto.NullValue()
}
js.setFunc(o, "transform", js.transform)
js.setFunc(o, "save", js.save)
return o.Value()
})
}
示例2: getString
func getString(obj *otto.Object, name string) (string, error) {
v, err := obj.Get(name)
if err != nil {
return "", err
}
return v.ToString()
}
示例3: fields
func (ctx ppctx) fields(obj *otto.Object) []string {
var (
vals, methods []string
seen = make(map[string]bool)
)
add := func(k string) {
if seen[k] || boringKeys[k] {
return
}
seen[k] = true
if v, _ := obj.Get(k); v.IsFunction() {
methods = append(methods, k)
} else {
vals = append(vals, k)
}
}
// add own properties
ctx.doOwnProperties(obj.Value(), add)
// add properties of the constructor
if cp := constructorPrototype(obj); cp != nil {
ctx.doOwnProperties(cp.Value(), add)
}
sort.Strings(vals)
sort.Strings(methods)
return append(vals, methods...)
}
示例4: gremlinFollowR
func (wk *worker) gremlinFollowR(kind string, prev *otto.Object, env *otto.Otto) func(otto.FunctionCall) otto.Value {
return func(call otto.FunctionCall) otto.Value {
call.Otto.Run("var out = {}")
out, _ := call.Otto.Object("out")
out.Set("_gremlin_type", kind)
out.Set("_gremlin_values", call.ArgumentList)
args := argsOf(call)
if len(args) > 0 {
out.Set("string_args", args)
}
if len(call.ArgumentList) == 0 {
return prev.Value()
}
arg := call.Argument(0)
if isVertexChain(arg.Object()) {
return prev.Value()
}
newChain, _ := reverseGremlinChainTo(call.Otto, arg.Object(), "")
out.Set("_gremlin_prev", prev)
out.Set("_gremlin_followr", newChain)
wk.embedTraversals(env, out)
if isVertexChain(call.This.Object()) {
wk.embedFinals(env, out)
}
return out.Value()
}
}
示例5: getViaData
func getViaData(obj *otto.Object) (predicates []interface{}, tags []string, ok bool) {
argList, _ := obj.Get("_gremlin_values")
if argList.Class() != "GoArray" {
clog.Errorf("How is arglist not an array? Return nothing. %v", argList.Class())
return nil, nil, false
}
argArray := argList.Object()
lengthVal, _ := argArray.Get("length")
length, _ := lengthVal.ToInteger()
if length == 0 {
predicates = []interface{}{}
} else {
zero, _ := argArray.Get("0")
predicates = buildPathFromValue(zero)
}
if length >= 2 {
one, _ := argArray.Get("1")
if one.IsString() {
tags = append(tags, one.String())
} else if one.Class() == "Array" {
tags = stringsFrom(one.Object())
}
}
ok = true
return
}
示例6: gremlinFollowR
func gremlinFollowR(kind string, prevObj *otto.Object, env *otto.Otto, ses *GremlinSession) func(otto.FunctionCall) otto.Value {
return func(call otto.FunctionCall) otto.Value {
call.Otto.Run("var out = {}")
out, _ := call.Otto.Object("out")
out.Set("_gremlin_type", kind)
out.Set("_gremlin_values", call.ArgumentList)
outStrings := concatStringArgs(call)
if len(*outStrings) > 0 {
out.Set("string_args", *outStrings)
}
if len(call.ArgumentList) == 0 {
return prevObj.Value()
}
arg := call.Argument(0)
if isVertexChain(arg.Object()) {
return prevObj.Value()
}
newChain, _ := reverseGremlinChainTo(call.Otto, arg.Object(), "")
out.Set("_gremlin_prev", prevObj)
out.Set("_gremlin_followr", newChain)
embedTraversals(env, ses, out)
if isVertexChain(call.This.Object()) {
embedFinals(env, ses, out)
}
return out.Value()
}
}
示例7: getInt
func getInt(obj *otto.Object, name string) (int64, error) {
v, err := obj.Get(name)
if err != nil {
return -1, err
}
return v.ToInteger()
}
示例8: propertiesOf
func propertiesOf(obj *otto.Object, name string) []string {
val, _ := obj.Get(name)
if val.IsUndefined() {
return nil
}
export, _ := val.Export()
return export.([]string)
}
示例9: getFirstArgAsMorphismChain
func getFirstArgAsMorphismChain(obj *otto.Object) *otto.Object {
arg, _ := obj.Get("_gremlin_values")
firstArg, _ := arg.Object().Get("0")
if isVertexChain(firstArg.Object()) {
return nil
}
return firstArg.Object()
}
示例10: constructorPrototype
func constructorPrototype(obj *otto.Object) *otto.Object {
if v, _ := obj.Get("constructor"); v.Object() != nil {
if v, _ = v.Object().Get("prototype"); v.Object() != nil {
return v.Object()
}
}
return nil
}
示例11: debugChain
func debugChain(obj *otto.Object) bool {
val, _ := obj.Get("_gremlin_type")
glog.V(2).Infoln(val)
val, _ = obj.Get("_gremlin_prev")
if val.IsObject() {
return debugChain(val.Object())
}
return false
}
示例12: isVertexChain
func isVertexChain(obj *otto.Object) bool {
val, _ := obj.Get("_gremlin_type")
if val.String() == "vertex" {
return true
}
val, _ = obj.Get("_gremlin_prev")
if val.IsObject() {
return isVertexChain(val.Object())
}
return false
}
示例13: debugChain
func debugChain(obj *otto.Object) bool {
val, _ := obj.Get("_gremlin_type")
if clog.V(2) {
clog.Infof("%v", val)
}
val, _ = obj.Get("_gremlin_prev")
if val.IsObject() {
return debugChain(val.Object())
}
return false
}
示例14: getStrings
func getStrings(obj *otto.Object, field string) []string {
strings := make([]string, 0)
val, _ := obj.Get(field)
if !val.IsUndefined() {
export, _ := val.Export()
array := export.([]interface{})
for _, arg := range array {
strings = append(strings, arg.(string))
}
}
return strings
}
示例15: ResponseWriterToJso
func ResponseWriterToJso(o *otto.Object, w http.ResponseWriter) {
o.Set("write", func(c otto.FunctionCall) otto.Value {
text, _ := c.Argument(0).ToString()
w.Write([]byte(text))
return otto.TrueValue()
})
o.Set("writeHeader", func(c otto.FunctionCall) otto.Value {
statusCode, _ := c.Argument(0).ToInteger()
w.WriteHeader(int(statusCode))
return otto.TrueValue()
})
}